token

package
v0.0.0-...-6e5bb36 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	Payload
	jwt.StandardClaims
}

Claims define custom jwt claims

type IToken

type IToken interface {
	GetImplicitToken(payload Payload) (tokenStr string, expiresAt int64, err error)
	GetNewToken(payload Payload, refreshToken string) (tokenStr string, expiresAt int64, err error)
	GetRefreshToken(payload Payload) (tokenStr string, expiresAt int64, err error)
	IsTokenValid(tokenString string) (valid bool, err error)
	GetClaims(tokenString string) (claims jwt.MapClaims, err error)
}

func New

func New(opts ...Options) IToken

Init initialized token

type Options

type Options func(*Token)

Options define functional options for token

func WithAccessTokenTTL

func WithAccessTokenTTL(ttl uint64) Options

WithAccessTokenTTL assign access token ttl

func WithIssuer

func WithIssuer(issue string) Options

WithIssuer assign issuer

func WithRefreshTokenTTL

func WithRefreshTokenTTL(ttl uint64) Options

WithRefreshTokenTTL assign refresh token ttl

func WithSecretKey

func WithSecretKey(secretKey string) Options

WithSecretKey assign secret key to token

type Payload

type Payload struct {
	UserID uuid.UUID
}

Payload define payload body for token

type Token

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

Token define struct for token

func (*Token) GetClaims

func (t *Token) GetClaims(tokenString string) (claims jwt.MapClaims, err error)

GetClaims get token claims

func (*Token) GetImplicitToken

func (t *Token) GetImplicitToken(payload Payload) (tokenStr string, expiresAt int64, err error)

GetImplicitToken generate new access token for implicit grant

func (*Token) GetNewToken

func (t *Token) GetNewToken(payload Payload, refreshToken string) (tokenStr string, expiresAt int64, err error)

GetNewToken generate new access token

func (*Token) GetRefreshToken

func (t *Token) GetRefreshToken(payload Payload) (tokenStr string, expiresAt int64, err error)

GetRefreshToken generate new refresh token

func (*Token) IsTokenValid

func (t *Token) IsTokenValid(tokenString string) (valid bool, err error)

IsTokenValid check whether token still valid

Jump to

Keyboard shortcuts

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