Skip to content

Commit

Permalink
Merge pull request #125 from Ogdentrod/feat/add-proxy
Browse files Browse the repository at this point in the history
Add proxy option to jwksClient
  • Loading branch information
davidpatrick authored Feb 18, 2020
2 parents 5fc0f15 + 51d99e9 commit 31177e3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ declare namespace JwksRsa {
cacheMaxEntries?: number;
cacheMaxAge?: number;
jwksRequestsPerMinute?: number;
proxy?: string;
strictSsl?: boolean;
requestHeaders?: Headers;
}
Expand Down
3 changes: 2 additions & 1 deletion src/JwksClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 22 additions & 1 deletion tests/jwksClient.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 31177e3

Please sign in to comment.