parser

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AlgorithmHS256 is token signing algorithm
	AlgorithmHS256 = "HS256"
)

Variables

This section is empty.

Functions

func WithJWTMapClaims

func WithJWTMapClaims(signingKey any) jwtParserOpt

WithJWTMapClaims returns a jwtParser with default jwt.MapClaims and signingMethod

func WithKeyFunc

func WithKeyFunc(keyFunc jwt.Keyfunc) jwtParserOpt

func WithNewClaimsFunc

func WithNewClaimsFunc(newClaimsFunc func(context.Context) jwt.Claims) jwtParserOpt

WithNewClaimsFunc sets NewClaimsFunc. the newClaimsFunc must return a reference for json unmarshalling to work

func WithSigningKey

func WithSigningKey(signingKey any) jwtParserOpt

func WithSigningKeys

func WithSigningKeys(signingKeys map[string]any) jwtParserOpt

func WithSigningMethod

func WithSigningMethod(signingMethod string) jwtParserOpt

Types

type JwtParser

type JwtParser struct {
	// Signing key to validate token.
	// This is one of the three options to provide a token validation key.
	// The order of precedence is a user-defined KeyFunc, SigningKeys and SigningKey.
	// Required if neither user-defined KeyFunc nor SigningKeys is provided.
	SigningKey any
	// KeyFunc defines a user-defined function that supplies the public key for a token validation.
	// The function shall take care of verifying the signing algorithm and selecting the proper key.
	// A user-defined KeyFunc can be useful if tokens are issued by an external party.
	// Used by default ParseTokenFunc implementation.
	//
	// When a user-defined KeyFunc is provided, SigningKey, SigningKeys, and SigningMethod are ignored.
	// This is one of the three options to provide a token validation key.
	// The order of precedence is a user-defined KeyFunc, SigningKeys and SigningKey.
	// Required if neither SigningKeys nor SigningKey is provided.
	// Default to an internal implementation verifying the signing algorithm and selecting the proper key.
	KeyFunc jwt.Keyfunc
	// Map of signing keys to validate token with kid field usage.
	// This is one of the three options to provide a token validation key.
	// The order of precedence is a user-defined KeyFunc, SigningKeys and SigningKey.
	// Required if neither user-defined KeyFunc nor SigningKey is provided.
	SigningKeys map[string]any
	// Signing method used to check the token's signing algorithm.
	// Optional. Default value HS256.
	SigningMethod string
	// NewClaimsFunc is used during parsing the token, it must return a reference for json unmarshalling to work
	// Default to function returning jwt.MapClaims
	NewClaimsFunc func(c context.Context) jwt.Claims
}

func NewJwtParser

func NewJwtParser(opts ...jwtParserOpt) (JwtParser, error)

func (JwtParser) Parse

func (j JwtParser) Parse(ctx context.Context, token string) (jwt.Claims, error)

Jump to

Keyboard shortcuts

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