Documentation ¶
Index ¶
- Variables
- func FromContext(ctx context.Context) (token jwt.Claims, ok bool)
- func GenerateSignature(message string, secret string) string
- func GenerateToken(key string, opts ...Option) (string, error)
- func New(config JwtConfig) (*jwtMiddleware, error)
- func NewContext(ctx context.Context, info jwt.Claims) context.Context
- func ParseJwtToken(jwtToken string, opts ...Option) (jwt.Claims, error)
- func VerifySignature(ak, sk, timeStr, sign string) bool
- type JwtConfig
- type Option
- type TokenClaims
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrMissingJwtToken = errors.New("JWT token is missing") ErrMissingKeyFunc = errors.New("keyFunc is missing") ErrTokenInvalid = errors.New("Token is invalid") ErrTokenExpired = errors.New("JWT token has expired") ErrTokenParseFail = errors.New("Fail to parse JWT token ") ErrUnSupportSigningMethod = errors.New("Wrong signing method") ErrWrongContext = errors.New("Wrong context for middleware") ErrNeedTokenProvider = errors.New("Token provider is missing") ErrSignToken = errors.New("Can not sign token.Is the key correct?") ErrGetKey = errors.New("Can not get key while signing token") )
Functions ¶
func FromContext ¶ added in v0.0.11
FromContext extract auth info from context
func GenerateSignature ¶
GenerateSignature 生成签名
func GenerateToken ¶ added in v0.0.11
func NewContext ¶ added in v0.0.11
NewContext put auth info into context
func ParseJwtToken ¶ added in v0.0.11
ParseJwtToken 解析和验证令牌
Types ¶
type JwtConfig ¶
type JwtConfig struct { SigningKey interface{} // 用于签名的密钥 TokenLookup string // 定义如何查找令牌 SigningMethod string // 签名方法 ErrHandler func(w http.ResponseWriter, r *http.Request, err error) }
JwtConfig 定义了 JWT 中间件的配置
type Option ¶ added in v0.0.11
type Option func(*options)
Option is jwt option.
func WithClaims ¶ added in v0.0.11
func WithClaims(f func() jwt.Claims) Option
func WithKeyFunc ¶ added in v0.0.11
func WithKeyFunc(f jwt.Keyfunc) Option
func WithSigningMethod ¶ added in v0.0.11
func WithSigningMethod(method jwt.SigningMethod) Option
type TokenClaims ¶
type TokenClaims struct { Username string `json:"username"` // 在这里添加你想包含的其他声明 jwt.RegisteredClaims }
Click to show internal directories.
Click to hide internal directories.