oauth2-cli 1.2.0 → 1.2.3
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 +16 -0
- package/dist/Client.d.ts +6 -6
- package/dist/Client.js +16 -18
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
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
|
+
## [1.2.3](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.2.2...oauth2-cli/1.2.3) (2026-03-08)
|
|
6
|
+
|
|
7
|
+
## [1.2.2](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.2.1...oauth2-cli/1.2.2) (2026-03-08)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* don't lose search params when building url from base or credentials.issuer ([a328c96](https://github.com/battis/oauth2-cli/commit/a328c9693d0a39cccc7d6f38bd24065b6f633c1b))
|
|
13
|
+
|
|
14
|
+
## [1.2.1](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.2.0...oauth2-cli/1.2.1) (2026-03-08)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* still more detail on JSON error ([d9d28ce](https://github.com/battis/oauth2-cli/commit/d9d28ce8145a5c29288f28317041e8545b232a1e))
|
|
20
|
+
|
|
5
21
|
## [1.2.0](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.1.5...oauth2-cli/1.2.0) (2026-03-08)
|
|
6
22
|
|
|
7
23
|
|
package/dist/Client.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { JSONValue } from '@battis/typescript-tricks';
|
|
|
2
2
|
import { Request } from 'express';
|
|
3
3
|
import { EventEmitter } from 'node:events';
|
|
4
4
|
import * as OpenIDClient from 'openid-client';
|
|
5
|
-
import
|
|
5
|
+
import * as requestish from 'requestish';
|
|
6
6
|
import { Credentials } from './Credentials.js';
|
|
7
7
|
import { Injection } from './Injection.js';
|
|
8
8
|
import * as Localhost from './Localhost/index.js';
|
|
@@ -26,7 +26,7 @@ export declare class Client<C extends Credentials = Credentials> extends EventEm
|
|
|
26
26
|
/** Credentials for server access */
|
|
27
27
|
credentials: C;
|
|
28
28
|
/** Base URL for all non-absolute requests */
|
|
29
|
-
base_url?: URL.ish;
|
|
29
|
+
base_url?: requestish.URL.ish;
|
|
30
30
|
/**
|
|
31
31
|
* `openid-client` configuration metadata (either dervied from
|
|
32
32
|
* {@link credentials}) or requested from the well-known OpenID configuration
|
|
@@ -117,7 +117,7 @@ export declare class Client<C extends Credentials = Credentials> extends EventEm
|
|
|
117
117
|
* @param body Optional
|
|
118
118
|
* @param dPoPOptions Optional, see {@link OpenIDClient.DPoPOptions}
|
|
119
119
|
*/
|
|
120
|
-
request(url: URL.ish, method?: string, body?: Body.ish, headers?: Headers.ish, dPoPOptions?: OpenIDClient.DPoPOptions): Promise<Response>;
|
|
120
|
+
request(url: requestish.URL.ish, method?: string, body?: requestish.Body.ish, headers?: requestish.Headers.ish, dPoPOptions?: OpenIDClient.DPoPOptions): Promise<Response>;
|
|
121
121
|
/**
|
|
122
122
|
* Available hook to manipulate a fully-prepared request before sending to the
|
|
123
123
|
* server
|
|
@@ -134,7 +134,7 @@ export declare class Client<C extends Credentials = Credentials> extends EventEm
|
|
|
134
134
|
* Returns the result of {@link request} as a parsed JSON object, optionally
|
|
135
135
|
* typed as `J`
|
|
136
136
|
*/
|
|
137
|
-
requestJSON<J extends JSONValue = JSONValue>(url: URL.ish, method?: string, body?: Body.ish, headers?: Headers.ish, dPoPOptions?: OpenIDClient.DPoPOptions): Promise<J>;
|
|
137
|
+
requestJSON<J extends JSONValue = JSONValue>(url: requestish.URL.ish, method?: string, body?: requestish.Body.ish, headers?: requestish.Headers.ish, dPoPOptions?: OpenIDClient.DPoPOptions): Promise<J>;
|
|
138
138
|
/**
|
|
139
139
|
* Request a protected resource using the client's access token.
|
|
140
140
|
*
|
|
@@ -147,10 +147,10 @@ export declare class Client<C extends Credentials = Credentials> extends EventEm
|
|
|
147
147
|
* @param dPoPOptions Optional, see {@link OpenIDClient.DPoPOptions}
|
|
148
148
|
* @see {@link request} for which this is an alias for {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API Fetch API}-style requests
|
|
149
149
|
*/
|
|
150
|
-
fetch(input: URL.ish, init?: RequestInit, dPoPOptions?: OpenIDClient.DPoPOptions): Promise<Response>;
|
|
150
|
+
fetch(input: requestish.URL.ish, init?: RequestInit, dPoPOptions?: OpenIDClient.DPoPOptions): Promise<Response>;
|
|
151
151
|
/**
|
|
152
152
|
* Returns the result of {@link fetch} as a parsed JSON object, optionally
|
|
153
153
|
* typed as `J`
|
|
154
154
|
*/
|
|
155
|
-
fetchJSON<J extends JSONValue = JSONValue>(input: URL.ish, init?: RequestInit, dPoPOptions?: OpenIDClient.DPoPOptions): Promise<J>;
|
|
155
|
+
fetchJSON<J extends JSONValue = JSONValue>(input: requestish.URL.ish, init?: RequestInit, dPoPOptions?: OpenIDClient.DPoPOptions): Promise<J>;
|
|
156
156
|
}
|
package/dist/Client.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Mutex } from 'async-mutex';
|
|
2
2
|
import * as gcrtl from 'gcrtl';
|
|
3
3
|
import { EventEmitter } from 'node:events';
|
|
4
|
-
import
|
|
4
|
+
import { text } from 'node:stream/consumers';
|
|
5
5
|
import * as OpenIDClient from 'openid-client';
|
|
6
|
-
import
|
|
6
|
+
import * as requestish from 'requestish';
|
|
7
7
|
import * as Localhost from './Localhost/index.js';
|
|
8
8
|
import * as Token from './Token/index.js';
|
|
9
9
|
/**
|
|
@@ -64,7 +64,7 @@ export class Client extends EventEmitter {
|
|
|
64
64
|
let discovery = undefined;
|
|
65
65
|
if (!this.config && this.credentials.issuer) {
|
|
66
66
|
try {
|
|
67
|
-
this.config = await OpenIDClient.discovery(URL.from(this.credentials.issuer), this.credentials.client_id, { client_secret: this.credentials.client_secret });
|
|
67
|
+
this.config = await OpenIDClient.discovery(requestish.URL.from(this.credentials.issuer), this.credentials.client_id, { client_secret: this.credentials.client_secret });
|
|
68
68
|
}
|
|
69
69
|
catch (error) {
|
|
70
70
|
discovery = error;
|
|
@@ -72,9 +72,9 @@ export class Client extends EventEmitter {
|
|
|
72
72
|
}
|
|
73
73
|
if (!this.config && this.credentials?.authorization_endpoint) {
|
|
74
74
|
this.config = new OpenIDClient.Configuration({
|
|
75
|
-
issuer: `https://${URL.from(this.credentials.authorization_endpoint).hostname}`,
|
|
76
|
-
authorization_endpoint: URL.toString(this.credentials.authorization_endpoint),
|
|
77
|
-
token_endpoint: URL.toString(this.credentials.token_endpoint ||
|
|
75
|
+
issuer: `https://${requestish.URL.from(this.credentials.authorization_endpoint).hostname}`,
|
|
76
|
+
authorization_endpoint: requestish.URL.toString(this.credentials.authorization_endpoint),
|
|
77
|
+
token_endpoint: requestish.URL.toString(this.credentials.token_endpoint ||
|
|
78
78
|
this.credentials.authorization_endpoint)
|
|
79
79
|
}, this.credentials.client_id, { client_secret: this.credentials.client_secret });
|
|
80
80
|
}
|
|
@@ -96,8 +96,8 @@ export class Client extends EventEmitter {
|
|
|
96
96
|
* Authorization Code flow session
|
|
97
97
|
*/
|
|
98
98
|
async buildAuthorizationUrl(session) {
|
|
99
|
-
const params = URLSearchParams.from(this.inject?.search);
|
|
100
|
-
params.set('redirect_uri', URL.toString(this.credentials.redirect_uri));
|
|
99
|
+
const params = requestish.URLSearchParams.from(this.inject?.search);
|
|
100
|
+
params.set('redirect_uri', requestish.URL.toString(this.credentials.redirect_uri));
|
|
101
101
|
params.set('code_challenge', await OpenIDClient.calculatePKCECodeChallenge(session.code_verifier));
|
|
102
102
|
params.set('code_challenge_method', 'S256');
|
|
103
103
|
params.set('state', session.state);
|
|
@@ -160,7 +160,7 @@ export class Client extends EventEmitter {
|
|
|
160
160
|
pkceCodeVerifier: session.code_verifier,
|
|
161
161
|
expectedState: session.state
|
|
162
162
|
}, this.inject?.search
|
|
163
|
-
? URLSearchParams.from(this.inject.search)
|
|
163
|
+
? requestish.URLSearchParams.from(this.inject.search)
|
|
164
164
|
: undefined);
|
|
165
165
|
}
|
|
166
166
|
catch (cause) {
|
|
@@ -185,10 +185,10 @@ export class Client extends EventEmitter {
|
|
|
185
185
|
}
|
|
186
186
|
try {
|
|
187
187
|
const token = await OpenIDClient.refreshTokenGrant(await this.getConfiguration(), refresh_token, this.inject?.search
|
|
188
|
-
? URLSearchParams.from(this.inject.search)
|
|
188
|
+
? requestish.URLSearchParams.from(this.inject.search)
|
|
189
189
|
: undefined, {
|
|
190
190
|
// @ts-expect-error 2322 undocumented arg pass-through to oauth4webapi
|
|
191
|
-
headers: Headers.merge(this.headers, inject?.headers)
|
|
191
|
+
headers: requestish.Headers.merge(this.headers, inject?.headers)
|
|
192
192
|
});
|
|
193
193
|
return await this.save(token);
|
|
194
194
|
}
|
|
@@ -255,13 +255,11 @@ export class Client extends EventEmitter {
|
|
|
255
255
|
*/
|
|
256
256
|
async request(url, method = 'GET', body, headers = {}, dPoPOptions) {
|
|
257
257
|
try {
|
|
258
|
-
url = URL.from(url);
|
|
258
|
+
url = requestish.URL.from(url);
|
|
259
259
|
}
|
|
260
260
|
catch (error) {
|
|
261
261
|
if (this.base_url || this.credentials.issuer) {
|
|
262
|
-
url =
|
|
263
|
-
// @ts-expect-error 2345 TS, I _just_ tested this!
|
|
264
|
-
URL.toString(this.base_url || this.credentials.issuer), URL.toString(url).replace(/^\/?/, ''));
|
|
262
|
+
url = new URL(url, this.base_url || this.credentials.issuer);
|
|
265
263
|
}
|
|
266
264
|
else {
|
|
267
265
|
throw new Error(`${this.name} request url invalid`, {
|
|
@@ -273,7 +271,7 @@ export class Client extends EventEmitter {
|
|
|
273
271
|
});
|
|
274
272
|
}
|
|
275
273
|
}
|
|
276
|
-
const request = async () => await OpenIDClient.fetchProtectedResource(...(await this.prepareRequest(await this.getConfiguration(), (await this.getToken()).access_token, URL.from(URLSearchParams.appendTo(url, this.inject?.search || {})), method, await Body.from(body), Headers.merge(this.inject?.headers, headers), dPoPOptions)));
|
|
274
|
+
const request = async () => await OpenIDClient.fetchProtectedResource(...(await this.prepareRequest(await this.getConfiguration(), (await this.getToken()).access_token, requestish.URL.from(requestish.URLSearchParams.appendTo(url, this.inject?.search || {})), method, await requestish.Body.from(body), requestish.Headers.merge(this.inject?.headers, headers), dPoPOptions)));
|
|
277
275
|
try {
|
|
278
276
|
return this.prepareResponse(await request());
|
|
279
277
|
}
|
|
@@ -321,7 +319,7 @@ export class Client extends EventEmitter {
|
|
|
321
319
|
status: response.status,
|
|
322
320
|
statusText: response.statusText,
|
|
323
321
|
headers: Object.fromEntries(response.headers.entries()),
|
|
324
|
-
body: `${response.body}`
|
|
322
|
+
body: response.body ? `${await text(response.body)}` : undefined
|
|
325
323
|
}
|
|
326
324
|
}
|
|
327
325
|
});
|
|
@@ -347,7 +345,7 @@ export class Client extends EventEmitter {
|
|
|
347
345
|
* @see {@link request} for which this is an alias for {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API Fetch API}-style requests
|
|
348
346
|
*/
|
|
349
347
|
async fetch(input, init, dPoPOptions) {
|
|
350
|
-
return await this.request(input, init?.method, await Body.from(init?.body), Headers.from(init?.headers), dPoPOptions);
|
|
348
|
+
return await this.request(input, init?.method, await requestish.Body.from(init?.body), requestish.Headers.from(init?.headers), dPoPOptions);
|
|
351
349
|
}
|
|
352
350
|
/**
|
|
353
351
|
* Returns the result of {@link fetch} as a parsed JSON object, optionally
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oauth2-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
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": {
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"open": "^11.0.0",
|
|
24
24
|
"openid-client": "^6.8.2",
|
|
25
25
|
"ora": "^9.3.0",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"gcrtl": "0.1.11",
|
|
27
|
+
"requestish": "0.1.10"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@battis/descriptive-types": "^0.2.6",
|