Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Token has invalid claims: token is expired #372

Answered by oxisto
maheshkumar2150 asked this question in Q&A
Discussion options

How do i exactly look for the error?

What does it mean that token has invalid claims?

If the token has just expired, i would like to issue a new token. But it has invalid key or anything else, i cant issue a new token.

How do i check for errors?
Please give me an example

Thanks..

You must be logged in to vote

I am not 100 % sure, if I understand your problem correctly, but if you are looking for a way to differentiate between different error messages coming from the parser, you can have a look at our examples:

jwt/example_test.go

Lines 164 to 189 in 4d0edcd

// An example of parsing the error types using errors.Is.
func ExampleParse_errorChecking() {
// Token from another example. This token is expired
var tokenString = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJleHAiOjE1MDAwLCJpc3MiOiJ0ZXN0In0.HE7fK0xOQwFEr4WDgRWj4teRPZ6i3GLwD5YCm6Pwu_c"
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
return []byte("AllY...

Replies: 1 comment 2 replies

Comment options

I am not 100 % sure, if I understand your problem correctly, but if you are looking for a way to differentiate between different error messages coming from the parser, you can have a look at our examples:

jwt/example_test.go

Lines 164 to 189 in 4d0edcd

// An example of parsing the error types using errors.Is.
func ExampleParse_errorChecking() {
// Token from another example. This token is expired
var tokenString = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJleHAiOjE1MDAwLCJpc3MiOiJ0ZXN0In0.HE7fK0xOQwFEr4WDgRWj4teRPZ6i3GLwD5YCm6Pwu_c"
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
return []byte("AllYourBase"), nil
})
switch {
case token.Valid:
fmt.Println("You look nice today")
case errors.Is(err, jwt.ErrTokenMalformed):
fmt.Println("That's not even a token")
case errors.Is(err, jwt.ErrTokenSignatureInvalid):
// Invalid signature
fmt.Println("Invalid signature")
case errors.Is(err, jwt.ErrTokenExpired) || errors.Is(err, jwt.ErrTokenNotValidYet):
// Token is either expired or not active yet
fmt.Println("Timing is everything")
default:
fmt.Println("Couldn't handle this token:", err)
}
// Output: Timing is everything
}

Basically, you can use errors.Is to check for the different error types.

You must be logged in to vote
2 replies
Comment options

This is what i want exactly..

From where can i find this example??

Thanks a lot for helping..

Comment options

Answer selected by oxisto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /