Skip to content
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

Add proxy option to jwksClient #125

Merged
merged 5 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
});

benoitsepe marked this conversation as resolved.
Show resolved Hide resolved
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