jwtToken

package
v0.0.0-...-ac3b76c Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeJWT         = "jwt"
	DefaultDuration = int64(2 * 3600)
)

Variables

This section is empty.

Functions

func RegisterValidFunc

func RegisterValidFunc(authType string, validFunc ValidFunc)

RegisterValidFunc 注册校验函数

Types

type Auth

type Auth struct {
	Foo     string `json:"foo"`
	UID     int64  `json:"uid"`
	RoleID  int64  `json:"role_id"`
	IsAdmin int64  `json:"is_admin"`
	AuthExtend
}

func (*Auth) Encode

func (a *Auth) Encode(sign string) (Token, error)

Encode 将Auth编码成Token

func (*Auth) String

func (a *Auth) String() string

func (*Auth) Valid

func (a *Auth) Valid() error

Valid 校验Auth

type AuthExtend

type AuthExtend jwt.RegisteredClaims

func (AuthExtend) GetAudience

func (c AuthExtend) GetAudience() (jwt.ClaimStrings, error)

GetAudience implements the Claims interface.

func (AuthExtend) GetExpirationTime

func (c AuthExtend) GetExpirationTime() (*jwt.NumericDate, error)

GetExpirationTime implements the Claims interface.

func (AuthExtend) GetIssuedAt

func (c AuthExtend) GetIssuedAt() (*jwt.NumericDate, error)

GetIssuedAt implements the Claims interface.

func (AuthExtend) GetIssuer

func (c AuthExtend) GetIssuer() (string, error)

GetIssuer implements the Claims interface.

func (AuthExtend) GetNotBefore

func (c AuthExtend) GetNotBefore() (*jwt.NumericDate, error)

GetNotBefore implements the Claims interface.

func (AuthExtend) GetSubject

func (c AuthExtend) GetSubject() (string, error)

GetSubject implements the Claims interface.

type Token

type Token string

func GetToken

func GetToken(r *http.Request, cookieName string) Token

GetToken 从请求中获取jwt Token

func (Token) Decode

func (t Token) Decode(sign string, verify bool) *Auth

Decode 将Token解码成Auth结构体, verify为true表示进行,校验失败则返回nil

func (Token) SetCookie

func (t Token) SetCookie(w http.ResponseWriter, cookieName string)

SetCookie 将jwt Token保存到cookie中

func (Token) SetHeader

func (t Token) SetHeader(w http.ResponseWriter)

SetHeader 将jwt Token保存到请求返回的X-Auth头部

func (Token) String

func (t Token) String() string

String jwtToken Token转成字符串

type ValidFunc

type ValidFunc func(c *Auth) error

Jump to

Keyboard shortcuts

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