Reduce account jwt token validity to 30mins

This commit is contained in:
Neeraj Gupta
2024-06-12 14:13:52 +05:30
parent 2e1c5d7684
commit c95260a228
2 changed files with 10 additions and 1 deletions

View File

@@ -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

View File

@@ -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)