Documentation ¶
Index ¶
- Variables
- type Auther
- type Cacher
- type JWTAuth
- func (a *JWTAuth) DestroyToken(ctx context.Context, tokenStr string) error
- func (a *JWTAuth) GenerateToken(ctx context.Context, subject string) (TokenInfo, 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 StoreOption
- type Storer
- type TokenInfo
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalidToken = errors.New("invalid token")
Functions ¶
This section is empty.
Types ¶
type Auther ¶
type Auther interface { // GenerateToken Generate a JWT (JSON Web Token) with the provided subject. GenerateToken(ctx context.Context, subject string) (TokenInfo, error) // DestroyToken Invalidate a token by removing it from the token store. DestroyToken(ctx context.Context, accessToken string) error // ParseSubject 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 JWTAuth ¶
type JWTAuth struct {
// contains filtered or unexported fields
}
func (*JWTAuth) DestroyToken ¶
func (*JWTAuth) GenerateToken ¶
func (*JWTAuth) ParseSubject ¶
type MemoryConfig ¶
type Option ¶
type Option func(*options)
func SetExpired ¶
func SetSigningKey ¶
func SetSigningMethod ¶
func SetSigningMethod(method jwt.SigningMethod) Option
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.