diff --git a/index.d.ts b/index.d.ts index 422f9d3..99516af 100644 --- a/index.d.ts +++ b/index.d.ts @@ -30,7 +30,13 @@ declare namespace JwksRsa { timeout?: number; requestAgent?: HttpAgent | HttpsAgent; fetcher?(jwksUri: string): Promise<{ keys: any }>; - getKeysInterceptor?(): Promise; + getKeysInterceptor?(): Promise; + } + + interface JSONWebKey { + kid: string, + alg: string, + [key: string]: any } interface CertSigningKey { diff --git a/tests/ts-definitions.tests.ts b/tests/ts-definitions.tests.ts index 0cf0401..9d5adc3 100644 --- a/tests/ts-definitions.tests.ts +++ b/tests/ts-definitions.tests.ts @@ -23,4 +23,25 @@ describe('typescript definition', () => { expect(key).to.contain('-----BEGIN PUBLIC KEY'); }); }); + + describe('getKeysInterceptor', async () => { + const keySetResponse = { + keys: [ + { + alg: 'RS256', + kty: 'RSA', + use: 'sig', + kid: 'NkFCNEE1NDFDNTQ5RTQ5OTE1QzRBMjYyMzY0NEJCQTJBMjJBQkZCMA' + } + ] + }; + + const client = new jwksRsa.JwksClient({ + jwksUri: `${jwksHost}/.well-known/jwks.json`, + getKeysInterceptor: () => Promise.resolve(keySetResponse.keys) + }); + + const key = await client.getSigningKey('NkFCNEE1NDFDNTQ5RTQ5OTE1QzRBMjYyMzY0NEJCQTJBMjJBQkZCMA'); + expect(key.kid).to.equal('NkFCNEE1NDFDNTQ5RTQ5OTE1QzRBMjYyMzY0NEJCQTJBMjJBQkZCMA'); + }); });