token

package
v0.0.0-...-af31a00 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessToken = iota
	RefreshToken
)

token类型

Variables

This section is empty.

Functions

func InitJwtBackend

func InitJwtBackend()

初始化jwt

Types

type JwtBackend

type JwtBackend struct {
	PublicKey *rsa.PublicKey
	// contains filtered or unexported fields
}

jwt

func GetJwtBackend

func GetJwtBackend() *JwtBackend

func (*JwtBackend) DropToken

func (this *JwtBackend) DropToken(tokenStr string) error

丢弃token到redis中

func (*JwtBackend) GenerateToken

func (this *JwtBackend) GenerateToken(userUUID string, tokenType uint8) (string, uint32)

生成token(使用hmac256,token比较短)

func (*JwtBackend) GetRemainingValidity

func (this *JwtBackend) GetRemainingValidity(tokenObj *jwt.Token) int64

token的有效期

func (*JwtBackend) GetUserIdFromToken

func (this *JwtBackend) GetUserIdFromToken(tokenObj interface{}) string

从token中获取user uuid

func (*JwtBackend) GetUserIdFromTokenStr

func (this *JwtBackend) GetUserIdFromTokenStr(tokenStr string) string

从token string获取 userid

func (*JwtBackend) OnLogout

func (this *JwtBackend) OnLogout(req *http.Request, refreshTokenStr string) error

登出时,把未过期的token入库到redis中 accessToken和refreshToken一起失效(安全起见,要失效都要一起失效)

func (*JwtBackend) ParseToken

func (this *JwtBackend) ParseToken(in interface{}) (*jwt.Token, error)

解析jwt(传入string或者*http.Request)

func (*JwtBackend) TokenAuthentication

func (this *JwtBackend) TokenAuthentication(req *http.Request) (error, *jwt.Token)

解析token并认证

Jump to

Keyboard shortcuts

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