|
@@ -1,9 +1,8 @@
|
|
|
package token
|
|
|
|
|
|
import (
|
|
|
+ "github.com/golang-jwt/jwt/v4"
|
|
|
"time"
|
|
|
-
|
|
|
- "github.com/dgrijalva/jwt-go"
|
|
|
)
|
|
|
|
|
|
func (t *token) JwtSign(userId uint64, platform string, expireDuration time.Duration) (tokenString string, err error) {
|
|
@@ -18,10 +17,13 @@ func (t *token) JwtSign(userId uint64, platform string, expireDuration time.Dura
|
|
|
c := claims{
|
|
|
userId,
|
|
|
platform,
|
|
|
- jwt.StandardClaims{
|
|
|
- NotBefore: time.Now().Unix(),
|
|
|
- IssuedAt: time.Now().Unix(),
|
|
|
- ExpiresAt: time.Now().Add(expireDuration).Unix(),
|
|
|
+ jwt.RegisteredClaims{
|
|
|
+ Issuer: "BvBeJ",
|
|
|
+ Subject: "JSON Web Token",
|
|
|
+ Audience: jwt.ClaimStrings(t.domain),
|
|
|
+ ExpiresAt: jwt.NewNumericDate(time.Now().Add(expireDuration)),
|
|
|
+ NotBefore: jwt.NewNumericDate(time.Now()),
|
|
|
+ IssuedAt: jwt.NewNumericDate(time.Now()),
|
|
|
},
|
|
|
}
|
|
|
tokenString, err = jwt.NewWithClaims(jwt.SigningMethodHS256, c).SignedString([]byte(t.secret))
|