Documentation ¶
Index ¶
- Variables
- type DefaultStore
- type DefaultToken
- func (dt *DefaultToken[T, F]) CreateToken(ctx context.Context, claim jwt.Claims, expire ...time.Duration) (T, error)
- func (dt *DefaultToken[T, F]) RefreshToken(ctx context.Context, token T, claim jwt.Claims, expire ...time.Duration) (T, error)
- func (dt *DefaultToken[T, F]) Store() Store[T]
- func (dt *DefaultToken[T, F]) Validate(token T) (jwt.Claims, error)
- type Fun
- type Option
- type RStore
- type Store
- type Token
- type Type
- type Val
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrTokenNotFound = errors.New("token not found") ErrInvalidKey = errors.New("key is invalid") ErrTokenTimeout = errors.New("token is expired") )
View Source
var (
ErrNotString = errors.New("type is not string")
)
Functions ¶
This section is empty.
Types ¶
type DefaultStore ¶
type DefaultStore[T Type] struct { // contains filtered or unexported fields }
func (*DefaultStore[T]) Delete ¶
func (ds *DefaultStore[T]) Delete(token T) error
func (*DefaultStore[T]) Exists ¶
func (ds *DefaultStore[T]) Exists(token T) bool
type DefaultToken ¶
type DefaultToken[T string, F Fun] struct { Expire time.Duration // contains filtered or unexported fields }
func (*DefaultToken[T, F]) CreateToken ¶
func (dt *DefaultToken[T, F]) CreateToken(ctx context.Context, claim jwt.Claims, expire ...time.Duration) (T, error)
CreateToken creates a new token. jwt claim token to string `f` is a function that returns jwt.SigningMethod, []byte, jwt.Claims not `f` is struct dt.f
func (*DefaultToken[T, F]) RefreshToken ¶
func (dt *DefaultToken[T, F]) RefreshToken(ctx context.Context, token T, claim jwt.Claims, expire ...time.Duration) (T, error)
RefreshToken creates a new refresh token. The old token is revoked or set token to Expire. `token` is the old token.
func (*DefaultToken[T, F]) Store ¶
func (dt *DefaultToken[T, F]) Store() Store[T]
type Fun ¶
type Fun interface { func() (jwt.SigningMethod, []byte) }
type Store ¶
type Store[T Type] interface { // Set a token to the store with the specified expiry time. Set(token T, expiry time.Duration) error // Exists checks if a token exists in the store. Exists(token T) bool // Delete a token from the store. Delete(token T) error // Shutdown the store. Shutdown(ctx context.Context) <-chan error }
func NewDefaultStore ¶
type Token ¶
type Token[T Type, V Val] interface { // CreateToken creates a new token. CreateToken(ctx context.Context, claim jwt.Claims, expire ...time.Duration) (T, error) // RefreshToken creates a new refresh token. // The old token is revoked or set token to Expire. RefreshToken(ctx context.Context, token T, claim jwt.Claims, expire ...time.Duration) (T, error) // Validate validates a token. Validate(token T) (jwt.Claims, error) // Store returns the store used by the token. Store() Store[T] }
Click to show internal directories.
Click to hide internal directories.