Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrTokenInvalid = errors.Unauthorized(reason, "Token is invalid") ErrTokenExpired = errors.Unauthorized(reason, "Token has expired") ErrTokenParseFail = errors.Unauthorized(reason, "Fail to parse token") ErrUnSupportSigningMethod = errors.Unauthorized(reason, "Wrong signing method") ErrSignTokenFailed = errors.Unauthorized(reason, "Failed to sign token") )
View Source
var ( MessageTokenInvalid = &goi18n.Message{ID: "jwt.token.invalid", Other: ErrTokenInvalid.Error()} MessageTokenExpired = &goi18n.Message{ID: "jwt.token.expired", Other: ErrTokenExpired.Error()} MessageTokenParseFail = &goi18n.Message{ID: "jwt.token.parse.failed", Other: ErrTokenParseFail.Error()} MessageUnSupportSigningMethod = &goi18n.Message{ID: "jwt.wrong.signing.method", Other: ErrUnSupportSigningMethod.Error()} MessageSignTokenFailed = &goi18n.Message{ID: "jwt.token.sign.failed", Other: ErrSignTokenFailed.Error()} )
Define i18n messages.
Functions ¶
This section is empty.
Types ¶
type JWTAuth ¶
type JWTAuth struct {
// contains filtered or unexported fields
}
JWTAuth implement the authn.Authenticator interface.
func (*JWTAuth) ParseClaims ¶
func (a *JWTAuth) ParseClaims(ctx context.Context, refreshToken string) (*jwt.RegisteredClaims, error)
ParseClaims parse the token and return the claims.
type Option ¶
type Option func(*options)
Option is jwt option.
func WithExpired ¶
WithExpired set the token expiration time (in seconds, default 2h).
func WithIssuer ¶
WithIssuer set token issuer which is identifies the principal that issued the JWT.
func WithKeyfunc ¶
func WithKeyfunc(keyFunc jwt.Keyfunc) Option
WithKeyfunc set the callback function for verifying the key.
func WithSigningMethod ¶
func WithSigningMethod(method jwt.SigningMethod) Option
WithSigningMethod set signature method.
func WithTokenHeader ¶
WithTokenHeader set the customer tokenHeader for client side.
type Storer ¶
type Storer interface { // Store token data and specify expiration time. Set(ctx context.Context, accessToken string, expiration time.Duration) error // Delete token data from storage. Delete(ctx context.Context, accessToken string) (bool, error) // Check if token exists. Check(ctx context.Context, accessToken string) (bool, error) // Close the storage. Close() error }
Storer token storage interface.
Click to show internal directories.
Click to hide internal directories.