auth0 / go-jwt-middleware

A Middleware for Go Programming Language to check for JWTs on HTTP requests
MIT License
1.07k stars 205 forks source link

newVerifier() function - verificationKey type #255

Open juan-rojas-soteria opened 6 months ago

juan-rojas-soteria commented 6 months ago

Checklist

Description

After updating the library from version github.com/auth0/go-jwt-middleware/v2 v2.1.0 to github.com/auth0/go-jwt-middleware/v2@v2.2.1, an error was detected in the validation of a JWT that worked correctly in version v2.1.0. Specifically, the function func newVerifier(verificationKey interface{}) (payloadVerifier, error) has problems in the switch case fragment where it compares the encryption algorithm. I compared the type of interface that you get in the two versions of the library and they are different. I attach images for reference. Version v2.2.1 does not have the same type as version v2.1.0, therefore the process is not able to determine the algorithm and breaks

v2.1.0:

v2 1 0

v2.2.1:

v2 2 1 .

Reproduction

  1. Given a JWT generated using /oauth/token with a RS256 signature algorithm
  2. When consuming a REST endpoint created using golang (v1.20 and v.1.22) and gin
  3. Then I get in the response: Encountered error while validating JWT: jwt invalid: failed to deserialize token claims: could not get token claims: go-jose/go-jose: unsupported key type/format

Go JWT Middleware version

github.com/auth0/go-jwt-middleware/v2@v2.2.1

Go version

1.20 / 1.22