Error with raw JWT from jwt.io
yageek opened this issue · 1 comments
yageek commented
I created some JWT from https://jwt.io with some scope payload:
{
"scopes": [
"test",
"test2"
]
}
The resulted token value is: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZXMiOlsidGVzdCIsInRlc3QyIl19.03T1Fi7AE6GsJW_wdvB1faqoT69UeEBEj0J5RCjLxD4
Then I wanted to use the Claims()
function to recover the scopes
array from the token.
c := token.Claims()
scopesPayload := c.Get("scopes")
if scopesPayload == nil {
http.Error(rw, "No scopes provided", http.StatusBadRequest)
return
}
userScopes, ok := scopesPayload.([]string)
if !ok {
http.Error(rw, "No valid scopes provided", http.StatusBadRequest)
return
}
The type assertion never work in my case and the ok
value is never true.
yageek commented
My fault. It is a misreading of the documentation from my part.