jwtx

package
v0.0.0-...-1b17b00 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

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
}

func New

func New(store Storer, opts ...Option) Auther

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 (a *JWTAuth) DestroyToken(ctx context.Context, tokenStr string) error

func (*JWTAuth) GenerateToken

func (a *JWTAuth) GenerateToken(ctx context.Context, subject string) (TokenInfo, error)

func (*JWTAuth) ParseSubject

func (a *JWTAuth) ParseSubject(ctx context.Context, tokenStr string) (string, error)

func (*JWTAuth) Release

func (a *JWTAuth) Release(ctx context.Context) error

type MemoryConfig

type MemoryConfig struct {
	CleanupInterval time.Duration
}

type Option

type Option func(*options)

func SetExpired

func SetExpired(expired int) Option

func SetSigningKey

func SetSigningKey(key, oldKey string) Option

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

type TokenInfo

type TokenInfo interface {
	GetAccessToken() string
	GetTokenType() string
	GetExpiresAt() int64
	EncodeToJSON() ([]byte, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL