Documentation
¶
Overview ¶
Package jwt implements the functions, types, and interfaces for the module.
Package jwt implements the functions, types, and interfaces for the module.
Package jwt implements the functions, types, and interfaces for the module.
Index ¶
- Variables
- func ClaimsToJwtClaims(raw security.Claims) jwtv5.Claims
- func GetKeyFunc(key string) func(token *jwtv5.Token) (any, error)
- func GetKeyFuncWithAlg(alg, key string) func(token *jwtv5.Token) (any, error)
- func GetSigningMethodFromAlg(algorithm string) jwtv5.SigningMethod
- func MapToClaims(rawClaims jwtv5.MapClaims, extraKeys ...string) (security.Claims, error)
- func NewAuthenticator(cfg *configv1.Security, ss ...Setting) (security.Authenticator, error)
- func RegisteredToClaims(rawClaims *jwtv5.RegisteredClaims) (security.Claims, error)
- func ToClaims(rawClaims jwtv5.Claims, extraKeys ...string) (security.Claims, error)
- type Authenticator
- func (obj *Authenticator) ApplyDefaults() error
- func (obj *Authenticator) Authenticate(ctx context.Context, tokenStr string) (bool, error)
- func (obj *Authenticator) AuthenticateContext(ctx context.Context, tokenType security.TokenType) (bool, error)
- func (obj *Authenticator) AuthenticateToken(ctx context.Context, tokenStr string) (security.Claims, error)
- func (obj *Authenticator) AuthenticateTokenContext(ctx context.Context, tokenType security.TokenType) (security.Claims, error)
- func (obj *Authenticator) Close(ctx context.Context) error
- func (obj *Authenticator) CreateToken(ctx context.Context, claims security.Claims) (string, error)
- func (obj *Authenticator) CreateTokenContext(ctx context.Context, tokenType security.TokenType, claims security.Claims) (context.Context, error)
- func (obj *Authenticator) DestroyToken(ctx context.Context, tokenStr string) error
- func (obj *Authenticator) DestroyTokenContext(ctx context.Context, token security.TokenType) error
- func (obj *Authenticator) WithConfig(config *configv1.AuthNConfig_JWTConfig) error
- type SecurityClaims
- func (s *SecurityClaims) GetAudience() []string
- func (s *SecurityClaims) GetExpiration() time.Time
- func (s *SecurityClaims) GetExtra() map[string]string
- func (s *SecurityClaims) GetIssuedAt() time.Time
- func (s *SecurityClaims) GetIssuer() string
- func (s *SecurityClaims) GetJWTID() string
- func (s *SecurityClaims) GetNotBefore() time.Time
- func (s *SecurityClaims) GetScopes() map[string]bool
- func (s *SecurityClaims) GetSubject() string
- type Setting
- func WithCache(cache security.TokenCacheService) Setting
- func WithExtraKeys(extraKeys ...string) Setting
- func WithKeyFunc(keyFunc func(token *jwtv5.Token) (any, error)) Setting
- func WithScheme(scheme security.Scheme) Setting
- func WithScoped(scoped bool) Setting
- func WithSigningMethod(signingMethod jwtv5.SigningMethod) Setting
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidToken = securityv1.ErrorAuthErrorReasonBearerTokenMissing("invalid bearer token") ErrTokenNotFound = securityv1.ErrorAuthErrorReasonTokenNotFound("token not found") ErrTokenMalformed = securityv1.ErrorAuthErrorReasonBearerTokenMissing("token malformed") ErrTokenSignatureInvalid = securityv1.ErrorAuthErrorReasonSignTokenFailed("token signature invalid") ErrTokenExpired = securityv1.ErrorAuthErrorReasonTokenExpired("token expired") ErrTokenNotValidYet = securityv1.ErrorAuthErrorReasonTokenExpired("token not valid yet") ErrUnsupportedSigningMethod = securityv1.ErrorAuthErrorReasonUnsupportedSigningMethod("unsupported signing method") ErrInvalidClaims = securityv1.ErrorAuthErrorReasonInvalidClaims("invalid Claims") ErrBearerTokenMissing = securityv1.ErrorAuthErrorReasonBearerTokenMissing("bearer token missing") ErrSignTokenFailed = securityv1.ErrorAuthErrorReasonSignTokenFailed("sign token failed") ErrMissingKeyFunc = securityv1.ErrorAuthErrorReasonMissingKeyFunc("missing key function") ErrGetKeyFailed = securityv1.ErrorAuthErrorReasonGetKeyFailed("get key failed") ErrInvalidSubject = securityv1.ErrorAuthErrorReasonInvalidSubject("invalid subject") ErrInvalidIssuer = securityv1.ErrorAuthErrorReasonInvalidIssuer("invalid issuer") ErrInvalidAudience = securityv1.ErrorAuthErrorReasonInvalidAudience("invalid audience") ErrInvalidExpiration = securityv1.ErrorAuthErrorReasonInvalidExpiration("invalid expiration") )
Functions ¶
func GetKeyFunc ¶
GetKeyFunc returns a function that retrieves the key for a given token. The returned function takes a jwtv5.Token as an argument and returns the key as a string.
func GetKeyFuncWithAlg ¶
GetKeyFuncWithAlg returns a function that retrieves the key for a given token with a specific algorithm. The returned function takes a jwtv5.Token as an argument and returns the key as a byte slice.
func GetSigningMethodFromAlg ¶
func GetSigningMethodFromAlg(algorithm string) jwtv5.SigningMethod
GetSigningMethodFromAlg returns the signing method for a given algorithm.
func MapToClaims ¶
func NewAuthenticator ¶
NewAuthenticator creates a new Authenticator.
func RegisteredToClaims ¶
func RegisteredToClaims(rawClaims *jwtv5.RegisteredClaims) (security.Claims, error)
Types ¶
type Authenticator ¶
type Authenticator struct {
// contains filtered or unexported fields
}
Authenticator is a struct that implements the Authenticator interface.
func (*Authenticator) ApplyDefaults ¶
func (obj *Authenticator) ApplyDefaults() error
func (*Authenticator) Authenticate ¶
Authenticate authenticates the token string.
func (*Authenticator) AuthenticateContext ¶
func (obj *Authenticator) AuthenticateContext(ctx context.Context, tokenType security.TokenType) (bool, error)
AuthenticateContext authenticates the token string from the context.
func (*Authenticator) AuthenticateToken ¶
func (obj *Authenticator) AuthenticateToken(ctx context.Context, tokenStr string) (security.Claims, error)
AuthenticateToken authenticates the token string.
func (*Authenticator) AuthenticateTokenContext ¶
func (obj *Authenticator) AuthenticateTokenContext(ctx context.Context, tokenType security.TokenType) (security.Claims, error)
AuthenticateTokenContext authenticates the token string from the context.
func (*Authenticator) Close ¶
func (obj *Authenticator) Close(ctx context.Context) error
Close closes the token cache service.
func (*Authenticator) CreateToken ¶
CreateToken creates a token string from the claims.
func (*Authenticator) CreateTokenContext ¶
func (obj *Authenticator) CreateTokenContext(ctx context.Context, tokenType security.TokenType, claims security.Claims) (context.Context, error)
CreateTokenContext creates a token string from the claims and adds it to the context.
func (*Authenticator) DestroyToken ¶
func (obj *Authenticator) DestroyToken(ctx context.Context, tokenStr string) error
DestroyToken destroys the token string.
func (*Authenticator) DestroyTokenContext ¶
DestroyTokenContext destroys the token string from the context.
func (*Authenticator) WithConfig ¶
func (obj *Authenticator) WithConfig(config *configv1.AuthNConfig_JWTConfig) error
type SecurityClaims ¶
type SecurityClaims struct { *securityv1.Claims Extra map[string]string }
func (*SecurityClaims) GetAudience ¶
func (s *SecurityClaims) GetAudience() []string
func (*SecurityClaims) GetExpiration ¶
func (s *SecurityClaims) GetExpiration() time.Time
func (*SecurityClaims) GetExtra ¶
func (s *SecurityClaims) GetExtra() map[string]string
func (*SecurityClaims) GetIssuedAt ¶
func (s *SecurityClaims) GetIssuedAt() time.Time
func (*SecurityClaims) GetIssuer ¶
func (s *SecurityClaims) GetIssuer() string
func (*SecurityClaims) GetJWTID ¶
func (s *SecurityClaims) GetJWTID() string
func (*SecurityClaims) GetNotBefore ¶
func (s *SecurityClaims) GetNotBefore() time.Time
func (*SecurityClaims) GetScopes ¶
func (s *SecurityClaims) GetScopes() map[string]bool
func (*SecurityClaims) GetSubject ¶
func (s *SecurityClaims) GetSubject() string
type Setting ¶
type Setting = func(*Authenticator)
Setting is a function type for setting the Authenticator.
func WithCache ¶
func WithCache(cache security.TokenCacheService) Setting
WithCache returns a Setting function that sets the token cache service for an Authenticator.
func WithExtraKeys ¶
WithExtraKeys returns a Setting function that sets the extra keys for an Authenticator.
func WithKeyFunc ¶
WithKeyFunc returns a Setting function that sets the key function for an Authenticator. The key function is used to retrieve the key for a given token.
func WithScheme ¶
WithScheme returns a Setting function that sets the scheme for an Authenticator.
func WithScoped ¶
WithScoped returns a Setting function that sets the scoped flag for an Authenticator. The scoped flag determines whether the Authenticator should use scoped tokens.
func WithSigningMethod ¶
func WithSigningMethod(signingMethod jwtv5.SigningMethod) Setting
WithSigningMethod returns a Setting function that sets the signing method for an Authenticator. The signing method is used to sign and verify tokens.