Parsing out custom claims
wz2b opened this issue · comments
I'm a little confused about this API. All I want to do is take an id token and parse out the custom claims, no verification is required because I just got this token by logging in. What I'm parsing is actually an ID token.
Where I'm getting confused is here:
token, err := jwtParser.ParseUnverified(tokenStr, claims)
Why am I passing claims in? I don't have any claims yet, I'm trying to get them out of the token.
What am I missing?
I ended up solving it with some messy casting, with a little guarding to make sure it more or less does the right thing. the goal here is to parse the field "custom:something" from the IdToken, and remember the value:
claims := jwt.MapClaims{}
_, _, err := jwt.NewParser().ParseUnverified(*a.IdToken, claims)
if err == nil {
entry := claims["custom:something"]
strVal, ok := entry.(string)
if ok {
claimValue = strVal
}
}
Solved my own problem, so I closed this ticket. If anybody has any comments feel free. I'll leave the issue here as an example in case somebody else is wondering the same thing.