jwt

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTokenExpiredTime = 10 * time.Minute
	DefaultTokenSecretKey   = "secret-key"
	DefaultSigningMethod    = "HS256"
)

Define constants

View Source
const (
	UserDataKey = "user_data"
)

Define constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	TokenExpiredTime time.Duration
	TokenSecretKey   string
	SigningMethod    string
}

Auth struct

func (*Auth) GenerateToken

func (a *Auth) GenerateToken(data interface{}) (string, *time.Time)

GenerateToken generate jwt token

func (*Auth) ValidateToken

func (a *Auth) ValidateToken(jwtToken string) (map[string]interface{}, error)

ValidateToken validate jwt token

type IJWTAuth

type IJWTAuth interface {
	GenerateToken(data interface{}) (string, *time.Time)
	ValidateToken(jwtToken string) (map[string]interface{}, error)
}

IJWTAuth interface

func New

func New(opts ...Option) IJWTAuth

New Auth object

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option validation option

func WithExpiredTime

func WithExpiredTime(d time.Duration) Option

WithExpiredTime set TokenExpiredTime

func WithSigningMethod

func WithSigningMethod(method string) Option

WithSigningMethod set SigningMethod

func WithTokenSecretKey

func WithTokenSecretKey(key string) Option

WithTokenSecretKey set TokenSecretKey

Jump to

Keyboard shortcuts

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