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 GetAlgorithmSigningMethod(algorithm string) jwtv5.SigningMethod
- func GetKeyFunc(key string) func(token *jwtv5.Token) (any, error)
- func GetKeyFuncWithAlg(alg, key string) func(token *jwtv5.Token) (any, error)
- func MapToClaims(rawClaims jwtv5.MapClaims, extras map[string]string) (security.Claims, error)
- func NewAuthenticator(cfg *configv1.Security, ss ...Setting) (security.Authenticator, error)
- func ProtoClaimsToClaims(rawClaims *securityv1.Claims) security.Claims
- func RegisteredToClaims(rawClaims *jwtv5.RegisteredClaims) (security.Claims, error)
- func ToClaims(rawClaims jwtv5.Claims, extras map[string]string) (security.Claims, error)
- type Authenticator
- func (obj *Authenticator) Authenticate(ctx context.Context, tokenStr string) (security.Claims, error)
- func (obj *Authenticator) AuthenticateContext(ctx context.Context, tokenType security.TokenType) (security.Claims, error)
- func (obj *Authenticator) Close(ctx context.Context) error
- func (obj *Authenticator) CreateIdentityClaims(_ context.Context, id string, refresh bool) (security.Claims, error)
- func (obj *Authenticator) CreateIdentityClaimsContext(ctx context.Context, tokenType security.TokenType, id string) (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) Verify(ctx context.Context, tokenStr string) (bool, error)
- func (obj *Authenticator) VerifyContext(ctx context.Context, tokenType security.TokenType) (bool, error)
- type Option
- 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 WithAudience(audience []string) Setting
- func WithCache(cache security.TokenCacheService) Setting
- func WithExpireAccess(expiresAt time.Duration) Setting
- func WithExpireRefresh(expiresAt time.Duration) Setting
- func WithExtraClaims(extras map[string]string) Setting
- func WithIssuer(issuer string) Setting
- func WithJTI(fn func() string) Setting
- func WithKeyFunc(keyFunc func(token *jwtv5.Token) (any, error)) Setting
- func WithScheme(scheme security.Scheme) Setting
- func WithScopes(scopes map[string]bool) Setting
- func WithSigningMethod(signingMethod jwtv5.SigningMethod) Setting
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidToken = securityv1.ErrorSecurityErrorReasonBearerTokenMissing("invalid bearer token") ErrTokenNotFound = securityv1.ErrorSecurityErrorReasonTokenNotFound("token not found") ErrTokenMalformed = securityv1.ErrorSecurityErrorReasonBearerTokenMissing("token malformed") ErrTokenSignatureInvalid = securityv1.ErrorSecurityErrorReasonSignTokenFailed("token signature invalid") ErrTokenExpired = securityv1.ErrorSecurityErrorReasonTokenExpired("token expired") ErrTokenNotValidYet = securityv1.ErrorSecurityErrorReasonTokenExpired("token not valid yet") ErrUnsupportedSigningMethod = securityv1.ErrorSecurityErrorReasonUnsupportedSigningMethod("unsupported signing method") ErrInvalidClaims = securityv1.ErrorSecurityErrorReasonInvalidClaims("invalid Claims") ErrBearerTokenMissing = securityv1.ErrorSecurityErrorReasonBearerTokenMissing("bearer token missing") ErrSignTokenFailed = securityv1.ErrorSecurityErrorReasonSignTokenFailed("sign token failed") ErrMissingKeyFunc = securityv1.ErrorSecurityErrorReasonMissingKeyFunc("missing key function") ErrGetKeyFailed = securityv1.ErrorSecurityErrorReasonGetKeyFailed("get key failed") ErrInvalidSubject = securityv1.ErrorSecurityErrorReasonInvalidSubject("invalid subject") ErrInvalidIssuer = securityv1.ErrorSecurityErrorReasonInvalidIssuer("invalid issuer") ErrInvalidAudience = securityv1.ErrorSecurityErrorReasonInvalidAudience("invalid audience") ErrInvalidExpiration = securityv1.ErrorSecurityErrorReasonInvalidExpiration("invalid expiration") )
Functions ¶
func GetAlgorithmSigningMethod ¶ added in v0.0.3
func GetAlgorithmSigningMethod(algorithm string) jwtv5.SigningMethod
GetAlgorithmSigningMethod returns the signing method for a given algorithm.
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 MapToClaims ¶
func NewAuthenticator ¶
NewAuthenticator creates a new Authenticator.
func ProtoClaimsToClaims ¶
func ProtoClaimsToClaims(rawClaims *securityv1.Claims) security.Claims
func RegisteredToClaims ¶
func RegisteredToClaims(rawClaims *jwtv5.RegisteredClaims) (security.Claims, error)
Types ¶
type Authenticator ¶
type Authenticator struct { *Option // contains filtered or unexported fields }
Authenticator is a struct that implements the Authenticator interface.
func (*Authenticator) Authenticate ¶
func (*Authenticator) AuthenticateContext ¶
func (*Authenticator) Close ¶
func (obj *Authenticator) Close(ctx context.Context) error
Close closes the token cache service.
func (*Authenticator) CreateIdentityClaims ¶
func (*Authenticator) CreateIdentityClaimsContext ¶
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) VerifyContext ¶
type Option ¶ added in v0.0.3
type Option struct {
// contains filtered or unexported fields
}
func (*Option) ApplyDefaults ¶ added in v0.0.3
func (*Option) WithConfig ¶ added in v0.0.3
func (option *Option) 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(*Option)
Setting is a function type for setting the Authenticator.
func WithAudience ¶ added in v0.0.3
WithAudience returns a Setting function that sets the audience for an Authenticator.
func WithCache ¶
func WithCache(cache security.TokenCacheService) Setting
WithCache returns a Setting function that sets the token cache service for an Authenticator.
func WithExpireAccess ¶ added in v0.0.3
WithExpireAccess returns a Setting function that sets the expiration time for an Authenticator.
func WithExpireRefresh ¶ added in v0.0.3
WithExpireRefresh returns a Setting function that sets the expiration time for an Authenticator.
func WithExtraClaims ¶ added in v0.0.3
WithExtraClaims returns a Setting function that sets the extra keys for an Authenticator.
func WithIssuer ¶ added in v0.0.3
WithIssuer returns a Setting function that sets the issuer for an Authenticator.
func WithJTI ¶ added in v0.0.3
WithJTI returns a Setting function that sets the JTI generator function 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 WithScopes ¶ added in v0.0.3
WithScopes 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.