Documentation ¶
Overview ¶
Package jwt is token generation and validation.
Index ¶
- Variables
- func GenerateCustomToken(kv map[string]interface{}) (string, error)
- func GenerateToken(uid string, name ...string) (string, error)
- func Init(opts ...Option)
- func RefreshCustomToken(tokenString string) (string, error)
- func RefreshToken(tokenString string) (string, error)
- type Claims
- type CustomClaims
- type KV
- type Option
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // HS256 Method HS256 = jwt.SigningMethodHS256 // HS384 Method HS384 = jwt.SigningMethodHS384 // HS512 Method HS512 = jwt.SigningMethodHS512 )
View Source
var ErrTokenExpired = jwt.ErrTokenExpired
ErrTokenExpired expired
Functions ¶
func GenerateCustomToken ¶ added in v1.5.4
GenerateCustomToken generate token by custom fields, use CustomClaims
func GenerateToken ¶
GenerateToken generate token by uid and name, use universal Claims
func RefreshCustomToken ¶ added in v1.5.16
RefreshCustomToken refresh custom token
func RefreshToken ¶ added in v1.5.16
RefreshToken refresh token
Types ¶
type Claims ¶ added in v1.5.4
Claims standard claims, include uid, name, and RegisteredClaims
func ParseToken ¶ added in v1.5.4
ParseToken parse token, return universal Claims
type CustomClaims ¶
type CustomClaims struct { Fields KV `json:"fields"` jwt.RegisteredClaims }
CustomClaims custom fields claims
func ParseCustomToken ¶ added in v1.5.4
func ParseCustomToken(tokenString string) (*CustomClaims, error)
ParseCustomToken parse token, return CustomClaims
func (*CustomClaims) Get ¶ added in v1.5.4
func (c *CustomClaims) Get(key string) (val interface{}, isExist bool)
Get custom field value by key, if not found, return false
func (*CustomClaims) GetInt ¶ added in v1.9.3
func (c *CustomClaims) GetInt(key string) (int, bool)
GetInt custom field value by key, if not found, return false
type Option ¶
type Option func(*options)
Option set the jwt options.
func WithSigningMethod ¶
func WithSigningMethod(sm *jwt.SigningMethodHMAC) Option
WithSigningMethod set signing method value
Click to show internal directories.
Click to hide internal directories.