oauth2-cli 1.2.1 → 1.2.4

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 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.4](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.2.3...oauth2-cli/1.2.4) (2026-03-08)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * actually fix base_url completion removing search params ([2575df7](https://github.com/battis/oauth2-cli/commit/2575df7250ec1c5c0ba76ab5f7babc40b2e5a07d))
11
+
12
+ ## [1.2.3](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.2.2...oauth2-cli/1.2.3) (2026-03-08)
13
+
14
+ ## [1.2.2](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.2.1...oauth2-cli/1.2.2) (2026-03-08)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * don't lose search params when building url from base or credentials.issuer ([a328c96](https://github.com/battis/oauth2-cli/commit/a328c9693d0a39cccc7d6f38bd24065b6f633c1b))
20
+
5
21
  ## [1.2.1](https://github.com/battis/oauth2-cli/compare/oauth2-cli/1.2.0...oauth2-cli/1.2.1) (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 { Body, Headers, URL } from 'requestish';
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 { Body, Headers, URL, URLSearchParams } from 'requestish';
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,25 +255,34 @@ 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 = path.join(
264
- // @ts-expect-error 2345 TS, I _just_ tested this!
265
- URL.toString(this.base_url || this.credentials.issuer), URL.toString(url).replace(/^\/?/, ''));
262
+ try {
263
+ url = new URL(url, this.base_url || this.credentials.issuer);
264
+ }
265
+ catch (error) {
266
+ throw new Error(`${this.name} request url invalid`, {
267
+ cause: {
268
+ url,
269
+ base_url: this.base_url,
270
+ issuer: this.credentials.issuer,
271
+ error
272
+ }
273
+ });
274
+ }
266
275
  }
267
276
  else {
268
277
  throw new Error(`${this.name} request url invalid`, {
269
278
  cause: {
270
- base_url: this.base_url,
271
- issuer: this.credentials.issuer,
279
+ url,
272
280
  error
273
281
  }
274
282
  });
275
283
  }
276
284
  }
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)));
285
+ 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
286
  try {
279
287
  return this.prepareResponse(await request());
280
288
  }
@@ -348,7 +356,7 @@ export class Client extends EventEmitter {
348
356
  * @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
357
  */
350
358
  async fetch(input, init, dPoPOptions) {
351
- return await this.request(input, init?.method, await Body.from(init?.body), Headers.from(init?.headers), dPoPOptions);
359
+ return await this.request(input, init?.method, await requestish.Body.from(init?.body), requestish.Headers.from(init?.headers), dPoPOptions);
352
360
  }
353
361
  /**
354
362
  * 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.1",
3
+ "version": "1.2.4",
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
- "gcrtl": "0.1.11",
27
- "requestish": "0.1.10"
26
+ "requestish": "0.1.10",
27
+ "gcrtl": "0.1.11"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@battis/descriptive-types": "^0.2.6",