-
Notifications
You must be signed in to change notification settings - Fork 234
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
fix: types-compabitility for express-jwt @ 7 #301
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import * as jwksRsaType from '../index'; | ||
import {expect} from 'chai'; | ||
import expressjwt6 from "express-jwt"; | ||
import { expressjwt as expressjwt7, GetVerificationKey } from "express-jwt-v7"; | ||
const { jwksEndpoint } = require('../tests/mocks/jwks'); | ||
const { publicKey } = require('../tests/mocks/keys'); | ||
const { x5cSingle } = require('../tests/keys.js'); | ||
const jwksRsa: typeof jwksRsaType = require('../src'); | ||
|
||
describe('typescript definition', () => { | ||
const jwksHost = 'http://my-authz-server'; | ||
const jwksHost = 'http://localhost'; | ||
|
||
describe('hapiJwt2KeyAsync', () => { | ||
it('should return a secret provider function', async () => { | ||
|
@@ -24,24 +27,31 @@ describe('typescript definition', () => { | |
}); | ||
}); | ||
|
||
describe('getKeysInterceptor', async () => { | ||
const keySetResponse = { | ||
keys: [ | ||
{ | ||
alg: 'RS256', | ||
kty: 'RSA', | ||
use: 'sig', | ||
kid: 'NkFCNEE1NDFDNTQ5RTQ5OTE1QzRBMjYyMzY0NEJCQTJBMjJBQkZCMA' | ||
} | ||
] | ||
}; | ||
|
||
it('getKeysInterceptor', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for spotting this, looks like you've uncovered a failing test. Could you replace |
||
const client = new jwksRsa.JwksClient({ | ||
jwksUri: `${jwksHost}/.well-known/jwks.json`, | ||
getKeysInterceptor: () => Promise.resolve(keySetResponse.keys) | ||
getKeysInterceptor: () => Promise.resolve(x5cSingle.keys) | ||
}); | ||
|
||
const key = await client.getSigningKey('NkFCNEE1NDFDNTQ5RTQ5OTE1QzRBMjYyMzY0NEJCQTJBMjJBQkZCMA'); | ||
expect(key.kid).to.equal('NkFCNEE1NDFDNTQ5RTQ5OTE1QzRBMjYyMzY0NEJCQTJBMjJBQkZCMA'); | ||
}); | ||
|
||
it('Types-Only Validation with express-jwt', () => { | ||
expressjwt6({ | ||
algorithms: ["RS256"], | ||
secret: jwksRsa.expressJwtSecret({ | ||
cache: true, | ||
jwksUri: `https://my-authz-server/.well-known/jwks.json` | ||
}) | ||
}); | ||
|
||
expressjwt7({ | ||
algorithms: ['RS256'], | ||
secret: jwksRsa.expressJwtSecret({ | ||
cache: true, | ||
jwksUri: `https://my-authz-server/.well-known/jwks.json` | ||
}) as GetVerificationKey | ||
}); | ||
}) | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change makes jwks-rsa only compatible with Typescript 3.8+ as the type-only imports and exports feature was release with TS 3.8. For one of my projects, we are on TS 3.7.3, which means this breaks our compatibility
Also - this line is missing a semicolon :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, my bad.
Internally, I'd say update typescript on the project.
If that's not possible, then you may want to open a merge request to address that issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem - we just attempted to upgrade and ran into a couple of other issues. We will be putting up a pull request soon!