Documentation ¶
Index ¶
- Variables
- func Client(keyProvider jwt.Keyfunc, opts ...Option) middleware.Middleware
- func FromContext(ctx context.Context) (token jwt.Claims, ok bool)
- func FromTokenContext(ctx context.Context) (token string, ok bool)
- func NewContext(ctx context.Context, info jwt.Claims) context.Context
- func NewToken(keyProvider jwt.Keyfunc, opts ...Option) (string, error)
- func NewTokenContext(ctx context.Context, token string) context.Context
- func Server(keyFunc jwt.Keyfunc, opts ...Option) middleware.Middleware
- type Option
- func WithBlacklist(f func(ctx context.Context) bool) Option
- func WithClaims(f func() jwt.Claims) Option
- func WithHandleClaims(f func(ctx context.Context, claims jwt.Claims) context.Context) Option
- func WithSigningMethod(method jwt.SigningMethod) Option
- func WithTokenHeader(header map[string]any) Option
- func WithWhitelist(f func(ctx context.Context) bool) Option
Constants ¶
This section is empty.
Variables ¶
var ( ErrLoseEfficacyJwtToken = errors.Unauthorized(reason, "JWT token is lose efficacy") ErrMissingJwtToken = errors.Unauthorized(reason, "JWT token is missing") ErrMissingKeyFunc = errors.Unauthorized(reason, "keyFunc is missing") ErrTokenInvalid = errors.Unauthorized(reason, "Token is invalid") ErrTokenExpired = errors.Unauthorized(reason, "JWT token has expired") ErrTokenParseFail = errors.Unauthorized(reason, "Fail to parse JWT token ") ErrUnSupportSigningMethod = errors.Unauthorized(reason, "Wrong signing method") ErrWrongContext = errors.Unauthorized(reason, "Wrong context for middleware") ErrNeedTokenProvider = errors.Unauthorized(reason, "Token provider is missing") ErrSignToken = errors.Unauthorized(reason, "Can not sign token.Is the key correct?") ErrGetKey = errors.Unauthorized(reason, "Can not get key while signing token") )
Functions ¶
func Client ¶
func Client(keyProvider jwt.Keyfunc, opts ...Option) middleware.Middleware
Client is a client jwt middleware.
func FromContext ¶
FromContext extract auth info from context
func FromTokenContext ¶ added in v1.0.14
FromTokenContext extract auth info from context
func NewContext ¶
NewContext put auth info into context
func NewTokenContext ¶ added in v1.0.14
NewTokenContext put auth info into context
func Server ¶
func Server(keyFunc jwt.Keyfunc, opts ...Option) middleware.Middleware
Server is a server auth middleware. Check the token and extract the info from token.
Types ¶
type Option ¶
type Option func(*options)
Option is jwt option.
func WithBlacklist ¶ added in v1.0.16
WithBlacklist with jwt whitelist option.
func WithClaims ¶
func WithClaims(f func() jwt.Claims) Option
WithClaims with customer claim If you use it in Server, f needs to return a new jwt.Claims object each time to avoid concurrent write problems If you use it in Client, f only needs to return a single object to provide performance
func WithHandleClaims ¶ added in v1.0.16
WithHandleClaims with jwt claims option.
func WithSigningMethod ¶
func WithSigningMethod(method jwt.SigningMethod) Option
WithSigningMethod with signing method option.
func WithTokenHeader ¶
WithTokenHeader withe customer tokenHeader for client side