Documentation ¶
Index ¶
- Constants
- func InitJwtBackend()
- type JwtBackend
- func (this *JwtBackend) DropToken(tokenStr string) error
- func (this *JwtBackend) GenerateToken(userUUID string, tokenType uint8) (string, uint32)
- func (this *JwtBackend) GetRemainingValidity(tokenObj *jwt.Token) int64
- func (this *JwtBackend) GetUserIdFromToken(tokenObj interface{}) string
- func (this *JwtBackend) GetUserIdFromTokenStr(tokenStr string) string
- func (this *JwtBackend) OnLogout(req *http.Request, refreshTokenStr string) error
- func (this *JwtBackend) ParseToken(in interface{}) (*jwt.Token, error)
- func (this *JwtBackend) TokenAuthentication(req *http.Request) (error, *jwt.Token)
Constants ¶
View Source
const ( AccessToken = iota RefreshToken )
token类型
Variables ¶
This section is empty.
Functions ¶
Types ¶
type JwtBackend ¶
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并认证
Click to show internal directories.
Click to hide internal directories.