Documentation ¶
Index ¶
- Variables
- func AddPolicyFromResource(enforcer *casbin.Enforcer, sub string, resources []models.UmsResource)
- func GenerateToken(username string, uId int64) string
- func GenerateTokenExpire() time.Time
- func GenerateTokenFromClaims(claimsMap map[string]any) string
- func GetTokenExpireTime(tokenString string) time.Time
- func GetUsernameAndUserIdFromToken(tokenString string) (string, int64, error)
- func RefreshToken(oldTokenString string) (string, error)
- func TokenIsExpired(tokenString string) bool
- func TokenRefreshJustBeforeExpired(tokenString string, tm time.Duration) bool
- func TokenValid(tokenString string, username string) bool
- type CustomClaims
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 ¶
GenerateToken 根据用户名生成 token
func GenerateTokenFromClaims ¶
GenerateTokenFromClaims 根据自定义声明生成 token
func GetTokenExpireTime ¶
GetTokenExpireTime 获取 token 的过期时间
func GetUsernameAndUserIdFromToken ¶
GetUsernameAndUserIdFromToken 从 token 中获取 username 和 userId
func TokenRefreshJustBeforeExpired ¶
TokenRefreshJustBeforeExpired 判断 token 是否在指定时间内刷新过
func TokenValid ¶
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
Click to show internal directories.
Click to hide internal directories.