Skip to content

ParseWithClaims fails from json.NewDecoder #336

Answered by mfridman
Aner-Git asked this question in Q&A
Discussion options

You must be logged in to vote

Pass the memory address of c, e.g.,

ttoken, err := parser.ParseWithClaims(tokenString, &c <--- here

and then assert Claims to your type (*cc) in this case, e.g.,

v, ok := ttoken.Claims.(*cc)
if ok {
  fmt.Println(v.Foo)
  // value
}

There is an example of custom claims here if it helps:

jwt/http_example_test.go

Lines 101 to 109 in 8aa5d6c

token, err := jwt.ParseWithClaims(tokenString, &CustomClaimsExample{}, func(token *jwt.Token) (interface{}, error) {
// since we only use the one private key to sign the tokens,
// we also only use its public counter part to verify
return verifyKey, nil
})
fatal(err)
claims := token.Claims.(*CustomClaimsEx…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by oxisto
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #333 on August 14, 2023 19:00.