oauth2-cli 2.0.0 → 2.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/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/dist/Client.d.ts +1 -0
- package/dist/Client.js +35 -15
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [2.0.2](https://github.com/battis/oauth2-cli/compare/oauth2-cli/2.0.1...oauth2-cli/2.0.2) (2026-03-27)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* catch bad response earlier ([a47d977](https://github.com/battis/oauth2-cli/commit/a47d9774194c5cdda1c03972c7183837c88d20c1))
|
|
11
|
+
|
|
12
|
+
## [2.0.1](https://github.com/battis/oauth2-cli/compare/oauth2-cli/2.0.0...oauth2-cli/2.0.1) (2026-03-27)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* more detail on bad response ([8a38bd5](https://github.com/battis/oauth2-cli/commit/8a38bd5b86802e0640592117a21d69323a265d8f))
|
|
18
|
+
|
|
5
19
|
## [2.0.0](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.2.8...oauth2-cli/2.0.0) (2026-03-22)
|
|
6
20
|
|
|
7
21
|
|
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ const client = new Client({
|
|
|
33
33
|
storage: new FileStorage('/path/to/token/file.json');
|
|
34
34
|
});
|
|
35
35
|
console.log(
|
|
36
|
-
client.
|
|
36
|
+
client.fetch<ExpectedResponse>('https://example.com/path/to/api/endpoint')
|
|
37
37
|
);
|
|
38
38
|
```
|
|
39
39
|
|
package/dist/Client.d.ts
CHANGED
|
@@ -124,6 +124,7 @@ export declare class Client<C extends Credentials = Credentials> extends EventEm
|
|
|
124
124
|
* server
|
|
125
125
|
*/
|
|
126
126
|
protected prepareRequest(...args: PreparedRequest): Promise<PreparedRequest>;
|
|
127
|
+
private throwNotOkResponse;
|
|
127
128
|
/**
|
|
128
129
|
* Available hook to manipulate the complete response from the server before
|
|
129
130
|
* processing it
|
package/dist/Client.js
CHANGED
|
@@ -256,17 +256,31 @@ export class Client extends EventEmitter {
|
|
|
256
256
|
async requestRaw(url, method = 'GET', body, headers = {}, dPoPOptions) {
|
|
257
257
|
url = new URL(url, this.base_url || this.credentials.issuer);
|
|
258
258
|
url = requestish.URL.from(requestish.URLSearchParams.appendTo(url, requestish.URLSearchParams.merge(this.inject?.search, url.searchParams)));
|
|
259
|
-
|
|
259
|
+
headers = requestish.Headers.merge(this.inject?.headers, headers);
|
|
260
|
+
body = await requestish.Body.from(body);
|
|
261
|
+
const request = async () => await OpenIDClient.fetchProtectedResource(...(await this.prepareRequest(await this.getConfiguration(), (await this.getToken()).access_token, url, method, body, headers, dPoPOptions)));
|
|
260
262
|
try {
|
|
261
263
|
return this.prepareResponse(await request());
|
|
262
264
|
}
|
|
263
|
-
catch (
|
|
264
|
-
if (Error.isError(
|
|
265
|
+
catch (error) {
|
|
266
|
+
if (Error.isError(error) && 'status' in error && error.status === 401) {
|
|
265
267
|
await this.authorize();
|
|
266
268
|
return this.prepareResponse(await request());
|
|
267
269
|
}
|
|
268
270
|
else {
|
|
269
|
-
throw new Error(`${this.name} request failed`, {
|
|
271
|
+
throw new Error(`${this.name} request failed`, {
|
|
272
|
+
cause: {
|
|
273
|
+
request: {
|
|
274
|
+
method,
|
|
275
|
+
url,
|
|
276
|
+
headers: headers
|
|
277
|
+
? Object.fromEntries(headers.entries())
|
|
278
|
+
: undefined,
|
|
279
|
+
body
|
|
280
|
+
},
|
|
281
|
+
error
|
|
282
|
+
}
|
|
283
|
+
});
|
|
270
284
|
}
|
|
271
285
|
}
|
|
272
286
|
}
|
|
@@ -277,11 +291,27 @@ export class Client extends EventEmitter {
|
|
|
277
291
|
async prepareRequest(...args) {
|
|
278
292
|
return args;
|
|
279
293
|
}
|
|
294
|
+
async throwNotOkResponse(response) {
|
|
295
|
+
throw new Error(`${this.name} response status not ok`, {
|
|
296
|
+
cause: {
|
|
297
|
+
response: {
|
|
298
|
+
ok: response.ok,
|
|
299
|
+
status: response.status,
|
|
300
|
+
statusText: response.statusText,
|
|
301
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
302
|
+
body: response.body ? `${await text(response.body)}` : undefined
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
280
307
|
/**
|
|
281
308
|
* Available hook to manipulate the complete response from the server before
|
|
282
309
|
* processing it
|
|
283
310
|
*/
|
|
284
311
|
async prepareResponse(response) {
|
|
312
|
+
if (!response.ok) {
|
|
313
|
+
await this.throwNotOkResponse(response);
|
|
314
|
+
}
|
|
285
315
|
return response;
|
|
286
316
|
}
|
|
287
317
|
/**
|
|
@@ -310,17 +340,7 @@ export class Client extends EventEmitter {
|
|
|
310
340
|
}
|
|
311
341
|
}
|
|
312
342
|
else {
|
|
313
|
-
|
|
314
|
-
cause: {
|
|
315
|
-
response: {
|
|
316
|
-
ok: response.ok,
|
|
317
|
-
status: response.status,
|
|
318
|
-
statusText: response.statusText,
|
|
319
|
-
headers: Object.fromEntries(response.headers.entries()),
|
|
320
|
-
body: response.body ? `${await text(response.body)}` : undefined
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
});
|
|
343
|
+
await this.throwNotOkResponse(response);
|
|
324
344
|
}
|
|
325
345
|
}
|
|
326
346
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oauth2-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Acquire API access tokens via OAuth 2.0 / OpenID Connect within CLI tools",
|
|
5
5
|
"homepage": "https://github.com/battis/oauth2-cli/tree/main/packages/oauth2-cli#readme",
|
|
6
6
|
"repository": {
|