优化
This commit is contained in:
+11
-10
@@ -16,23 +16,24 @@ var (
|
||||
)
|
||||
|
||||
type Claims struct {
|
||||
UUID string
|
||||
ID uint
|
||||
Username string
|
||||
NickName string
|
||||
AuthorityID uint `json:"AuthorityId"`
|
||||
BufferTime int64
|
||||
UserType string
|
||||
MustChangePwd bool `json:"mustChangePwd"`
|
||||
UUID string
|
||||
ID uint
|
||||
Username string
|
||||
NickName string
|
||||
AuthorityID uint `json:"AuthorityId"`
|
||||
BufferTime int64
|
||||
UserType string
|
||||
MustChangePwd bool `json:"mustChangePwd"`
|
||||
PasswordVersion int64 `json:"passwordVersion,omitempty"`
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
func Generate(secret, issuer string, expires, buffer time.Duration, userID, authorityID uint, uuid, username, nickname string, mustChange bool) (string, *Claims, error) {
|
||||
func Generate(secret, issuer string, expires, buffer time.Duration, userID, authorityID uint, uuid, username, nickname string, mustChange bool, passwordVersion int64) (string, *Claims, error) {
|
||||
if secret == "" {
|
||||
return "", nil, errors.New("empty JWT signing key")
|
||||
}
|
||||
now := time.Now()
|
||||
claims := &Claims{UUID: uuid, ID: userID, Username: username, NickName: nickname, AuthorityID: authorityID, BufferTime: int64(buffer / time.Second), UserType: "admin", MustChangePwd: mustChange, RegisteredClaims: jwt.RegisteredClaims{Audience: jwt.ClaimStrings{"KRA"}, Issuer: issuer, NotBefore: jwt.NewNumericDate(now.Add(-1000)), ExpiresAt: jwt.NewNumericDate(now.Add(expires))}}
|
||||
claims := &Claims{UUID: uuid, ID: userID, Username: username, NickName: nickname, AuthorityID: authorityID, BufferTime: int64(buffer / time.Second), UserType: "admin", MustChangePwd: mustChange, PasswordVersion: passwordVersion, RegisteredClaims: jwt.RegisteredClaims{Audience: jwt.ClaimStrings{"KRA"}, Issuer: issuer, IssuedAt: jwt.NewNumericDate(now), NotBefore: jwt.NewNumericDate(now.Add(-1000)), ExpiresAt: jwt.NewNumericDate(now.Add(expires))}}
|
||||
token, err := Sign(secret, claims)
|
||||
return token, claims, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user