I am referring to this post (How to decode a JWT token in Go?) to get the claim fields of a Jwt token. Here are the code that I used based on this post:
tokenString := "<YOUR TOKEN STRING>"
claims := jwt.MapClaims{}
token, err := jwt.ParseWithClaims(tokenString, claims, func(token *jwt.Token) (interface{}, error) {
return []byte("<YOUR VERIFICATION KEY>"), nil
})
// ... error handling
// do something with decoded claims
for key, val := range claims {
fmt.Printf("Key: %v, value: %v\n", key, val)
}
I managed to get those claims and its values. However, in this Jwt token, there is a claim field called 'scope', and it has a string array values, like '['openId','username','email'].
Now I want to iterate over these values using loop.
for _, v := range claims["scope"]{
fmt.Println(v)
}
However, when I try to loop over this claims ["scope"], I got an error message saying that:
"cannot range over claims["scope"] (type interface {})".
How to iterate over these claims["scope"] values? Also, is it possible to convert it to other forms, like string array or json, to iterate over it?
Thanks.