jwt

package
v0.0.0-...-221f2c5 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPrivateKeyFile = errors.New("no private key err")

Functions

func GetClaimsFromCtx

func GetClaimsFromCtx(ctx context.Context) jwt.MapClaims

func SetClaimsToCtx

func SetClaimsToCtx(ctx context.Context, claims jwt.MapClaims) context.Context

func SetJwtFactory

func SetJwtFactory(jf *JWTFactory)

Types

type Config

type Config struct {
	SingingAlgorithm string `yaml:"singingAlgorithm"`
	Key              string `yaml:"key"`
	PublicKeyFile    string `yaml:"publicKeyFile"`
	PrivateKeyFile   string `yaml:"privateKeyFile"`
	Timeout          string `yaml:"timeout"`
}

type GenerateTokenFunc

type GenerateTokenFunc func(loginFunc LoginFunc) (jwt.Token, error)

type JWTFactory

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

func JwtFactory

func JwtFactory() *JWTFactory

func NewJWTFactory

func NewJWTFactory(config Config, opts ...Option) (JWTFactory, error)

func (JWTFactory) GenerateToken

func (f JWTFactory) GenerateToken(ctx context.Context, form LoginForm) (string, error)

func (JWTFactory) GetClaims

func (f JWTFactory) GetClaims(token string) (jwt.MapClaims, error)

func (*JWTFactory) Init

func (f *JWTFactory) Init() (err error)

func (JWTFactory) RefreshToken

func (f JWTFactory) RefreshToken(token string) (string, error)

func (JWTFactory) VerifyToken

func (f JWTFactory) VerifyToken(token string) bool

type KeyType

type KeyType string
const (
	CtxJWTKey KeyType = "jwt"
)

type LoginForm

type LoginForm struct {
	Username string `json:"username" form:"username" binding:"required"`
	Password string `json:"password" form:"password" binding:"required"`
}

type LoginFunc

type LoginFunc func(ctx context.Context, form LoginForm) (jwt.MapClaims, error)

type Option

type Option func(factory *JWTFactory)

func WithKey

func WithKey(key []byte) Option

func WithLoginFunc

func WithLoginFunc(f LoginFunc) Option

func WithPrivateKeyFile

func WithPrivateKeyFile(key string) Option

func WithPublicKeyFile

func WithPublicKeyFile(key string) Option

func WithTimeout

func WithTimeout(duration time.Duration) Option

Jump to

Keyboard shortcuts

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