I am using Golang and the Gin framework to get claims from a JWT sent from a client. But I can't compare the extracted roles with a string.
When I try to get the value, it returns [test-app]
but actually I want the value as "test-app"
token, _, err := new(jwt.Parser).ParseUnverified(tokenString, jwt.MapClaims{})
if err != nil {
fmt.Println(err2)
return
}
if claims, ok := token.Claims.(jwt.MapClaims); ok {
chkRoles := claims["roles"]
if chkRoles == "test-app" {
fmt.Println("Check Roles passed")
}
}
and My Payload
{
"roles": [
"test-app"
],
"exp": 1811749673,
"client_id": "testapp"
}
How can I get the value from json claims and use it to compare/validate with a string?