Zaubrik / djwt

Create and verify JSON Web Tokens (JWT) with Deno or the browser.
MIT License
225 stars 23 forks source link

TypeError: Unsupported key format when using RS256 #47

Closed Arunscape closed 3 years ago

Arunscape commented 3 years ago

Hello,

I'm getting the following error when I attempt to verify an access token from auth0:

From what I can tell, RS256 keys are implemented in this library, but there may be something upstream going wrong with god_crypto?

TypeError: Unsupported key format
    at detect_format (https://deno.land/x/god_crypto@v1.4.9/src/rsa/import_key.ts:25:9)
    at rsa_import_key (https://deno.land/x/god_crypto@v1.4.9/src/rsa/import_key.ts:177:43)
    at Function.importKey (https://deno.land/x/god_crypto@v1.4.9/src/rsa/mod.ts:102:23)
    at Function.parseKey (https://deno.land/x/god_crypto@v1.4.9/src/rsa/mod.ts:89:17)
    at verify (https://deno.land/x/djwt@v2.2/signature.ts:122:34)
    at verify (https://deno.land/x/djwt@v2.2/mod.ts:149:13)
    at file:///home/arunscape/Downloads/capstone/server/server.ts:64:27
    at async dispatch (https://deno.land/x/oak@v6.5.0/middleware.ts:41:7)
    at async dispatch (https://deno.land/x/oak@v6.5.0/middleware.ts:41:7)
    at async dispatch (https://deno.land/x/oak@v6.5.0/middleware.ts:41:7)

I have successfully verified my key using jwt.io, but am struggling to verify it with djwt. Any help is appreciated.

jwt header:

{
  "alg": "RS256",
  "typ": "JWT",
  "kid": "bhZbLtSnYfcBV8fKsvJQF"
}

payload:

{
  "https://polyserver.polypong.ca/email": "test@example.com",
  "iss": "https://polypong.us.auth0.com/",
  "sub": "google-oauth2|103380978269062535255",
  "aud": [
    "https://polyserver.polypong.ca",
    "https://polypong.us.auth0.com/userinfo"
  ],
  "iat": 1617403858,
  "exp": 1617490258,
  "azp": "mHazgm6fRKXOgoLxFYRhvstXJRl1dSGC",
  "scope": "openid profile email"
}

edit: I should also probably mention that decode seems to parse the token correctly and I can extract the other data from it

Thanks!