jwt

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

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

Auth struct

func NewJWTAuth

func NewJWTAuth(opts ...Option) *Auth

NewJWTAuth return new Auth pointer

func (*Auth) GenerateToken

func (a *Auth) GenerateToken(userID string) (TokenInfo, error)

GenerateToken return new TokenInfo, generate new access and refresh token

func (*Auth) ParseUserID

func (a *Auth) ParseUserID(tokenString string, refresh bool) (string, error)

ParseUserID parse user_id from token

func (*Auth) RefreshToken

func (a *Auth) RefreshToken(refreshToken string) (TokenInfo, error)

RefreshToken refresh token, return new TokenInfo

type IJWTAuth

type IJWTAuth interface {
	GenerateToken(userID string) (TokenInfo, error)
	RefreshToken(refreshToken string) (TokenInfo, error)
	ParseUserID(accessToken string, refresh bool) (string, error)
}

IJWTAuth interface

type Option

type Option func(*options)

Option jwt option

func WithExpired

func WithExpired(expired int) Option

WithExpired set expired time

func WithExpiredRefresh

func WithExpiredRefresh(expired int) Option

WithExpiredRefresh set expired for refresh token

func WithKeyFunc

func WithKeyFunc(keyFunc jwt.Keyfunc) Option

WithKeyFunc set key function

func WithKeyFuncRefresh

func WithKeyFuncRefresh(keyFunc jwt.Keyfunc) Option

WithKeyFuncRefresh set key function for refresh token

func WithSigningKey

func WithSigningKey(key interface{}) Option

WithSigningKey set signing key

func WithSigningKeyRefresh

func WithSigningKeyRefresh(key interface{}) Option

WithSigningKeyRefresh set signing key for refresh token

type TokenInfo

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

TokenInfo interface

Jump to

Keyboard shortcuts

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