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 httpAgent option #458

Merged
merged 1 commit into from
Apr 13, 2023
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
18 changes: 18 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Type definitions for express-openid-connect

import type { Agent as HttpAgent } from 'http';
import type { Agent as HttpsAgent } from 'https';
import {
AuthorizationParameters,
IdTokenClaims,
Expand Down Expand Up @@ -590,6 +592,22 @@ interface ConfigParams {
*/
httpTimeout?: number;

/**
* Specify an Agent or Agents to pass to the underlying http client https://github.com/sindresorhus/got/
*
* An object representing `http`, `https` and `http2` keys for [`http.Agent`](https://nodejs.org/api/http.html#http_class_http_agent),
* [`https.Agent`](https://nodejs.org/api/https.html#https_class_https_agent) and [`http2wrapper.Agent`](https://github.com/szmarczak/http2-wrapper#new-http2agentoptions) instance.
*
* See https://github.com/sindresorhus/got/blob/v11.8.6/readme.md#agent
*
* For a proxy agent see https://www.npmjs.com/package/proxy-agent
*/
httpAgent?: {
http?: HttpAgent | false;
https?: HttpsAgent | false;
http2?: unknown | false;
};

/**
* Optional User-Agent header value for oidc client requests. Default is `express-openid-connect/{version}`.
*/
Expand Down
1 change: 1 addition & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async function get(config) {
: undefined),
};
options.timeout = config.httpTimeout;
options.agent = config.httpAgent;
return options;
};

Expand Down
1 change: 1 addition & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ const paramsSchema = Joi.object({
.default(10 * 60 * 1000),
httpTimeout: Joi.number().optional().min(500).default(5000),
httpUserAgent: Joi.string().optional(),
httpAgent: Joi.object().optional(),
});

module.exports.get = function (config = {}) {
Expand Down
22 changes: 22 additions & 0 deletions test/client.tests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { Agent } = require('https');
const { custom } = require('openid-client');
const fs = require('fs');
const { assert, expect } = require('chai').use(require('chai-as-promised'));
const { get: getConfig } = require('../lib/config');
Expand Down Expand Up @@ -270,6 +272,26 @@ describe('client initialization', function () {
});
});

describe('client respects httpAgent configuration', function () {
const agent = new Agent();

const config = getConfig({
secret: '__test_session_secret__',
clientID: '__test_client_id__',
clientSecret: '__test_client_secret__',
issuerBaseURL: 'https://op.example.com',
baseURL: 'https://example.org',
httpAgent: { https: agent },
});

it('should pass agent argument', async function () {
const handler = sinon.stub().returns([200]);
nock('https://op.example.com').get('/foo').reply(handler);
const client = await getClient({ ...config });
expect(client[custom.http_options]({}).agent.https).to.eq(agent);
});
});

describe('client respects clientAssertionSigningAlg configuration', function () {
const config = {
secret: '__test_session_secret__',
Expand Down