IsValidAt with CustomClaims ?
NeleOb opened this issue · 3 comments
I created a CustomClaim:
type userClaims struct {
RegisteredClaims jwt.RegisteredClaims
Some string
}
with:
claims := &userClaims{
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time_exp),
NotBefore: jwt.NewNumericDate(time_nbf),
},
Some: some_value,
}
where time_exp and time_nbf are time.Time and some_value is a string.
I get the registered Claims doing this:
var regClaims jwt.RegisteredClaims
errParseClaims := jwt.ParseClaims(tokenBytes, verifier, ®Claims)
is_valid := regClaims.IsValidAt(time.Now())
I can build and parse the token.
I want to check the exp and nbf using "IsValidAt(time.Now())".
But it is always true.
When I tried "IsValidAt(time.Now())" with the regular claims it worked.
example.:
token.String():
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. eyJSZWdpc3RlcmVkQ2xhaW1zIjp7ImV4cCI6MjAwMDAwMDAwMCwibmJmIjoxNjcyODQzNzYwfSwiU29tZSI6IiJ9. 0piI7l7NlmrmGuEm5tjMvIQTpFDZTsXkwO78HG8AC8E
string(token.Claims):
{"RegisteredClaims":{"exp":2000000000,"nbf":1000000000},"Some":""}
is_valid: true
Sorry for the late response, the problem is still actual?
I think the problem lies in struct definition, can you try this?
type userClaims struct {
jwt.RegisteredClaims
Some string
}
?
Changing the userClaims struct to
type userClaims struct {
jwt.RegisteredClaims
Some string
}
worked. Thank you.