Documentation ¶
Index ¶
- func GenerateLoginToken(claims LoginRedisClaims) (string, error)
- func GenerateMfaToken(claims LoginRedisClaims, mfaSecret, appCallback string) (string, error)
- func GenerateToken(claims Claims) (string, error)
- func ParseToken[C Claims](Type, token string, target C) (claims C, valid bool, err error)
- func ParseU2fToken(token, ip string) (bool, error)
- type Claims
- type LoginRedisClaims
- type LoginToken
- type MfaRedisClaims
- type MfaToken
- type TypedClaims
- type U2fToken
- type UserToken
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 GenerateToken ¶
func ParseToken ¶
func ParseU2fToken ¶
Types ¶
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 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"` }
func GenerateUserToken ¶
GenerateUserToken 生成有效期 15 天的后台 Token
Click to show internal directories.
Click to hide internal directories.