This commit is contained in:
@@ -23,7 +23,7 @@ func VerifyToken(authorization string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func NewToken(auds ...string) (string, error) {
|
||||
func NewToken(expire time.Duration, auds ...string) (string, error) {
|
||||
if len(auds) == 0 {
|
||||
auds = []string{"non-audience"}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func NewToken(auds ...string) (string, error) {
|
||||
"bar",
|
||||
jwt.RegisteredClaims{
|
||||
// A usual scenario is to set the expiration time relative to the current time
|
||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Duration(config.Cfg.Security.Jwt.Expire) * time.Second)),
|
||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(expire)),
|
||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||
NotBefore: jwt.NewNumericDate(time.Now()),
|
||||
Issuer: "drivelinked",
|
||||
@@ -48,3 +48,11 @@ func NewToken(auds ...string) (string, error) {
|
||||
}
|
||||
return ss, nil
|
||||
}
|
||||
|
||||
func NewShortToken(auds ...string) (string, error) {
|
||||
return NewToken(time.Duration(config.Cfg.Security.Jwt.Expire) * time.Second)
|
||||
}
|
||||
|
||||
func NewRefreshToken(auds ...string) (string, error) {
|
||||
return NewToken(24 * time.Hour)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user