jwt
jwt copied to clipboard
It seems that the default Claims may lose the type when the number is too large
I use jwt.MapClaims to store the kv ("e", time.Now().Unix() + (a int64 value) ),and when I deserialize it to jwt.MapClaims , use m["e"].(int64), it panics and says that interface conversion: interface {} is float64, not int64.
I have the same problem - if you log the value, it is logged as float64 for some reason. why does it try to parse as float?
This is sort of a duplicate of #230. The problem is that a JWT is a JSON and JSON does not have integer values. In fact all JSON numbers are float values. You can try to work around with jwt.Parse(..., jwt.WithJSONNumber()) and then access it as json.Number. However, this will still have limitations for large numbers.
A better alternative, especially for time and date values is the jwt.RegisteredClaims which has a built-in type for time values.
Thanks for the response @oxisto Yeah I figured that Registered Claims are better suited for this use case, so will go with them.