feat: self-connection blocking API support (token-device internal endpoint, jti)
This commit is contained in:
1 parent
37b9991d0e
commit
9e34bdce9e
6 files changed
+73
-1
No files matched your search
@@ -3,6 +3,7 @@ package jwt
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/google/uuid"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -33,6 +34,9 @@ func (s *Jwt) GenerateToken(userId uint) string {
|
||||
UserId: userId,
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(s.TokenExpireDuration)),
|
||||
// 每次登录生成唯一 jti,避免同一账号同秒多次登录产生相同 token,
|
||||
// 导致 UserToken 表中 token 无法区分设备
|
||||
ID: uuid.NewString(),
|
||||
},
|
||||
})
|
||||
token, err := t.SignedString(s.Key)
|
||||
|
||||
Reference in new issue
Block a user