Reduce account jwt token validity to 30mins
This commit is contained in:
@@ -13,11 +13,15 @@ import (
|
||||
const ValidForDays = 1
|
||||
|
||||
func (c *UserController) GetJWTToken(userID int64, scope enteJWT.ClaimScope) (string, error) {
|
||||
tokenExpirty := time.NDaysFromNow(1)
|
||||
if scope == enteJWT.ACCOUNTS {
|
||||
tokenExpirty = time.NMinFromNow(30)
|
||||
}
|
||||
// Create a new token object, specifying signing method and the claims
|
||||
// you would like it to contain.
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, &enteJWT.WebCommonJWTClaim{
|
||||
UserID: userID,
|
||||
ExpiryTime: time.NDaysFromNow(1),
|
||||
ExpiryTime: tokenExpirty,
|
||||
ClaimScope: &scope,
|
||||
})
|
||||
// Sign and get the complete encoded token as a string using the secret
|
||||
|
||||
@@ -48,6 +48,11 @@ func NDaysFromNow(n int) int64 {
|
||||
return time.Now().AddDate(0, 0, n).UnixNano() / 1000
|
||||
}
|
||||
|
||||
// NMinFromNow returns the time n min from now in micro seconds
|
||||
func NMinFromNow(n int64) int64 {
|
||||
return time.Now().Add(time.Minute*time.Duration(n)).UnixNano() / 1000
|
||||
}
|
||||
|
||||
// MicrosecondsBeforeMinutes returns the unix time n minutes before now in micro seconds
|
||||
func MicrosecondsBeforeMinutes(noOfMinutes int64) int64 {
|
||||
return Microseconds() - (MicroSecondsInOneMinute * noOfMinutes)
|
||||
|
||||
Reference in New Issue
Block a user