Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type mismatch error with expressJwtSecret and express-jwt@7 #308

Closed
tpluscode opened this issue May 13, 2022 · 3 comments
Closed

Type mismatch error with expressJwtSecret and express-jwt@7 #308

tpluscode opened this issue May 13, 2022 · 3 comments

Comments

@tpluscode
Copy link

Describe the problem

Typescript does not like the return type of jwksRsa.expressJwtSecret. I get this error when relying on TS to resolve the types

TS2322: Type 'SecretCallbackLong | GetVerificationKey' is not assignable to type 'Secret | GetVerificationKey'.
Type 'SecretCallbackLong' is not assignable to type 'Secret | GetVerificationKey'.
Type 'SecretCallbackLong' is not assignable to type 'GetVerificationKey'.

What was the expected behavior?

No type errors

Reproduction

import { expressjwt as jwt } from 'express-jwt'
import jwksRsa from 'jwks-rsa'

const authorize = jwt({
    // Dynamically provide a signing key
    // based on the kid in the header and
    // the signing keys provided by the JWKS endpoint.
    secret: jwksRsa.expressJwtSecret({
      cache: true,
      rateLimit: true,
      jwksRequestsPerMinute: 5,
      jwksUri,
    }),
})

This can be mitigated by explicitly typing as GetVerificationKey

Environment

  • Version of this library used: 2.1.2
  • Other modules/plugins/libraries that might be involved: [email protected]
@trasherdk
Copy link

import { expressjwt as jwt } from 'express-jwt'
import jwksRsa from 'jwks-rsa'

const authorize = jwt({
    // Dynamically provide a signing key
    // based on the kid in the header and
    // the signing keys provided by the JWKS endpoint.
    secret: jwksRsa.expressJwtSecret({
      cache: true,
      rateLimit: true,
      jwksRequestsPerMinute: 5,
      jwksUri,
    }) as GetVerificationKey,
})

Source: auth0/express-jwt#288 (comment)

@adamjmcgrath
Copy link
Contributor

Yep, thanks for posting the workaround. Not much we can do in this SDK about auth0/express-jwt#288 (comment)

@shaunco
Copy link

shaunco commented Dec 20, 2022

At a minimum, the express-demo README should be updated to point out the as GetVerificationKey workaround for typescript users.

klondikemarlen added a commit to icefoganalytics/travel-authorization that referenced this issue Jan 15, 2024
klondikemarlen added a commit to icefoganalytics/travel-authorization that referenced this issue Jan 15, 2024
Use type casting to make jwksRsa work with express-jwt

See auth0/node-jwks-rsa#308
klondikemarlen added a commit to icefoganalytics/travel-authorization that referenced this issue Jan 15, 2024
klondikemarlen added a commit to icefoganalytics/travel-authorization that referenced this issue Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants