I am setting the the expiration of JWT token claims using
claims["exp"] = time.Now().Add(time.Hour * time.Duration(settings.Get().JWTExpiration)).Unix()
where settings.Get().JWTExpiration gives me the settings I have made in my application settings file.
I have written a function which should ideally give me the remaining time the token is valid for.
func getTokenRemainingValidity(timestamp interface{}) int {
if validity, ok := timestamp.(float64); ok {
tm := time.Unix(int64(validity), 0)
remainder := tm.Sub(time.Now())
if remainder > 0 {
return int(remainder.Seconds() + expireOffset)
}
}
return expireOffset
}
and I invoke this function like:
x := getTokenRemainingValidity(claims["exp"])
fmt.Println(x)
where claims["exp"] is the claims I have got after parsing a jwt token.
But this always gives me same output. i.e. 3600
. How can I check for the remaining validity of my token. I am using golang.