Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsValidAt with CustomClaims ? #134

Closed
NeleOb opened this issue Jan 4, 2023 · 3 comments
Closed

IsValidAt with CustomClaims ? #134

NeleOb opened this issue Jan 4, 2023 · 3 comments
Labels
question Further information is requested

Comments

@NeleOb
Copy link

NeleOb commented Jan 4, 2023

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, &regClaims)
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

@cristaloleg
Copy link
Member

Sorry for the late response, the problem is still actual?

@cristaloleg
Copy link
Member

I think the problem lies in struct definition, can you try this?

type userClaims struct {
	jwt.RegisteredClaims
	Some             string
}

?

@NeleOb
Copy link
Author

NeleOb commented Jan 6, 2023

Changing the userClaims struct to

type userClaims struct {
	jwt.RegisteredClaims
	Some             string
}

worked. Thank you.

@NeleOb NeleOb closed this as completed Jan 6, 2023
@cristaloleg cristaloleg added the question Further information is requested label Jan 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants