openid-client 5.6.0 → 5.6.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 +18 -0
- package/lib/client.js +1 -1
- package/lib/helpers/request.js +4 -1
- package/lib/issuer.js +16 -29
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -246,6 +246,24 @@ This will poll in the defined interval and only resolve with a TokenSet once one
|
|
|
246
246
|
will handle the defined `authorization_pending` and `slow_down` "soft" errors and continue polling
|
|
247
247
|
but upon any other error it will reject. With tokenSet received you can throw away the handle.
|
|
248
248
|
|
|
249
|
+
### Client Credentials Grant Flow
|
|
250
|
+
|
|
251
|
+
Client Credentials flow is for obtaining Access Tokens to use with third party APIs on behalf of your application, rather than an end-user which was the case in previous examples.
|
|
252
|
+
|
|
253
|
+
**See the [documentation](./docs/README.md#clientgrantbody-extras) for full API details.**
|
|
254
|
+
|
|
255
|
+
```js
|
|
256
|
+
const client = new issuer.Client({
|
|
257
|
+
client_id: 'zELcpfANLqY7Oqas',
|
|
258
|
+
client_secret: 'TQV5U29k1gHibH5bx1layBo0OSAvAbRT3UYW3EWrSYBB5swxjVfWUa1BS8lqzxG/0v9wruMcrGadany3',
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const tokenSet = await client.grant({
|
|
262
|
+
resource: 'urn:example:third-party-api',
|
|
263
|
+
grant_type: 'client_credentials'
|
|
264
|
+
});
|
|
265
|
+
```
|
|
266
|
+
|
|
249
267
|
## FAQ
|
|
250
268
|
|
|
251
269
|
#### Semver?
|
package/lib/client.js
CHANGED
package/lib/helpers/request.js
CHANGED
|
@@ -39,7 +39,10 @@ const setDefaults = (props, options) => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
setDefaults([], {
|
|
42
|
-
headers: {
|
|
42
|
+
headers: {
|
|
43
|
+
'User-Agent': `${pkg.name}/${pkg.version} (${pkg.homepage})`,
|
|
44
|
+
'Accept-Encoding': 'identity',
|
|
45
|
+
},
|
|
43
46
|
timeout: 3500,
|
|
44
47
|
});
|
|
45
48
|
|
package/lib/issuer.js
CHANGED
|
@@ -138,35 +138,7 @@ class Issuer {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
static async discover(uri) {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
if (parsed.pathname.includes('/.well-known/')) {
|
|
144
|
-
const response = await request.call(this, {
|
|
145
|
-
method: 'GET',
|
|
146
|
-
responseType: 'json',
|
|
147
|
-
url: uri,
|
|
148
|
-
headers: {
|
|
149
|
-
Accept: 'application/json',
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
const body = processResponse(response);
|
|
153
|
-
return new Issuer({
|
|
154
|
-
...ISSUER_DEFAULTS,
|
|
155
|
-
...body,
|
|
156
|
-
[AAD_MULTITENANT]: !!AAD_MULTITENANT_DISCOVERY.find((discoveryURL) =>
|
|
157
|
-
uri.startsWith(discoveryURL),
|
|
158
|
-
),
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
let pathname;
|
|
163
|
-
if (parsed.pathname.endsWith('/')) {
|
|
164
|
-
pathname = `${parsed.pathname}.well-known/openid-configuration`;
|
|
165
|
-
} else {
|
|
166
|
-
pathname = `${parsed.pathname}/.well-known/openid-configuration`;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const wellKnownUri = url.format({ ...parsed, pathname });
|
|
141
|
+
const wellKnownUri = resolveWellKnownUri(uri);
|
|
170
142
|
|
|
171
143
|
const response = await request.call(this, {
|
|
172
144
|
method: 'GET',
|
|
@@ -201,4 +173,19 @@ class Issuer {
|
|
|
201
173
|
}
|
|
202
174
|
}
|
|
203
175
|
|
|
176
|
+
function resolveWellKnownUri(uri) {
|
|
177
|
+
const parsed = url.parse(uri);
|
|
178
|
+
if (parsed.pathname.includes('/.well-known/')) {
|
|
179
|
+
return uri;
|
|
180
|
+
} else {
|
|
181
|
+
let pathname;
|
|
182
|
+
if (parsed.pathname.endsWith('/')) {
|
|
183
|
+
pathname = `${parsed.pathname}.well-known/openid-configuration`;
|
|
184
|
+
} else {
|
|
185
|
+
pathname = `${parsed.pathname}/.well-known/openid-configuration`;
|
|
186
|
+
}
|
|
187
|
+
return url.format({ ...parsed, pathname });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
204
191
|
module.exports = Issuer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openid-client",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.2",
|
|
4
4
|
"description": "OpenID Connect Relying Party (RP, Client) implementation for Node.js runtime, supports passportjs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auth",
|
|
@@ -45,18 +45,18 @@
|
|
|
45
45
|
"test": "mocha test/**/*.test.js"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"jose": "^4.15.
|
|
48
|
+
"jose": "^4.15.4",
|
|
49
49
|
"lru-cache": "^6.0.0",
|
|
50
50
|
"object-hash": "^2.2.0",
|
|
51
51
|
"oidc-token-hash": "^5.0.3"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@types/node": "^16.18.
|
|
55
|
-
"@types/passport": "^1.0.
|
|
54
|
+
"@types/node": "^16.18.59",
|
|
55
|
+
"@types/passport": "^1.0.14",
|
|
56
56
|
"base64url": "^3.0.1",
|
|
57
57
|
"chai": "^4.3.10",
|
|
58
58
|
"mocha": "^10.2.0",
|
|
59
|
-
"nock": "^13.3.
|
|
59
|
+
"nock": "^13.3.6",
|
|
60
60
|
"prettier": "^2.8.8",
|
|
61
61
|
"readable-mock-req": "^0.2.2",
|
|
62
62
|
"sinon": "^9.2.4",
|