Skip to content

Commit c72b5e8

Browse files
committed
refactor: upgrade got from v9.x to v11.x
BREAKING CHANGE: upgraded got http request library dependency from `v9.x` to `v11.x`. If you override some of the http request options you will most certainly have to accomodate them.
1 parent 641a42f commit c72b5e8

File tree

16 files changed

+83
-89
lines changed

16 files changed

+83
-89
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
strategy:
4444
matrix:
4545
node-version:
46-
- 10.13.0
46+
- 10.19.0
4747
- 10
4848
- 12.0.0
4949
- 12

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ or koa middlewares. Those can however be built using the exposed API.
8181

8282
## Install
8383

84-
Node.js version **>=12.0.0** is recommended, but **^10.13.0** lts/dubnium is also supported.
84+
Node.js version **>=12.0.0** is recommended, but **^10.19.0** lts/dubnium is also supported.
8585

8686
```console
8787
npm install openid-client
@@ -260,7 +260,7 @@ private API and is subject to change between any versions.
260260

261261
#### How do I use it outside of Node.js
262262

263-
It is **only built for ^10.13.0 || >=12.0.0 Node.js** environment - including openid-client in
263+
It is **only built for ^10.19.0 || >=12.0.0 Node.js** environment - including openid-client in
264264
browser-environment targeted projects is not supported and may result in unexpected results.
265265

266266
#### What's new in 3.x?

docs/README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ Fetches an arbitrary resource with the provided Access Token in an Authorization
360360
- `method`: `<string>` The HTTP verb to use for the request. **Default:** 'GET'
361361
- `tokenType`: `<string>` The token type as the Authorization Header scheme. **Default:** 'Bearer'
362362
or the `token_type` property from a passed in TokenSet.
363-
- Returns: `Promise<Response>` Response is a [Got Response](https://github.com/sindresorhus/got/tree/v9.6.0#response)
363+
- Returns: `Promise<Response>` Response is a [Got Response](https://github.com/sindresorhus/got/tree/v11.5.2#response)
364364
with the `body` property being a `<Buffer>`
365365

366366

@@ -523,7 +523,7 @@ Performs Dynamic Client Read Request to retrieve a Client instance.
523523
#### Customizing HTTP requests
524524

525525
The following are default [`got`][got-library] request
526-
[options](https://github.com/sindresorhus/got/tree/v9.6.0#options) that openid-client sets for all
526+
[options](https://github.com/sindresorhus/got/tree/v11.5.2#options) that openid-client sets for all
527527
requests.
528528

529529
```js
@@ -552,7 +552,7 @@ This is meant to change global request options such as `timeout` or the default
552552
<summary><em><strong>Example</strong></em> (Click to expand) debugging HTTP requests and responses</summary>
553553

