token

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const PluginName = "token"

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	PrivateKey string `mapstructure:"private_key"`
	TTL        struct {
		JWT     time.Duration `mapstructure:"jwt"`
		Refresh time.Duration `mapstructure:"refresh"`
	} `mapstructure:"ttl"`
}

func (*Config) InitDefault

func (cfg *Config) InitDefault()

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

func (*Plugin) Init

func (p *Plugin) Init(cfg config.Configurer, s storage.UserStorage, client redis.UniversalClient) error

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns user-friendly plugin name

func (*Plugin) SessByRefreshToken

func (p *Plugin) SessByRefreshToken(ctx context.Context, refreshToken string) (Session, error)

func (*Plugin) SessByUser

func (p *Plugin) SessByUser(ctx context.Context, user models.User, metadata any) (Session, error)

func (*Plugin) ValidateJWT

func (p *Plugin) ValidateJWT(ctx context.Context, token string) (jwt.UserClaims, models.User, error)

type Service

type Service interface {
	ValidateJWT(ctx context.Context, token string) (jwt.UserClaims, models.User, error)
	SessByRefreshToken(ctx context.Context, refreshToken string) (Session, error)
	SessByUser(ctx context.Context, user models.User, metadata any) (Session, error)
}

type Session

type Session struct {
	ExpiresIn    uint   `json:"expires_in"` // The lifetime in seconds of refresh token
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type Storage

type Storage interface {
	Set(ctx context.Context, refreshToken string, data StorageData, expiration time.Duration) error
	Get(ctx context.Context, refreshToken string) (StorageData, error)
	Del(ctx context.Context, refreshToken string)
}

type StorageData

type StorageData struct {
	Id       string `json:"id,omitempty"`
	Metadata any    `json:"metadata,omitempty"`
}

Jump to

Keyboard shortcuts

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