openid-client 4.9.0 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -58
- package/lib/client.js +525 -497
- package/lib/device_flow_handle.js +46 -32
- package/lib/errors.js +38 -44
- package/lib/helpers/assert.js +3 -1
- package/lib/helpers/base64url.js +2 -1
- package/lib/helpers/client.js +87 -37
- package/lib/helpers/consts.js +2 -57
- package/lib/helpers/decode_jwt.js +27 -0
- package/lib/helpers/deep_clone.js +3 -1
- package/lib/helpers/defaults.js +0 -2
- package/lib/helpers/generators.js +2 -1
- package/lib/helpers/is_key_object.js +4 -0
- package/lib/helpers/issuer.js +110 -0
- package/lib/helpers/keystore.js +312 -0
- package/lib/helpers/merge.js +0 -2
- package/lib/helpers/pick.js +1 -1
- package/lib/helpers/process_response.js +24 -8
- package/lib/helpers/request.js +152 -26
- package/lib/helpers/weak_cache.js +1 -8
- package/lib/index.js +0 -2
- package/lib/index.mjs +0 -1
- package/lib/issuer.js +84 -162
- package/lib/issuer_registry.js +2 -2
- package/lib/passport_strategy.js +28 -22
- package/lib/token_set.js +2 -22
- package/package.json +8 -12
- package/types/index.d.ts +84 -454
- package/lib/helpers/is_absolute_url.js +0 -12
package/README.md
CHANGED
|
@@ -14,8 +14,6 @@ openid-client.
|
|
|
14
14
|
- Implicit Flow
|
|
15
15
|
- Hybrid Flow
|
|
16
16
|
- UserInfo Request
|
|
17
|
-
- Fetching Distributed Claims
|
|
18
|
-
- Unpacking Aggregated Claims
|
|
19
17
|
- Offline Access / Refresh Token Grant
|
|
20
18
|
- Client Credentials Grant
|
|
21
19
|
- Client Authentication
|
|
@@ -25,7 +23,7 @@ openid-client.
|
|
|
25
23
|
- client_secret_jwt
|
|
26
24
|
- private_key_jwt
|
|
27
25
|
- Consuming Self-Issued OpenID Provider ID Token response
|
|
28
|
-
- [
|
|
26
|
+
- [OpenID Connect Discovery 1.0][feature-discovery]
|
|
29
27
|
- Discovery of OpenID Provider (Issuer) Metadata
|
|
30
28
|
- Discovery of OpenID Provider (Issuer) Metadata via user provided inputs (via [webfinger][documentation-webfinger])
|
|
31
29
|
- [OpenID Connect Dynamic Client Registration 1.0][feature-registration]
|
|
@@ -44,13 +42,12 @@ openid-client.
|
|
|
44
42
|
- self_signed_tls_client_auth
|
|
45
43
|
- [RFC9101 - OAuth 2.0 JWT-Secured Authorization Request (JAR)][feature-jar]
|
|
46
44
|
- [RFC9126 - OAuth 2.0 Pushed Authorization Requests (PAR)][feature-par]
|
|
47
|
-
- [OpenID Connect
|
|
48
|
-
|
|
49
|
-
- [Financial-grade API - Part 2: Read and Write API Security Profile (FAPI) - ID2][feature-fapi]
|
|
45
|
+
- [OpenID Connect RP-Initiated Logout 1.0 - draft 01][feature-rp-logout]
|
|
46
|
+
- [Financial-grade API Security Profile 1.0 - Part 2: Advanced (FAPI)][feature-fapi]
|
|
50
47
|
- [JWT Secured Authorization Response Mode for OAuth 2.0 (JARM) - ID1][feature-jarm]
|
|
51
48
|
- [OAuth 2.0 Demonstration of Proof-of-Possession at the Application Layer (DPoP) - draft 03][feature-dpop]
|
|
52
49
|
|
|
53
|
-
Updates to draft specifications (DPoP, JARM,
|
|
50
|
+
Updates to draft specifications (DPoP, JARM, etc) are released as MINOR library versions,
|
|
54
51
|
if you utilize these specification implementations consider using the tilde `~` operator in your
|
|
55
52
|
package.json since breaking changes may be introduced as part of these version updates.
|
|
56
53
|
|
|
@@ -59,13 +56,12 @@ package.json since breaking changes may be introduced as part of these version u
|
|
|
59
56
|
Filip Skokan has [certified][openid-certified-link] that [openid-client][npm-url]
|
|
60
57
|
conforms to the following profiles of the OpenID Connect™ protocol
|
|
61
58
|
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
|
|
59
|
+
- Basic, Implicit, Hybrid, Config, Dynamic, and Form Post RP
|
|
60
|
+
- FAPI 1.0 Advanced RP
|
|
65
61
|
|
|
66
62
|
## Sponsor
|
|
67
63
|
|
|
68
|
-
[<img
|
|
64
|
+
[<img height="65" align="left" src="https://cdn.auth0.com/blog/github-sponsorships/brand-evolution-logo-Auth0-horizontal-Indigo.png" alt="auth0-logo">][sponsor-auth0] If you want to quickly add OpenID Connect authentication to Node.js apps, feel free to check out Auth0's Node.js SDK and free plan. [Create an Auth0 account; it's free!][sponsor-auth0]<br><br>
|
|
69
65
|
|
|
70
66
|
## Support
|
|
71
67
|
|
|
@@ -76,8 +72,8 @@ If you or your business use openid-client, please consider becoming a [sponsor][
|
|
|
76
72
|
|
|
77
73
|
The library exposes what are essentially steps necessary to be done by a relying party consuming
|
|
78
74
|
OpenID Connect Authorization Server responses or wrappers around requests to its endpoints. Aside
|
|
79
|
-
from a generic OpenID Connect [passport][passport-url] strategy it does not expose
|
|
80
|
-
|
|
75
|
+
from a generic OpenID Connect [passport][passport-url] strategy it does not expose any framework
|
|
76
|
+
specific middlewares. Those can however be built using the exposed API, one such example is [express-openid-connect][]
|
|
81
77
|
|
|
82
78
|
- [openid-client API Documentation][documentation]
|
|
83
79
|
- [Issuer][documentation-issuer]
|
|
@@ -90,7 +86,9 @@ or koa middlewares. Those can however be built using the exposed API.
|
|
|
90
86
|
|
|
91
87
|
## Install
|
|
92
88
|
|
|
93
|
-
Node.js
|
|
89
|
+
Node.js LTS releases Codename Erbium (starting with ^12.19.0) and newer LTS releases are supported.
|
|
90
|
+
This means ^12.19.0 (Erbium), ^14.15.0 (Fermium), and ^16.13.0 (Gallium). Future LTS releases will
|
|
91
|
+
be added to this list as they're released.
|
|
94
92
|
|
|
95
93
|
```console
|
|
96
94
|
npm install openid-client
|
|
@@ -100,11 +98,10 @@ npm install openid-client
|
|
|
100
98
|
|
|
101
99
|
Discover an Issuer configuration using its published .well-known endpoints
|
|
102
100
|
```js
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
});
|
|
101
|
+
import { Issuer } from 'openid-client';
|
|
102
|
+
|
|
103
|
+
const googleIssuer = await Issuer.discover('https://accounts.google.com');
|
|
104
|
+
console.log('Discovered issuer %s %O', googleIssuer.issuer, googleIssuer.metadata);
|
|
108
105
|
```
|
|
109
106
|
|
|
110
107
|
### Authorization Code Flow
|
|
@@ -116,7 +113,7 @@ PKCE instead of `state` parameter for CSRF protection.
|
|
|
116
113
|
Create a Client instance for that issuer's authorization server intended for Authorization Code
|
|
117
114
|
flow.
|
|
118
115
|
|
|
119
|
-
**See the [documentation][
|
|
116
|
+
**See the [documentation][] for full API details.**
|
|
120
117
|
|
|
121
118
|
```js
|
|
122
119
|
const client = new googleIssuer.Client({
|
|
@@ -135,7 +132,7 @@ to get the authorization endpoint's URL with parameters already encoded in the q
|
|
|
135
132
|
to.
|
|
136
133
|
|
|
137
134
|
```js
|
|
138
|
-
|
|
135
|
+
import { generators } from 'openid-client';
|
|
139
136
|
const code_verifier = generators.codeVerifier();
|
|
140
137
|
// store the code_verifier in your framework's session mechanism, if it is a cookie based solution
|
|
141
138
|
// it should be httpOnly (not readable by javascript) and encrypted.
|
|
@@ -154,28 +151,22 @@ When end-users are redirected back to your `redirect_uri` your application consu
|
|
|
154
151
|
passes in the `code_verifier` to include it in the authorization code grant token exchange.
|
|
155
152
|
```js
|
|
156
153
|
const params = client.callbackParams(req);
|
|
157
|
-
client.callback('https://client.example.com/callback', params, { code_verifier })
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
console.log('validated ID Token claims %j', tokenSet.claims());
|
|
161
|
-
});
|
|
154
|
+
const tokenSet = await client.callback('https://client.example.com/callback', params, { code_verifier });
|
|
155
|
+
console.log('received and validated tokens %j', tokenSet);
|
|
156
|
+
console.log('validated ID Token claims %j', tokenSet.claims());
|
|
162
157
|
```
|
|
163
158
|
|
|
164
159
|
You can then call the `userinfo_endpoint`.
|
|
165
160
|
```js
|
|
166
|
-
client.userinfo(access_token)
|
|
167
|
-
|
|
168
|
-
console.log('userinfo %j', userinfo);
|
|
169
|
-
});
|
|
161
|
+
const userinfo = await client.userinfo(access_token);
|
|
162
|
+
console.log('userinfo %j', userinfo);
|
|
170
163
|
```
|
|
171
164
|
|
|
172
165
|
And later refresh the tokenSet if it had a `refresh_token`.
|
|
173
166
|
```js
|
|
174
|
-
client.refresh(refresh_token)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
console.log('refreshed ID Token claims %j', tokenSet.claims());
|
|
178
|
-
});
|
|
167
|
+
const tokenSet = await client.refresh(refresh_token);
|
|
168
|
+
console.log('refreshed and validated tokens %j', tokenSet);
|
|
169
|
+
console.log('refreshed ID Token claims %j', tokenSet.claims());
|
|
179
170
|
```
|
|
180
171
|
|
|
181
172
|
### Implicit ID Token Flow
|
|
@@ -186,7 +177,7 @@ with no need for accessing any third party APIs with an Access Token from the Au
|
|
|
186
177
|
|
|
187
178
|
Create a Client instance for that issuer's authorization server intended for ID Token implicit flow.
|
|
188
179
|
|
|
189
|
-
**See the [documentation][
|
|
180
|
+
**See the [documentation][] for full API details.**
|
|
190
181
|
```js
|
|
191
182
|
const client = new googleIssuer.Client({
|
|
192
183
|
client_id: 'zELcpfANLqY7Oqas',
|
|
@@ -202,7 +193,7 @@ to get the authorization endpoint's URL with parameters already encoded in the q
|
|
|
202
193
|
to.
|
|
203
194
|
|
|
204
195
|
```js
|
|
205
|
-
|
|
196
|
+
import { generators } from 'openid-client';
|
|
206
197
|
const nonce = generators.nonce();
|
|
207
198
|
// store the nonce in your framework's session mechanism, if it is a cookie based solution
|
|
208
199
|
// it should be httpOnly (not readable by javascript) and encrypted.
|
|
@@ -220,11 +211,9 @@ ID Token verification steps.
|
|
|
220
211
|
```js
|
|
221
212
|
// assumes req.body is populated from your web framework's body parser
|
|
222
213
|
const params = client.callbackParams(req);
|
|
223
|
-
client.callback('https://client.example.com/callback', params, { nonce })
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
console.log('validated ID Token claims %j', tokenSet.claims());
|
|
227
|
-
});
|
|
214
|
+
const tokenSet = await client.callback('https://client.example.com/callback', params, { nonce });
|
|
215
|
+
console.log('received and validated tokens %j', tokenSet);
|
|
216
|
+
console.log('validated ID Token claims %j', tokenSet.claims());
|
|
228
217
|
```
|
|
229
218
|
|
|
230
219
|
### Device Authorization Grant (Device Flow)
|
|
@@ -253,11 +242,6 @@ This will poll in the defined interval and only resolve with a TokenSet once one
|
|
|
253
242
|
will handle the defined `authorization_pending` and `slow_down` "soft" errors and continue polling
|
|
254
243
|
but upon any other error it will reject. With tokenSet received you can throw away the handle.
|
|
255
244
|
|
|
256
|
-
## Electron Support
|
|
257
|
-
|
|
258
|
-
Electron >=v6.0.0 runtime is supported to the extent of the crypto engine BoringSSL feature parity
|
|
259
|
-
with standard Node.js OpenSSL.
|
|
260
|
-
|
|
261
245
|
## FAQ
|
|
262
246
|
|
|
263
247
|
#### Semver?
|
|
@@ -269,8 +253,8 @@ private API and is subject to change between any versions.
|
|
|
269
253
|
|
|
270
254
|
#### How do I use it outside of Node.js
|
|
271
255
|
|
|
272
|
-
It is **only built for
|
|
273
|
-
browser-environment targeted projects is not supported
|
|
256
|
+
It is **only built for Node.js** environments - including openid-client in
|
|
257
|
+
browser-environment targeted projects is not supported.
|
|
274
258
|
|
|
275
259
|
#### How to make the client send client_id and client_secret in the body?
|
|
276
260
|
|
|
@@ -278,32 +262,27 @@ See [Client Authentication Methods (docs)][documentation-methods].
|
|
|
278
262
|
|
|
279
263
|
#### Can I adjust the HTTP timeout?
|
|
280
264
|
|
|
281
|
-
See [Customizing (docs)]
|
|
282
|
-
|
|
283
|
-
#### How can I debug the requests and responses?
|
|
284
|
-
|
|
285
|
-
See [Customizing (docs)](https://github.com/panva/node-openid-client/blob/master/docs/README.md#customizing).
|
|
265
|
+
See [Customizing (docs)][documentation-customizing].
|
|
286
266
|
|
|
287
267
|
|
|
288
268
|
[openid-connect]: https://openid.net/connect/
|
|
289
269
|
[feature-core]: https://openid.net/specs/openid-connect-core-1_0.html
|
|
290
270
|
[feature-discovery]: https://openid.net/specs/openid-connect-discovery-1_0.html
|
|
291
|
-
[feature-oauth-discovery]: https://tools.ietf.org/html/rfc8414
|
|
292
271
|
[feature-registration]: https://openid.net/specs/openid-connect-registration-1_0.html
|
|
293
272
|
[feature-revocation]: https://tools.ietf.org/html/rfc7009
|
|
294
273
|
[feature-introspection]: https://tools.ietf.org/html/rfc7662
|
|
295
274
|
[feature-mtls]: https://tools.ietf.org/html/rfc8705
|
|
296
275
|
[feature-device-flow]: https://tools.ietf.org/html/rfc8628
|
|
297
|
-
[feature-rp-logout]: https://openid.net/specs/openid-connect-
|
|
276
|
+
[feature-rp-logout]: https://openid.net/specs/openid-connect-rpinitiated-1_0-01.html
|
|
298
277
|
[feature-jarm]: https://openid.net/specs/openid-financial-api-jarm-ID1.html
|
|
299
|
-
[feature-fapi]: https://openid.net/specs/openid-financial-api-part-2-
|
|
278
|
+
[feature-fapi]: https://openid.net/specs/openid-financial-api-part-2-1_0.html
|
|
300
279
|
[feature-dpop]: https://tools.ietf.org/html/draft-ietf-oauth-dpop-03
|
|
301
280
|
[feature-par]: https://www.rfc-editor.org/rfc/rfc9126.html
|
|
302
281
|
[feature-jar]: https://www.rfc-editor.org/rfc/rfc9101.html
|
|
303
282
|
[openid-certified-link]: https://openid.net/certification/
|
|
304
283
|
[passport-url]: http://passportjs.org
|
|
305
284
|
[npm-url]: https://www.npmjs.com/package/openid-client
|
|
306
|
-
[sponsor-auth0]: https://
|
|
285
|
+
[sponsor-auth0]: https://a0.to/try-auth0
|
|
307
286
|
[support-sponsor]: https://github.com/sponsors/panva
|
|
308
287
|
[documentation]: https://github.com/panva/node-openid-client/blob/master/docs/README.md
|
|
309
288
|
[documentation-issuer]: https://github.com/panva/node-openid-client/blob/master/docs/README.md#issuer
|
|
@@ -315,3 +294,4 @@ See [Customizing (docs)](https://github.com/panva/node-openid-client/blob/master
|
|
|
315
294
|
[documentation-generators]: https://github.com/panva/node-openid-client/blob/master/docs/README.md#generators
|
|
316
295
|
[documentation-methods]: https://github.com/panva/node-openid-client/blob/master/docs/README.md#client-authentication-methods
|
|
317
296
|
[documentation-webfinger]: https://github.com/panva/node-openid-client/blob/master/docs/README.md#issuerwebfingerinput
|
|
297
|
+
[express-openid-connect]: https://www.npmjs.com/package/express-openid-connect
|