this morning.
This here is my token creation:
func CreateToken(id int) (string, error) {
claims := jwt.MapClaims{}
claims["authorized"] = true
claims["id"] = id
...
But then while trying to read the claims with:
_, claims, _ := jwtauth.FromContext(r.Context())
id := claims["id"].(string) or id := claims["id"].(int64)
I can't cast it to string, int or something else because it says it's a float. Why float? I never had this problem because I was only working with floats in jwt till now, but what's wrong here?
What's the underlying type of MapClaims?
seems like you’re working with JSON 🙂 there are no ints in JSON, only IEEE 754 floating point numbers (float64) btw, try to reproduce your problem on play.golang.org so people can see what you’re doing exactly
Yep, that’s probably the problem. Seems like jwt-go is directly working with floats
Обсуждают сегодня