ref
This commit is contained in:
1 parent
dc5ca4b1c6
commit
24dc1fe615
5 files changed
+63
-62
No files matched your search
+10
-7
@@ -8,19 +8,22 @@ import (
|
||||
)
|
||||
|
||||
type customClaims struct {
|
||||
id string
|
||||
Id string
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
func GetToken(id string) (string, string) {
|
||||
func GetToken(id string) (string, string, error) {
|
||||
expired := ""
|
||||
claims := customClaims{id: id}
|
||||
claims := customClaims{Id: id}
|
||||
cfg := config.GetRemote().(*conf.RemoteConfig)
|
||||
if cfg.ExpirySec != 0 {
|
||||
exp := time.Now().Add(time.Second * time.Duration(cfg.ExpirySec))
|
||||
if cfg.ExpireSec != 0 {
|
||||
exp := time.Now().Add(time.Second * time.Duration(cfg.ExpireSec))
|
||||
expired = exp.String()
|
||||
claims.ExpiresAt = exp.Unix()
|
||||
}
|
||||
tokenString, _ := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString([]byte(cfg.SecretKey))
|
||||
return tokenString, expired
|
||||
tokenString, err := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString([]byte(cfg.SecretKey))
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
return tokenString, expired, nil
|
||||
}
|
||||
Reference in new issue
Block a user