ParseWithClaims: getting json error when processing JWT that has multiple values for audience #348
Description
I am using JWT tokens generated by Auth0 and oauth2. The token payload looks like this:
{ "iss": "https://redacted.auth0.com/", "sub": "google-oauth2|redacted", "aud": [ "https://redacted:443/app/v1", "https://redacted.auth0.com/userinfo" ], "iat": 1565196366, "exp": 1565282766, "azp": "redacted", "scope": "openid profile email", "permissions": [ "admin" ] }
Because the audience is multi-valued, I am getting parsing error when trying to read the claims.
My parsing code looks like this:
type CustomClaimType struct { Permissions []string
json:"permissions"Scope string
json:"scope" jwt.StandardClaims }
. . .
// Now parse the token parsedToken, err := jwt.ParseWithClaims(bearerToken, &CustomClaimType{}, auth0ValidationKeyGetter) if err != nil { log.Printf("Got error parsing token: " + err.Error()) return nil, false, err }
When I run this, I get an error:
Got error parsing token: json: cannot unmarshal array into Go struct field CustomClaimType.aud of type string
Activity