chore: init bj_power monorepo (dashboard/mes/wms/wms_client/workstation), clear subproject git metadata and align naming to folder names
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package token
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const RefreshTokenKeyPrefix = "token:refresh:"
|
||||
|
||||
func GenToken(secretKey string, iat int64, expireSeconds int64, payloads map[string]any) (string, error) {
|
||||
claims := make(jwt.MapClaims)
|
||||
claims["exp"] = iat + expireSeconds
|
||||
claims["iat"] = iat
|
||||
for k, v := range payloads {
|
||||
claims[k] = v
|
||||
}
|
||||
|
||||
token := jwt.New(jwt.SigningMethodHS256)
|
||||
token.Claims = claims
|
||||
|
||||
return token.SignedString([]byte(secretKey))
|
||||
}
|
||||
|
||||
func GenRefreshToken() string {
|
||||
return base64.StdEncoding.EncodeToString([]byte(uuid.New().String()))
|
||||
}
|
||||
|
||||
func GenRefreshTokenCacheKey(userId int64) string {
|
||||
return fmt.Sprintf("%s%d", RefreshTokenKeyPrefix, userId)
|
||||
}
|
||||
Reference in New Issue
Block a user