Documentation ¶
Index ¶
Constants ¶
View Source
const (
AlgorithmHS256 = "HS256"
)
Variables ¶
Functions ¶
func ParseSigningKeyFromString ¶
ParseSigningKeyFromString parses a key([]byte or rsa Key) from a string.
keystr format: - file uri: "file:///path/to/key",such as rsa file - string: "raw key",such as hs256 key or rsa rwa key string private key: if need to use private key,such as rsa private key
Types ¶
type JWTOptions ¶
type JWTOptions 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 // 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 // Claims are extendable claims data defining token content. Used by default ParseTokenFunc implementation. // Not used if custom ParseTokenFunc is set. // Optional. Default value jwt.MapClaims Claims jwt.Claims // TokenLookup is a string in the form of "<source>:<name>" or "<source>:<name>,<source>:<name>" that is used // to extract token from the request. // Optional. Default value "header:Authorization". // Possible values: // - "header:<name>" or "header:<name>:<cut-prefix>" // `<cut-prefix>` is argument value to cut/trim prefix of the extracted value. This is useful if header // value has static prefix like `Authorization: <auth-scheme> <authorisation-parameters>` where part that we // want to cut is `<auth-scheme> ` note the space at the end. // In case of JWT tokens `Authorization: Bearer <token>` prefix we cut is `Bearer `. // If prefix is left empty the whole value is returned. // - "query:<name>" // - "param:<name>" // - "cookie:<name>" // - "form:<name>" // Multiple sources example: // - "header:Authorization,cookie:myowncookie" TokenLookup string // AuthScheme to be used in the Authorization header. // Optional. Default value "Bearer". AuthScheme string // 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. // Not used if custom ParseTokenFunc is set. // Default to an internal implementation verifying the signing algorithm and selecting the proper key. KeyFunc jwt.Keyfunc // ParseTokenFunc defines a user-defined function that parses token from given auth. Returns an error when token // parsing fails or parsed token is invalid. // Defaults to implementation using `github.com/golang-jwt/jwt` as JWT implementation library ParseTokenFunc func(ctx context.Context, auth string) (*jwt.Token, error) // GetTokenIDFunc is a function that returns the value of token id. default return jwt.RegisteredClaims ID GetTokenIDFunc func(token *jwt.Token) (id string, exists bool) }
func NewJWTOptions ¶ added in v0.4.0
func NewJWTOptions() *JWTOptions
NewJWTOptions return a new JWTOptions
func (*JWTOptions) Init ¶ added in v0.4.0
func (opts *JWTOptions) Init() (err error)
Init initial JWTOptions
Click to show internal directories.
Click to hide internal directories.