Documentation ¶
Index ¶
- Constants
- func IsTokenExpiredError(err error) bool
- func Sign(key []byte, method jwt.SigningMethod, claims jwt.MapClaims, ...) (string, error)
- func SignWithCaesar(caesarShift int, key []byte, method jwt.SigningMethod, claims jwt.MapClaims, ...) (cipherText string, err error)
- func Verify(tokenString string, keyFunc jwt.Keyfunc, options ...jwt.ParserOption) (jwt.MapClaims, error)
- func VerifyWithCaesar(caesarShift int, cipherText string, keyFunc jwt.Keyfunc, ...) (jwt.MapClaims, error)
Constants ¶
View Source
const ( // KeyNotBefore 生效时间 KeyNotBefore = "nbf" // KeyExpirationTime 过期时间 KeyExpirationTime = "exp" // KeyIssuedAt 签发时间 KeyIssuedAt = "iat" // KeyAudience 受众 KeyAudience = "aud" // KeyIssuer 签发人 KeyIssuer = "iss" // KeySubject 主题 KeySubject = "sub" // KeyJwtId 编号 KeyJwtId = "jti" )
Variables ¶
This section is empty.
Functions ¶
func IsTokenExpiredError ¶
func Sign ¶ added in v3.0.67
func Sign(key []byte, method jwt.SigningMethod, claims jwt.MapClaims, options ...jwt.TokenOption) (string, error)
Sign 生成JWT字符串.
@param key 密钥(secret) @param method e.g. jwt.SigningMethodHS256 || jwt.SigningMethodHS384 || jwt.SigningMethodHS512
func SignWithCaesar ¶ added in v3.0.67
func Verify ¶ added in v3.0.67
func Verify(tokenString string, keyFunc jwt.Keyfunc, options ...jwt.ParserOption) (jwt.MapClaims, error)
Verify 验证JWT字符串.
PS: 如果 token 过期(根据"exp",有的话),会返回 error(可以通过 IsTokenExpiredError 判断).
@param keyFunc 此函数的第一个返回值为密钥(secret)
e.g. func(token *jwt.Token) (interface{}, error) { // Don't forget to validate the alg is what you expect: if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) } // hmacSampleSecret is a []byte containing your secret, e.g. []byte("my_secret_key") return key, nil }
func VerifyWithCaesar ¶ added in v3.0.67
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.