oauth2-cli 1.2.1 → 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 +9 -0
- package/dist/Client.d.ts +6 -6
- package/dist/Client.js +14 -17
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
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
|
+
|
|
5
14
|
## [1.2.1](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.2.0...oauth2-cli/1.2.1) (2026-03-08)
|
|
6
15
|
|
|
7
16
|
|
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,10 +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 path from 'node:path';
|
|
5
4
|
import { text } from 'node:stream/consumers';
|
|
6
5
|
import * as OpenIDClient from 'openid-client';
|
|
7
|
-
import
|
|
6
|
+
import * as requestish from 'requestish';
|
|
8
7
|
import * as Localhost from './Localhost/index.js';
|
|
9
8
|
import * as Token from './Token/index.js';
|
|
10
9
|
/**
|
|
@@ -65,7 +64,7 @@ export class Client extends EventEmitter {
|
|
|
65
64
|
let discovery = undefined;
|
|
66
65
|
if (!this.config && this.credentials.issuer) {
|
|
67
66
|
try {
|
|
68
|
-
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 });
|
|
69
68
|
}
|
|
70
69
|
catch (error) {
|
|
71
70
|
discovery = error;
|
|
@@ -73,9 +72,9 @@ export class Client extends EventEmitter {
|
|
|
73
72
|
}
|
|
74
73
|
if (!this.config && this.credentials?.authorization_endpoint) {
|
|
75
74
|
this.config = new OpenIDClient.Configuration({
|
|
76
|
-
issuer: `https://${URL.from(this.credentials.authorization_endpoint).hostname}`,
|
|
77
|
-
authorization_endpoint: URL.toString(this.credentials.authorization_endpoint),
|
|
78
|
-
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 ||
|
|
79
78
|
this.credentials.authorization_endpoint)
|
|
80
79
|
}, this.credentials.client_id, { client_secret: this.credentials.client_secret });
|
|
81
80
|
}
|
|
@@ -97,8 +96,8 @@ export class Client extends EventEmitter {
|
|
|
97
96
|
* Authorization Code flow session
|
|
98
97
|
*/
|
|
99
98
|
async buildAuthorizationUrl(session) {
|
|
100
|
-
const params = URLSearchParams.from(this.inject?.search);
|
|
101
|
-
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));
|
|
102
101
|
params.set('code_challenge', await OpenIDClient.calculatePKCECodeChallenge(session.code_verifier));
|
|
103
102
|
params.set('code_challenge_method', 'S256');
|
|
104
103
|
params.set('state', session.state);
|
|
@@ -161,7 +160,7 @@ export class Client extends EventEmitter {
|
|
|
161
160
|
pkceCodeVerifier: session.code_verifier,
|
|
162
161
|
expectedState: session.state
|
|
163
162
|
}, this.inject?.search
|
|
164
|
-
? URLSearchParams.from(this.inject.search)
|
|
163
|
+
? requestish.URLSearchParams.from(this.inject.search)
|
|
165
164
|
: undefined);
|
|
166
165
|
}
|
|
167
166
|
catch (cause) {
|
|
@@ -186,10 +185,10 @@ export class Client extends EventEmitter {
|
|
|
186
185
|
}
|
|
187
186
|
try {
|
|
188
187
|
const token = await OpenIDClient.refreshTokenGrant(await this.getConfiguration(), refresh_token, this.inject?.search
|
|
189
|
-
? URLSearchParams.from(this.inject.search)
|
|
188
|
+
? requestish.URLSearchParams.from(this.inject.search)
|
|
190
189
|
: undefined, {
|
|
191
190
|
// @ts-expect-error 2322 undocumented arg pass-through to oauth4webapi
|
|
192
|
-
headers: Headers.merge(this.headers, inject?.headers)
|
|
191
|
+
headers: requestish.Headers.merge(this.headers, inject?.headers)
|
|
193
192
|
});
|
|
194
193
|
return await this.save(token);
|
|
195
194
|
}
|
|
@@ -256,13 +255,11 @@ export class Client extends EventEmitter {
|
|
|
256
255
|
*/
|
|
257
256
|
async request(url, method = 'GET', body, headers = {}, dPoPOptions) {
|
|
258
257
|
try {
|
|
259
|
-
url = URL.from(url);
|
|
258
|
+
url = requestish.URL.from(url);
|
|
260
259
|
}
|
|
261
260
|
catch (error) {
|
|
262
261
|
if (this.base_url || this.credentials.issuer) {
|
|
263
|
-
url =
|
|
264
|
-
// @ts-expect-error 2345 TS, I _just_ tested this!
|
|
265
|
-
URL.toString(this.base_url || this.credentials.issuer), URL.toString(url).replace(/^\/?/, ''));
|
|
262
|
+
url = new URL(url, this.base_url || this.credentials.issuer);
|
|
266
263
|
}
|
|
267
264
|
else {
|
|
268
265
|
throw new Error(`${this.name} request url invalid`, {
|
|
@@ -274,7 +271,7 @@ export class Client extends EventEmitter {
|
|
|
274
271
|
});
|
|
275
272
|
}
|
|
276
273
|
}
|
|
277
|
-
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)));
|
|
278
275
|
try {
|
|
279
276
|
return this.prepareResponse(await request());
|
|
280
277
|
}
|
|
@@ -348,7 +345,7 @@ export class Client extends EventEmitter {
|
|
|
348
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
|
|
349
346
|
*/
|
|
350
347
|
async fetch(input, init, dPoPOptions) {
|
|
351
|
-
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);
|
|
352
349
|
}
|
|
353
350
|
/**
|
|
354
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": {
|