changed token
This commit is contained in:
1 parent
0c5b23b790
commit
9884712392
6 files changed
+58
-23
No files matched your search
@@ -0,0 +1,26 @@
|
||||
package token
|
||||
|
||||
import (
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/integration-system/isp-lib/config"
|
||||
"msp-admin-service/conf"
|
||||
"time"
|
||||
)
|
||||
|
||||
type customClaims struct {
|
||||
id string
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
func GetToken(id string) (string, string) {
|
||||
expired := ""
|
||||
claims := customClaims{id: id}
|
||||
cfg := config.GetRemote().(*conf.RemoteConfig)
|
||||
if cfg.ExpirySec != 0 {
|
||||
exp := time.Now().Add(time.Second * time.Duration(cfg.ExpirySec))
|
||||
expired = exp.String()
|
||||
claims.ExpiresAt = exp.Unix()
|
||||
}
|
||||
tokenString, _ := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString([]byte(cfg.SecretKey))
|
||||
return tokenString, expired
|
||||
}
|
||||
Reference in new issue
Block a user