dgrijalva / jwt-go

ARCHIVE - Golang implementation of JSON Web Tokens (JWT). This project is now maintained at:
https://github.com/golang-jwt/jwt
MIT License
10.78k stars 994 forks source link

Why `jwt.ParseWithClaims` treat an uint number as float64? #427

Closed donkw closed 4 years ago

donkw commented 4 years ago

claims := jwt.MapClaims{} token, err := jwt.ParseWithClaims(tokenString, claims, func(token *jwt.Token) (interface{}, error) { return j.AccessTokenSigningKey, nil } fmt.Printf("uint number: %+v\n", claims["uintnum"]) // out: 9.6863578e+07

uintNum := claims["uintnum"].(uint) // panic fmt.Printf("uint number: %+v\n", uintNum )

This will panic: interface conversion: interface {} is float64, not uint, but the value of uintnum is an uint number. How could i get uint number from claims ?

donkw commented 4 years ago

https://github.com/dgrijalva/jwt-go/blob/master/example_test.go#L56 This will help.