jwt

package
v0.0.0-...-6102823 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2024 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	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(opts ...Option) middleware.Middleware

Client is a client jwt middleware.

func ClientGrpcAuth

func ClientGrpcAuth(ctx context.Context, opts ...Option) (context.Context, error)

Client is a client jwt middleware.

func FromContext

func FromContext(ctx context.Context) (token jwtlib.Claims, ok bool)

FromContext extract auth info from context

func GetEmail

func GetEmail(ctx context.Context) string

func GetUserId

func GetUserId(ctx context.Context) (string, error)

func NewContext

func NewContext(ctx context.Context, info jwtlib.Claims) context.Context

NewContext put auth info into context

func Server

func Server(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 WithAutoParse

func WithAutoParse(autoParse bool) Option

func WithClaims

func WithClaims(f func() jwtlib.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 WithCustomKeyFunc

func WithCustomKeyFunc(keyFunc jwtlib.Keyfunc) Option

func WithExcludes

func WithExcludes(excludes string) Option

func WithRequired

func WithRequired(required bool) Option

func WithSecretKey

func WithSecretKey(key string) Option

func WithSigningMethod

func WithSigningMethod(method jwtlib.SigningMethod) Option

WithSigningMethod with signing method option.

func WithTokenHeader

func WithTokenHeader(header map[string]interface{}) Option

WithTokenHeader with customer tokenHeader for client side

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL