jwt
jwt copied to clipboard
Parsing token and getting payload
Parsing token and getting payload
Is there any way to extract claims from token like in this package (any example appreciated)?
In order to parse the token you'll need to verify it:
import "github.com/gbrlsnchs/jwt/v3"
type CustomPayload struct {
jwt.Payload
Foo string `json:"foo,omitempty"`
Bar int `json:"bar,omitempty"`
}
var hs = jwt.NewHS256([]byte("secret"))
func main() {
// ...
var pl CustomPayload
hd, err := jwt.Verify(token, hs, &pl)
if err != nil {
// ...
}
// ...
}
This was done on purpose in order to avoid security flaws where users use data from tokens that weren't validated.
Let me know if this info is enough for you so I can close this issue. :smiley: