auth

package
v0.0.0-...-3b54ddd Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2019 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	FormatError = 1 + iota
	SignatureError
	PayloadError
	ExpiredError
)

errCode 1:格式不正确 2:签名错误 3:payload错误 4:过期

Variables

This section is empty.

Functions

func CreateKey

func CreateKey(uid int, types string) (cacheKey string)

生成一个key

func CreateToken

func CreateToken(uid int, types string) (token string, value string)

生成一个token

func ErrcodeString

func ErrcodeString(code int) string

func GetKeyByToken

func GetKeyByToken(token, types string) (cacheKey string, err error)

验证时通过token获得缓存key

func JWTEncode

func JWTEncode(secret, iss string, exp int64, typ string, sub string, aud string) (out string)

加密数据 iss: 该JWT的签发者 ,exp(expires): 什么时候过期,这里是一个Unix时间戳 ,typ:用户类型(组),如admin/user ,sub: 该JWT所面向的用户 ,aud: 接收该JWT的一方

func VerifyToken

func VerifyToken(cacheToken string, userToken string) (uid int, err error)

验证缓存Token与用户Token是否匹配

Types

type JWTData

type JWTData struct {
	Iss string
	Iat int64 // iat(issued at): 在什么时候签发的
	Exp int64
	Sub string
	Aud string
	Typ string
}

func JWTDecode

func JWTDecode(secret, in string) (jwtData JWTData, errCode int)

func (JWTData) IsEmpty

func (j JWTData) IsEmpty() bool

Jump to

Keyboard shortcuts

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