github.com/Aoi-hosizora/ahlib@v1.5.1-0.20230404072829-241b93cf91c7/xstatus/xstatus_jwt.go (about)

     1  package xstatus
     2  
     3  // JwtStatus represents a status value for the result of jwt and database operation.
     4  type JwtStatus uint64
     5  
     6  // 0 - 13
     7  const (
     8  	JwtUnknown JwtStatus = 0    // Unknown
     9  	JwtSuccess JwtStatus = iota // Success
    10  	JwtBlank                    // Blank token
    11  	JwtInvalid                  // Invalid token (malformed, unverifiable, invalid signature)
    12  
    13  	JwtTokenNotFound // Token not found
    14  	JwtUserNotFound  // User not found
    15  	JwtFailed        // Something error
    16  	JwtTagA          // Tag a
    17  	JwtTagB          // Tag b
    18  	JwtTagC          // Tag c
    19  	JwtTagD          // Tag d
    20  	JwtTagE          // Tag e
    21  	JwtTagF          // Tag f
    22  	JwtTagG          // Tag g
    23  )
    24  
    25  // 16 - 2048
    26  const (
    27  	JwtAudience      JwtStatus = 16 << iota // AUD (Audience)
    28  	JwtExpired                              // EXP (Expires at)
    29  	JwtId                                   // JTI (Id)
    30  	JwtIssuedAt                             // IAT (Issued at)
    31  	JwtIssuer                               // ISS (Issuer)
    32  	JwtNotValidYet                          // NBF (Not before)
    33  	JwtSubject                              // SUB (Subject)
    34  	JwtClaimsInvalid                        // Invalid claims, generic claims error
    35  )
    36  
    37  func (j JwtStatus) String() string {
    38  	switch j {
    39  	case JwtUnknown:
    40  		return "jwt-unknown"
    41  	case JwtSuccess:
    42  		return "jwt-success"
    43  	case JwtBlank:
    44  		return "jwt-blank"
    45  	case JwtInvalid:
    46  		return "jwt-invalid"
    47  
    48  	case JwtTokenNotFound:
    49  		return "jwt-token-not-found"
    50  	case JwtUserNotFound:
    51  		return "jwt-user-not-found"
    52  	case JwtFailed:
    53  		return "jwt-failed"
    54  	case JwtTagA:
    55  		return "jwt-tag-a"
    56  	case JwtTagB:
    57  		return "jwt-tag-b"
    58  	case JwtTagC:
    59  		return "jwt-tag-c"
    60  	case JwtTagD:
    61  		return "jwt-tag-d"
    62  	case JwtTagE:
    63  		return "jwt-tag-e"
    64  	case JwtTagF:
    65  		return "jwt-tag-f"
    66  	case JwtTagG:
    67  		return "jwt-tag-g"
    68  
    69  	case JwtAudience:
    70  		return "jwt-audience"
    71  	case JwtExpired:
    72  		return "jwt-expired"
    73  	case JwtId:
    74  		return "jwt-id"
    75  	case JwtIssuedAt:
    76  		return "jwt-issued-at"
    77  	case JwtIssuer:
    78  		return "jwt-issuer"
    79  	case JwtNotValidYet:
    80  		return "jwt-not-valid-yet"
    81  	case JwtSubject:
    82  		return "jwt-subject"
    83  	case JwtClaimsInvalid:
    84  		return "jwt-claims-invalid"
    85  
    86  	default:
    87  		return "jwt-?"
    88  	}
    89  }