554554
You can use the [`got`][got-library] request
555-
[options.hooks](https://github.com/sindresorhus/got/tree/v9.6.0#options) to log outgoing requests and their responses.
555+
[options.hooks](https://github.com/sindresorhus/got/tree/v11.5.2#options) to log outgoing requests and their responses.
556556

557557
```js
558558
const { custom } = require('openid-client')
@@ -622,15 +622,15 @@ you need to work around, e.g. adding custom headers or body payload parameters.
622622
```js
623623
const { custom } = require('openid-client');
624624
client[custom.http_options] = function (options) {
625-
// see https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
626-
// key, cert, ca, rejectUnauthorized
627-
options.cert = cert; // <string> | <string[]> | <Buffer> | <Buffer[]>
628-
options.key = key; // <string> | <string[]> | <Buffer> | <Buffer[]> | <Object[]>
625+
// see https://github.com/sindresorhus/got/tree/v11.5.2#advanced-https-api
626+
options.https = options.https || {};
627+
options.https.cert = cert; // <string> | <string[]> | <Buffer> | <Buffer[]>
628+
options.https.key = key; // <string> | <string[]> | <Buffer> | <Buffer[]> | <Object[]>
629629
// custom CA
630-
// options.ca = ca; // <string> | <string[]> | <Buffer> | <Buffer[]>
630+
// options.https.ca = ca; // <string> | <string[]> | <Buffer> | <Buffer[]>
631631

632632
// use HTTP(S)_PROXY
633-
// https://github.com/sindresorhus/got/tree/v9.6.0#agent
633+
// https://github.com/sindresorhus/got/tree/v11.5.2#agent
634634
// options.agent = agent;
635635

636636
return options;
@@ -644,20 +644,20 @@ client[custom.http_options] = function (options) {
644644
```js
645645
const { custom } = require('openid-client');
646646
client[custom.http_options] = function (options) {
647-
// https://github.com/sindresorhus/got/tree/v9.6.0#headers
647+
// https://github.com/sindresorhus/got/tree/v11.5.2#headers
648648
// options.headers = Object.assign(options.headers, { 'custom': 'foo' });
649649

650-
// https://github.com/sindresorhus/got/tree/v9.6.0#timeout
650+
// https://github.com/sindresorhus/got/tree/v11.5.2#timeout
651651
// options.timeout = timeout;
652652

653-
// https://github.com/sindresorhus/got/tree/v9.6.0#retry
653+
// https://github.com/sindresorhus/got/tree/v11.5.2#retry
654654
// options.retry = retry;
655655

656-
// https://github.com/sindresorhus/got/tree/v9.6.0#followredirect
656+
// https://github.com/sindresorhus/got/tree/v11.5.2#followredirect
657657
// options.followRedirect = false;
658658

659659
// use HTTP(S)_PROXY
660-
// https://github.com/sindresorhus/got/tree/v9.6.0#agent
660+
// https://github.com/sindresorhus/got/tree/v11.5.2#agent
661661
// options.agent = agent;
662662

663663
return options;
@@ -987,5 +987,5 @@ request instance.
987987
[support-sponsor]: https://github.com/sponsors/panva
988988
[jose]: https://github.com/panva/jose
989989
[webfinger-discovery]: https://openid.net/specs/openid-connect-discovery-1_0.html#IssuerDiscovery
990-
[got-library]: https://github.com/sindresorhus/got/tree/v9.6.0
990+
[got-library]: https://github.com/sindresorhus/got/tree/v11.5.2
991991
[client-authentication]: https://openid.net/specs/openid-connect-core-1_0.html#ClientAuthentication

lib/client.js

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
10421042

10431043
return request.call(this, {
10441044
...requestOpts,
1045-
encoding: null,
1045+
responseType: 'buffer',
10461046
method,
10471047
url: resourceUrl,
10481048
}, { mTLS });
@@ -1071,8 +1071,7 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
10711071
throw new TypeError('can only send body on POST');
10721072
}
10731073

1074-
const jwt = !!(this.userinfo_signed_response_alg
1075-
|| this.userinfo_encrypted_response_alg);
1074+
const jwt = !!(this.userinfo_signed_response_alg || this.userinfo_encrypted_response_alg);
10761075

10771076
if (jwt) {
10781077
options.headers = { Accept: 'application/jwt' };
@@ -1155,11 +1154,7 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
11551154
try {
11561155
parsed = JSON.parse(response.body);
11571156
} catch (error) {
1158-
const parseError = new ParseError(
1159-
error, response.statusCode, response.request.gotOptions, response.body,
1160-
);
1161-
Object.defineProperty(parseError, 'response', { value: response });
1162-
throw parseError;
1157+
throw new ParseError(error, response);
11631158
}
11641159
}
11651160

@@ -1239,9 +1234,8 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
12391234
this,
12401235
'token',
12411236
{
1242-
form: true,
1243-
body,
1244-
json: true,
1237+
form: body,
1238+
responseType: 'json',
12451239
},
12461240
{ clientAssertionPayload },
12471241
);
@@ -1269,9 +1263,8 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
12691263
this,
12701264
'device_authorization',
12711265
{
1272-
form: true,
1273-
body,
1274-
json: true,
1266+
responseType: 'json',
1267+
form: body,
12751268
},
12761269
{ clientAssertionPayload, endpointAuthMethod: 'token' },
12771270
);
@@ -1296,17 +1289,16 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
12961289
throw new TypeError('hint must be a string');
12971290
}
12981291

1299-
const body = { ...revokeBody, token };
1292+
const form = { ...revokeBody, token };
13001293

13011294
if (hint) {
1302-
body.token_type_hint = hint;
1295+
form.token_type_hint = hint;
13031296
}
13041297

13051298
const response = await authenticatedPost.call(
13061299
this,
13071300
'revocation', {
1308-
body,
1309-
form: true,
1301+
form,
13101302
}, { clientAssertionPayload },
13111303
);
13121304
processResponse(response, { body: false });
@@ -1322,15 +1314,15 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
13221314
throw new TypeError('hint must be a string');
13231315
}
13241316

1325-
const body = { ...introspectBody, token };
1317+
const form = { ...introspectBody, token };
13261318
if (hint) {
1327-
body.token_type_hint = hint;
1319+
form.token_type_hint = hint;
13281320
}
13291321

13301322
const response = await authenticatedPost.call(
13311323
this,
13321324
'introspection',
1333-
{ body, form: true, json: true },
1325+
{ form, responseType: 'json' },
13341326
{ clientAssertionPayload },
13351327
);
13361328

@@ -1443,8 +1435,8 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
14431435
headers: initialAccessToken ? {
14441436
Authorization: authorizationHeaderValue(initialAccessToken),
14451437
} : undefined,
1446-
json: true,
1447-
body: metadata,
1438+
responseType: 'json',
1439+
json: metadata,
14481440
url: this.issuer.registration_endpoint,
14491441
method: 'POST',
14501442
});
@@ -1473,7 +1465,7 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
14731465
const response = await request.call(this, {
14741466
method: 'GET',
14751467
url: registrationClientUri,
1476-
json: true,
1468+
responseType: 'json',
14771469
headers: { Authorization: authorizationHeaderValue(registrationAccessToken) },
14781470
});
14791471
const responseBody = processResponse(response, { bearer: true });

lib/device_flow_handle.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ class DeviceFlowHandle {
4242
instance(this).client,
4343
'token',
4444
{
45-
form: true,
46-
body: {
45+
form: {
4746
...instance(this).exchangeBody,
4847
grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
4948
device_code: this.device_code,
5049
},
51-
json: true,
50+
responseType: 'json',
5251
},
5352
{ clientAssertionPayload: instance(this).clientAssertionPayload },
5453
);

lib/helpers/client.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ async function authFor(endpoint, { clientAssertionPayload } = {}) {
5656
case 'self_signed_tls_client_auth':
5757
case 'tls_client_auth':
5858
case 'none':
59-
return { body: { client_id: this.client_id } };
59+
return { form: { client_id: this.client_id } };
6060
case 'client_secret_post':
6161
if (!this.client_secret) {
6262
throw new TypeError('client_secret_post client authentication method requires a client_secret');
6363
}
64-
return { body: { client_id: this.client_id, client_secret: this.client_secret } };
64+
return { form: { client_id: this.client_id, client_secret: this.client_secret } };
6565
case 'private_key_jwt':
6666
case 'client_secret_jwt': {
6767
const timestamp = now();
@@ -76,7 +76,7 @@ async function authFor(endpoint, { clientAssertionPayload } = {}) {
7676
});
7777

7878
return {
79-
body: {
79+
form: {
8080
client_id: this.client_id,
8181
client_assertion: assertion,
8282
client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
@@ -125,7 +125,7 @@ async function authenticatedPost(endpoint, opts, {
125125
clientAssertionPayload, endpointAuthMethod = endpoint,
126126
} = {}) {
127127
const auth = await authFor.call(this, endpointAuthMethod, { clientAssertionPayload });
128-
const requestOpts = merge(opts, auth, { form: true });
128+
const requestOpts = merge(opts, auth);
129129

130130
const mTLS = this[`${endpointAuthMethod}_endpoint_auth_method`].includes('tls_client_auth')
131131
|| (endpoint === 'token' && this.tls_client_certificate_bound_access_tokens);
@@ -137,10 +137,10 @@ async function authenticatedPost(endpoint, opts, {
137137

138138
targetUrl = targetUrl || this.issuer[`${endpoint}_endpoint`];
139139

140-
if ('body' in requestOpts) {
141-
for (const [key, value] of Object.entries(requestOpts.body)) { // eslint-disable-line no-restricted-syntax, max-len
140+
if ('form' in requestOpts) {
141+
for (const [key, value] of Object.entries(requestOpts.form)) { // eslint-disable-line no-restricted-syntax, max-len
142142
if (typeof value === 'undefined') {
143-
delete requestOpts.body[key];
143+
delete requestOpts.form[key];
144144
}
145145
}
146146
}

lib/helpers/request.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ module.exports = function request(options, { mTLS = false } = {}) {
3333
opts = options;
3434
}
3535

36-
if (mTLS && (!opts.key || !opts.cert)) {
36+
if (
37+
mTLS
38+
&& (
39+
(!opts.key || !opts.cert)
40+
&& (!opts.https || !opts.https.key || !opts.https.certificate)
41+
)
42+
) {
3743
throw new TypeError('mutual-TLS certificate and key not set');
3844
}
3945
return got(opts);

lib/issuer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Issuer {
8585
cache.reset();
8686
const response = await request.call(this, {
8787
method: 'GET',
88-
json: true,
88+
responseType: 'json',
8989
url: this.jwks_uri,
9090
});
9191
const jwks = processResponse(response);
@@ -168,8 +168,8 @@ class Issuer {
168168
const response = await request.call(this, {
169169
method: 'GET',
170170
url: webfingerUrl,
171-
json: true,
172-
query: { resource, rel: REL },
171+
responseType: 'json',
172+
searchParams: { resource, rel: REL },
173173
followRedirect: true,
174174
});
175175
const body = processResponse(response);
@@ -214,7 +214,7 @@ class Issuer {
214214
if (parsed.pathname.includes('/.well-known/')) {
215215
const response = await request.call(this, {
216216
method: 'GET',
217-
json: true,
217+
responseType: 'json',
218218
url: uri,
219219
});
220220
const body = processResponse(response);
@@ -243,7 +243,7 @@ class Issuer {
243243
const wellKnownUri = url.format({ ...parsed, pathname });
244244
const response = await request.call(this, {
245245
method: 'GET',
246-
json: true,
246+
responseType: 'json',
247247
url: wellKnownUri,
248248
});
249249
const body = processResponse(response);

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@
4343
"test": "mocha test/**/*.test.js"
4444
},
4545
"dependencies": {
46-
"@types/got": "^9.6.9",
4746
"base64url": "^3.0.1",
48-
"got": "^9.6.0",
47+
"got": "^11.5.2",
4948
"jose": "^1.27.1",
5049
"lru-cache": "^6.0.0",
5150
"make-error": "^1.3.6",
@@ -70,7 +69,7 @@
7069
"timekeeper": "^2.2.0"
7170
},
7271
"engines": {
73-
"node": "^10.13.0 || >=12.0.0"
72+
"node": "^10.19.0 || >=12.0.0"
7473
},
7574
"commitlint": {
7675
"extends": [

0 commit comments

Comments
 (0)