Skip to content

Commit c7ee551

Browse files
committed
-feat 修改jwt claim信息
1 parent 76f141f commit c7ee551

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

jwtx/jwt.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ var (
1616

1717
// Claims JWT载荷
1818
type Claims struct {
19-
UID string `json:"uid"`
20-
Username string `json:"username"`
21-
MerchantId string `json:"merchant_id"`
22-
Currency string `json:"currency"`
23-
19+
UID string `json:"uid"`
20+
Username string `json:"username"`
2421
jwt.RegisteredClaims
2522
}
2623

@@ -41,15 +38,13 @@ func NewJWTUtil(secret string, accessExpire, refreshExpire int64) *JWTUtil {
4138
}
4239

4340
// GenerateToken 生成访问令牌
44-
func (j *JWTUtil) GenerateToken(uid, username, merchantId, currency string) (string, int64, error) {
41+
func (j *JWTUtil) GenerateToken(uid, username string) (string, int64, error) {
4542
now := time.Now()
4643
expireAt := now.Add(time.Duration(j.AccessExpire) * time.Second)
4744

4845
claims := Claims{
49-
UID: uid,
50-
Username: username,
51-
MerchantId: merchantId,
52-
Currency: currency,
46+
UID: uid,
47+
Username: username,
5348
RegisteredClaims: jwt.RegisteredClaims{
5449
ExpiresAt: jwt.NewNumericDate(expireAt),
5550
IssuedAt: jwt.NewNumericDate(now),
@@ -72,10 +67,8 @@ func (j *JWTUtil) GenerateRefreshToken(uid string, username, merchantId, currenc
7267
expireAt := now.Add(time.Duration(j.RefreshExpire) * time.Second)
7368

7469
claims := Claims{
75-
UID: uid,
76-
Username: username,
77-
MerchantId: merchantId,
78-
Currency: currency,
70+
UID: uid,
71+
Username: username,
7972
RegisteredClaims: jwt.RegisteredClaims{
8073
ExpiresAt: jwt.NewNumericDate(expireAt),
8174
IssuedAt: jwt.NewNumericDate(now),
@@ -126,5 +119,5 @@ func (j *JWTUtil) RefreshToken(refreshToken string) (string, int64, error) {
126119
}
127120

128121
// 生成新的访问令牌
129-
return j.GenerateToken(claims.UID, claims.Username, claims.MerchantId, claims.Currency)
122+
return j.GenerateToken(claims.UID, claims.Username)
130123
}

0 commit comments

Comments
 (0)