jwt

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenExpiredDuration = time.Hour * 24
)

根据使用情况调整 jwt 过期时间

Variables

This section is empty.

Functions

func GenToken

func GenToken(u *model.User) string

GenToken 生成 jwt(json web token)

func GenerateToken

func GenerateToken(username string) string

GenerateTokne 用户登录成功后,根据 username 查询到用户后生成一个 token

func ParseToken

func ParseToken(tokenString string) (*jwt.RegisteredClaims, error)

ParseToken 负责解析客户端 Header 中包含的 jwt,解析成功返回用户的 Claims(包含了用户的信息)

func RequireAuth

func RequireAuth() gin.HandlerFunc

RequireAuth 鉴权中间件 如果用户携带的 token 验证通过,将 user_id 存入上下文中然后执行下一个 Handler

func RequireAuthCookie

func RequireAuthCookie(c *gin.Context)

RequireAuthCookie ,使用 cookie 持久化。 本实现暂时用不到,需要网页端时直接修改为这种持久化存储实现即可

func RequireAuthWithoutLogin

func RequireAuthWithoutLogin() gin.HandlerFunc

RequireAuthWithoutLogin 用户在未登录情况如果携带了 token 验证 token 有效性,如果有效,解析出用户 id 存入上下文,否则存入默认值 0

Types

This section is empty.

Jump to

Keyboard shortcuts

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