package jwt import ( "errors" // "log" "github.com/gin-gonic/gin" "github.com/golang-jwt/jwt/v5" ) func (a Authenticator) BindClaims(c *gin.Context, claims *RequestClaims) error { token, err := a.getToken(c) if err != nil { return errors.Join(errors.New("BindClaims: failed to get token: "), err) } keyfunc, err := a.getKeyfunc(c) if err != nil { return errors.Join(errors.New("BindClaims: failed to get key function: "), err) } options, err := a.getParserOptions(c) if err != nil { return errors.Join(errors.New("BindClaims: failed to get parser options: "), err) } mapping := &jwt.MapClaims{} _, err = jwt.ParseWithClaims(token, mapping, keyfunc, options...) if err != nil { return errors.Join(errors.New("BindClaims: failed to ParseWithClaims: "), err) } claims.mapping = mapping return nil } func (a Authenticator) BindClaimsUnverified(c *gin.Context, claims *RequestClaims) error { token, err := a.getToken(c) if err != nil { return errors.Join(errors.New("BindClaims: failed to get token: "), err) } parser := jwt.NewParser() mapping := &jwt.MapClaims{} _, _, err = parser.ParseUnverified(token, mapping) if err != nil { return errors.Join(errors.New("BindClaims: failed to ParseWithClaims: "), err) } claims.mapping = mapping return nil }