jwt

package
v0.5.19 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// bearerWord the bearer key word for authorization
	BearerWord string = "Bearer"

	// authorizationKey holds the key used to store the JWT Token in the request tokenHeader.
	AuthorizationKey string = "Authorization"
)

Variables

View Source
var (
	ErrMissingJwtToken        = errors.Unauthorized("JWT token is missing")
	ErrMissingKeyFunc         = errors.Unauthorized("secret is missing")
	ErrTokenInvalid           = errors.Unauthorized("Token is invalid")
	ErrTokenExpired           = errors.Unauthorized("JWT token has expired")
	ErrTokenParseFail         = errors.Unauthorized("Fail to parse JWT token ")
	ErrUnSupportSigningMethod = errors.Unauthorized("Wrong signing method")
	ErrWrongContext           = errors.Unauthorized("Wrong context for middleware")
	ErrNeedTokenProvider      = errors.Unauthorized("Token provider is missing")
	ErrSignToken              = errors.Unauthorized("Can not sign token.Is the key correct?")
	ErrGetKey                 = errors.Unauthorized("Can not get key while signing token")
	ErrSignMethod             = errors.Unauthorized("error sign method.")
)

Functions

func FromContext

func FromContext(ctx context.Context) (token map[string]interface{}, ok bool)

FromContext extract auth info from context

func NewContext

func NewContext(ctx context.Context, info map[string]interface{}) context.Context

NewContext put auth info into context

func Sign

func Sign(signingMethod string, secret interface{}, data map[string]interface{}, timeout int64, opts ...Option) (string, error)

timeout 秒

func Verify

func Verify(tokenVal string, secret interface{}) (map[string]interface{}, error)

Types

type Keyfunc added in v0.2.2

type Keyfunc func(jwt.Claims) ([]byte, error)

type Option added in v0.2.2

type Option func(map[string]any)

func WithSNo added in v0.2.2

func WithSNo(serialNo string) Option

Jump to

Keyboard shortcuts

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