Documentation ¶
Index ¶
- Constants
- func GenerateAccessToken(uid uint, appCode, payload string) (string, error)
- func GenerateLoginToken(claims LoginRedisClaims) (string, error)
- func GenerateMfaToken(claims LoginRedisClaims, mfaSecret, appCallback string) (string, error)
- func GenerateRefreshToken(uid uint, appCode, payload string, valid time.Duration) (string, error)
- func GenerateToken(claims Claims) (string, error)
- func HeaderToken(c *gin.Context, Type string) (string, error)
- func ParseToken[C Claims](Type, token string, target C) (claims C, valid bool, err error)
- func ParseU2fToken(token, ip string) (bool, error)
- func TokenWithType(Type, token string) string
- type AccessToken
- type Claims
- type LoginRedisClaims
- type LoginToken
- type MfaRedisClaims
- type MfaToken
- type RefreshToken
- type TypedClaims
- type U2fToken
- type UserToken
Constants ¶
View Source
const ( User = "User" Login = "Login" Mfa = "Mfa" U2F = "U2F" Refresh = "Refresh" Access = "Access" )
Variables ¶
This section is empty.
Functions ¶
func GenerateAccessToken ¶ added in v1.17.2
func GenerateLoginToken ¶
func GenerateLoginToken(claims LoginRedisClaims) (string, error)
GenerateLoginToken 生成有效期 5 分钟的登录校验 Token
func GenerateMfaToken ¶
func GenerateMfaToken(claims LoginRedisClaims, mfaSecret, appCallback string) (string, error)
GenerateMfaToken 生成绑定 TOTP MFA 中间身份令牌,五分钟有效
func GenerateRefreshToken ¶ added in v1.17.2
func GenerateToken ¶
func ParseToken ¶
func ParseU2fToken ¶
func TokenWithType ¶ added in v1.17.3
Types ¶
type AccessToken ¶ added in v1.17.2
type AccessToken struct {
RefreshToken
}
func ParseAccessToken ¶ added in v1.17.2
func ParseAccessToken(token string) (*AccessToken, bool, error)
type LoginRedisClaims ¶
type LoginRedisClaims struct { UID uint `json:"uid"` AvatarUrl string `json:"avatarUrl"` Name string `json:"name"` IP string `json:"ip"` Groups []string `json:"groups"` AppID uint `json:"appID"` }
func ParseLoginToken ¶
func ParseLoginToken(token string) (*LoginRedisClaims, bool, error)
ParseLoginToken 解析后自动销毁
type LoginToken ¶
type LoginToken struct { TypedClaims // 无意义 ID ID uint64 `json:"id"` }
type MfaRedisClaims ¶
type MfaRedisClaims struct { LoginRedisClaims Mfa string `json:"mfa"` AppCallback string `json:"appCallback"` }
func ParseMfaToken ¶
func ParseMfaToken(token string) (*MfaRedisClaims, error)
ParseMfaToken 不会销毁,允许多次验证尝试
type MfaToken ¶
type MfaToken struct { TypedClaims // 无意义 ID ID uint64 `json:"id"` UID uint `json:"uid"` }
type RefreshToken ¶ added in v1.17.2
type RefreshToken struct { TypedClaims UID uint `json:"uid"` AppCode string `json:"appCode"` Payload string `json:"payload,omitempty"` }
func ParseRefreshToken ¶ added in v1.17.2
func ParseRefreshToken(token string) (*RefreshToken, bool, error)
type TypedClaims ¶
type TypedClaims struct { jwt.RegisteredClaims Type string `json:"type"` }
TypedClaims type 字段用于区分不同类型的 token,防止类型窜用导致的安全漏洞
func NewTypedClaims ¶
func NewTypedClaims(Type string, valid time.Duration) TypedClaims
func (*TypedClaims) GetType ¶
func (a *TypedClaims) GetType() string
type U2fToken ¶
type U2fToken struct { TypedClaims // 无意义 ID ID uint64 `json:"id"` UID uint `json:"uid"` IP string `json:"ip"` }
type UserToken ¶
type UserToken struct { TypedClaims // dao.User.ID ID uint `json:"id"` Name string `json:"name"` Groups []string `json:"groups,omitempty"` }
Click to show internal directories.
Click to hide internal directories.