Documentation
¶
Index ¶
- Variables
- type Auther
- type Cacher
- type CustomClaims
- type JWTAuth
- func (a *JWTAuth) DestroyRefreshToken(ctx context.Context, refreshToken string) error
- func (a *JWTAuth) DestroyToken(ctx context.Context, tokenStr string) error
- func (a *JWTAuth) GenerateRefreshToken(ctx context.Context, subject string, tenant string) (RefreshTokenInfo, error)
- func (a *JWTAuth) GenerateToken(ctx context.Context, subject string) (TokenInfo, error)
- func (a *JWTAuth) GenerateTokenWithExpired(ctx context.Context, subject string, expired int) (TokenInfo, error)
- func (a *JWTAuth) ParseRefreshToken(ctx context.Context, refreshToken string) (string, string, string, error)
- func (a *JWTAuth) ParseSubject(ctx context.Context, tokenStr string) (string, error)
- func (a *JWTAuth) Release(ctx context.Context) error
- type MemoryConfig
- type Option
- type RefreshTokenInfo
- type StoreOption
- type Storer
- type TokenInfo
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidToken = errors.New("Invalid token") ErrTokenRevoked = errors.New("Token has been revoked") )
Functions ¶
This section is empty.
Types ¶
type Auther ¶
type Auther interface {
// Generate a JWT (JSON Web Token) with the provided subject.
GenerateToken(ctx context.Context, subject string) (TokenInfo, error)
// Generate a JWT with custom expiration time.
GenerateTokenWithExpired(ctx context.Context, subject string, expired int) (TokenInfo, error)
// Generate a refresh token with the provided subject and tenant.
GenerateRefreshToken(ctx context.Context, subject string, tenant string) (RefreshTokenInfo, error)
// Parse and validate a refresh token, returns subject, tenant, jti.
ParseRefreshToken(ctx context.Context, refreshToken string) (string, string, string, error)
// Invalidate a token by removing it from the token store.
DestroyToken(ctx context.Context, accessToken string) error
// Invalidate a refresh token by adding it to the blacklist.
DestroyRefreshToken(ctx context.Context, refreshToken string) error
// Parse the subject (or user identifier) from a given access token.
ParseSubject(ctx context.Context, accessToken string) (string, error)
// Release any resources held by the JWTAuth instance.
Release(ctx context.Context) error
}
type Cacher ¶
type Cacher interface {
Set(ctx context.Context, ns, key, value string, expiration ...time.Duration) error
Get(ctx context.Context, ns, key string) (string, bool, error)
Exists(ctx context.Context, ns, key string) (bool, error)
Delete(ctx context.Context, ns, key string) error
Close(ctx context.Context) error
}
func NewMemoryCache ¶
func NewMemoryCache(cfg MemoryConfig) Cacher
type CustomClaims ¶
type CustomClaims struct {
jwt.StandardClaims
Type string `json:"type,omitempty"` // "access" or "refresh"
Tenant string `json:"tenant,omitempty"` // Tenant ID
}
CustomClaims includes standard claims plus custom fields for refresh token
type JWTAuth ¶
type JWTAuth struct {
// contains filtered or unexported fields
}
func (*JWTAuth) DestroyRefreshToken ¶
func (*JWTAuth) DestroyToken ¶
func (*JWTAuth) GenerateRefreshToken ¶
func (*JWTAuth) GenerateToken ¶
func (*JWTAuth) GenerateTokenWithExpired ¶
func (*JWTAuth) ParseRefreshToken ¶
func (*JWTAuth) ParseSubject ¶
type MemoryConfig ¶
type Option ¶
type Option func(*options)
func SetExpired ¶
func SetRefreshExpired ¶
func SetSigningKey ¶
func SetSigningMethod ¶
func SetSigningMethod(method jwt.SigningMethod) Option
type RefreshTokenInfo ¶
type StoreOption ¶
type StoreOption func(*storeOptions)
func WithCacheNS ¶
func WithCacheNS(ns string) StoreOption
type Storer ¶
type Storer interface {
Set(ctx context.Context, tokenStr string, expiration time.Duration) error
Delete(ctx context.Context, tokenStr string) error
Check(ctx context.Context, tokenStr string) (bool, error)
Close(ctx context.Context) error
}
Storer is the interface that storage the token.
func NewStoreWithCache ¶
func NewStoreWithCache(cache Cacher, opts ...StoreOption) Storer
Click to show internal directories.
Click to hide internal directories.