Skip to content

Commit

Permalink
Merge pull request #251 from auth0/typefix-getKeysInterceptor
Browse files Browse the repository at this point in the history
[SDK-2626] getKeysInterceptor types
  • Loading branch information
adamjmcgrath authored Jul 15, 2021
2 parents 034a5b5 + 45575a6 commit bd315cf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ declare namespace JwksRsa {
timeout?: number;
requestAgent?: HttpAgent | HttpsAgent;
fetcher?(jwksUri: string): Promise<{ keys: any }>;
getKeysInterceptor?(): Promise<SigningKey[]>;
getKeysInterceptor?(): Promise<JSONWebKey[]>;
}

interface JSONWebKey {
kid: string,
alg: string,
[key: string]: any
}

interface CertSigningKey {
Expand Down
21 changes: 21 additions & 0 deletions tests/ts-definitions.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

0 comments on commit bd315cf

Please sign in to comment.