security

package
v0.0.0-...-08c5772 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Enforcer *casbin.Enforcer
)

Functions

func AddPolicyFromResource

func AddPolicyFromResource(enforcer *casbin.Enforcer, sub string, resources []models.UmsResource)

AddPolicyFromResource 将基于每个不同的用户资源添加到 casbin 中

func GenerateToken

func GenerateToken(username string, uId int64) string

GenerateToken 根据用户名生成 token

func GenerateTokenExpire

func GenerateTokenExpire() time.Time

GenerateTokenExpire 生成 token 的过期时间

func GenerateTokenFromClaims

func GenerateTokenFromClaims(claimsMap map[string]any) string

GenerateTokenFromClaims 根据自定义声明生成 token

func GetTokenExpireTime

func GetTokenExpireTime(tokenString string) time.Time

GetTokenExpireTime 获取 token 的过期时间

func GetUsernameAndUserIdFromToken

func GetUsernameAndUserIdFromToken(tokenString string) (string, int64, error)

GetUsernameAndUserIdFromToken 从 token 中获取 username 和 userId

func RefreshToken

func RefreshToken(oldTokenString string) (string, error)

RefreshToken 刷新 token

func TokenIsExpired

func TokenIsExpired(tokenString string) bool

TokenIsExpired 判断 token 是否过期

func TokenRefreshJustBeforeExpired

func TokenRefreshJustBeforeExpired(tokenString string, tm time.Duration) bool

TokenRefreshJustBeforeExpired 判断 token 是否在指定时间内刷新过

func TokenValid

func TokenValid(tokenString string, username string) bool

TokenValid 判断 token 是否有效

Types

type CustomClaims

type CustomClaims struct {
	Sub     string    `json:"sub"`
	UserId  int64     `json:"userId"`
	Created time.Time `json:"created"`
	jwt.RegisteredClaims
}

CustomClaims 自定义声明

func GetClaimsFromToken

func GetClaimsFromToken(tokenString string) (CustomClaims, error)

GetClaimsFromToken 从 token 中获取 claims

Jump to

Keyboard shortcuts

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