diff --git a/README.md b/README.md index 41d414d..f00df66 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ const client = jwksClient({ strictSsl: true, // Default value jwksUri: 'https://sandrino.auth0.com/.well-known/jwks.json', requestHeaders: {}, // Optional - requestAgentOptions: {} // Optional + requestAgentOptions: {}, // Optional + proxy: '[protocol]://[username]:[pass]@[address]:[port]', // Optional }); const kid = 'RkI5MjI5OUY5ODc1N0Q4QzM0OUYzNkVGMTJDOUEzQkFCOTU3NjE2Rg'; diff --git a/index.d.ts b/index.d.ts index 36d9781..c874b4b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -22,6 +22,7 @@ declare namespace JwksRsa { cacheMaxEntries?: number; cacheMaxAge?: number; jwksRequestsPerMinute?: number; + proxy?: string; strictSsl?: boolean; requestHeaders?: Headers; } diff --git a/src/JwksClient.js b/src/JwksClient.js index 411b930..d8318e6 100644 --- a/src/JwksClient.js +++ b/src/JwksClient.js @@ -40,7 +40,8 @@ export class JwksClient { uri: this.options.jwksUri, strictSSL: this.options.strictSsl, headers: this.options.requestHeaders, - agentOptions: this.options.requestAgentOptions + agentOptions: this.options.requestAgentOptions, + proxy: this.options.proxy, }, (err, res) => { if (err || res.statusCode < 200 || res.statusCode >= 300) { this.logger('Failure:', res && res.body || err); diff --git a/tests/jwksClient.tests.js b/tests/jwksClient.tests.js index 075a96e..c9522c7 100644 --- a/tests/jwksClient.tests.js +++ b/tests/jwksClient.tests.js @@ -6,6 +6,7 @@ import { JwksClient } from "../src/JwksClient"; describe("JwksClient", () => { const jwksHost = "http://my-authz-server"; + const proxy = "my-proxy-server:2815"; beforeEach(() => { nock.cleanAll(); @@ -182,8 +183,28 @@ describe("JwksClient", () => { done(); }); }); - }); + it("should use a proxy if specified", done => { + const expectedError = { message: 'expectedError' }; + nock(`http://${proxy}`) + .get(() => true) + .replyWithError(expectedError); + + const client = new JwksClient({ + jwksUri: `${jwksHost}/.well-known/jwks.json`, + requestHeaders: { + "User-Agent": "My-bot" + }, + proxy: `http://username:password@${proxy}`, + }); + + client.getKeys((err) => { + expect(err).to.equal(expectedError); + done(); + }); + }); + }); + describe("#getSigningKeys", () => { it("should handle errors", done => { nock(jwksHost)