|
|
@ -4,7 +4,7 @@ import (
|
|
|
|
"Open_IM/src/common/config"
|
|
|
|
"Open_IM/src/common/config"
|
|
|
|
"Open_IM/src/common/db"
|
|
|
|
"Open_IM/src/common/db"
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"github.com/dgrijalva/jwt-go"
|
|
|
|
"github.com/golang-jwt/jwt/v4"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -22,7 +22,7 @@ type Claims struct {
|
|
|
|
jwt.StandardClaims
|
|
|
|
jwt.StandardClaims
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func BuildClaims(uid, accountAddr, platform string, ttl int64) Claims {
|
|
|
|
func BuildClaims(uid, platform string, ttl int64) Claims {
|
|
|
|
now := time.Now().Unix()
|
|
|
|
now := time.Now().Unix()
|
|
|
|
//if ttl=-1 Permanent token
|
|
|
|
//if ttl=-1 Permanent token
|
|
|
|
if ttl == -1 {
|
|
|
|
if ttl == -1 {
|
|
|
@ -45,8 +45,8 @@ func BuildClaims(uid, accountAddr, platform string, ttl int64) Claims {
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func CreateToken(userID, accountAddr string, platform int32) (string, int64, error) {
|
|
|
|
func CreateToken(userID string, platform int32) (string, int64, error) {
|
|
|
|
claims := BuildClaims(userID, accountAddr, PlatformIDToName(platform), config.Config.TokenPolicy.AccessExpire)
|
|
|
|
claims := BuildClaims(userID, PlatformIDToName(platform), config.Config.TokenPolicy.AccessExpire)
|
|
|
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
|
|
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
|
|
|
tokenString, err := token.SignedString([]byte(config.Config.TokenPolicy.AccessSecret))
|
|
|
|
tokenString, err := token.SignedString([]byte(config.Config.TokenPolicy.AccessSecret))
|
|
|
|
|
|
|
|
|
|
|
|