oauth2-cli 0.1.6 → 0.2.1

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,33 +2,46 @@
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
- ## [0.1.6](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.1.5...oauth2-cli/0.1.6) (2025-03-08)
5
+ ## [0.2.1](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.2.0...oauth2-cli/0.2.1) (2025-09-11)
6
+
7
+
8
+ ### Bug Fixes
6
9
 
10
+ * update dependencies to address transient openid-client config error ([f0ca9a8](https://github.com/battis/oauth2-cli/commit/f0ca9a8d2bb4551b80a49e48aa43df5ba66a5a9b))
11
+
12
+ ## [0.2.0](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.1.6...oauth2-cli/0.2.0) (2025-03-09)
7
13
 
8
14
  ### Features
9
15
 
10
- * **oauth2-cli:** export Credentials type for convenience ([f000b56](https://github.com/battis/oauth2-cli/commit/f000b56a587c021d64a294ff33d42fa3966afd38))
16
+ - **oauth2-cli:** detect and warn about reused localhost ports ([3431d84](https://github.com/battis/oauth2-cli/commit/3431d84d47251dd9fba47b23bbfd3dcf653fc7d3))
11
17
 
12
- ## [0.1.5](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.1.4...oauth2-cli/0.1.5) (2025-03-07)
18
+ ### Bug Fixes
13
19
 
20
+ - **oauth2-configure:** remove redundant caching ([7294e6a](https://github.com/battis/oauth2-cli/commit/7294e6a7aec373f72abc7c9e7c2ce4c659e3cba5))
14
21
 
15
- ### Features
22
+ ## [0.1.6](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.1.5...oauth2-cli/0.1.6) (2025-03-08)
16
23
 
17
- * **oauth2-cli:** attempt to reuse refresh_token if none returned ([8210698](https://github.com/battis/oauth2-cli/commit/82106982e508c1f5f54a16590594daa47f80d57d))
24
+ ### Features
18
25
 
19
- ## [0.1.4](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.1.3...oauth2-cli/0.1.4) (2025-03-06)
26
+ - **oauth2-cli:** export Credentials type for convenience ([f000b56](https://github.com/battis/oauth2-cli/commit/f000b56a587c021d64a294ff33d42fa3966afd38))
20
27
 
28
+ ## [0.1.5](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.1.4...oauth2-cli/0.1.5) (2025-03-07)
21
29
 
22
30
  ### Features
23
31
 
24
- * **oauth2-cli:** cache token in memory ([68ac632](https://github.com/battis/oauth2-cli/commit/68ac6323031cbcaa0dd7b444dcd6da62b4f9a48d))
25
- * **oauth2-cli:** Client.request() and Client.requestJSON() ([50c1198](https://github.com/battis/oauth2-cli/commit/50c11985c0ae8f135932d05bae2bf74ff1cd29df))
26
- * **oauth2-cli:** deprecate TokenManager (replaced by Client) ([991ac42](https://github.com/battis/oauth2-cli/commit/991ac42eb2cc83b4b31e60856faf192233cd35f3))
32
+ - **oauth2-cli:** attempt to reuse refresh_token if none returned ([8210698](https://github.com/battis/oauth2-cli/commit/82106982e508c1f5f54a16590594daa47f80d57d))
33
+
34
+ ## [0.1.4](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.1.3...oauth2-cli/0.1.4) (2025-03-06)
35
+
36
+ ### Features
27
37
 
38
+ - **oauth2-cli:** cache token in memory ([68ac632](https://github.com/battis/oauth2-cli/commit/68ac6323031cbcaa0dd7b444dcd6da62b4f9a48d))
39
+ - **oauth2-cli:** Client.request() and Client.requestJSON() ([50c1198](https://github.com/battis/oauth2-cli/commit/50c11985c0ae8f135932d05bae2bf74ff1cd29df))
40
+ - **oauth2-cli:** deprecate TokenManager (replaced by Client) ([991ac42](https://github.com/battis/oauth2-cli/commit/991ac42eb2cc83b4b31e60856faf192233cd35f3))
28
41
 
29
42
  ### Bug Fixes
30
43
 
31
- * **oauth2-cli:** improve error window title ([97a4c1c](https://github.com/battis/oauth2-cli/commit/97a4c1c9f98aaacf7ce63fb05a64cfee5f4dd0ce))
44
+ - **oauth2-cli:** improve error window title ([97a4c1c](https://github.com/battis/oauth2-cli/commit/97a4c1c9f98aaacf7ce63fb05a64cfee5f4dd0ce))
32
45
 
33
46
  ## [0.1.3](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.1.2...oauth2-cli/0.1.3) (2025-03-06)
34
47
 
package/dist/Localhost.js CHANGED
@@ -4,6 +4,8 @@ import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import open from 'open';
6
6
  import * as OpenIDClient from 'openid-client';
7
+ const ejs = await import('ejs');
8
+ const portRegistry = [];
7
9
  export async function redirectServer(options) {
8
10
  const { authorization_url, redirect_uri, code_verifier, state, headers, resolve, reject, views = '../views' } = options;
9
11
  const redirectUrl = new URL(redirect_uri);
@@ -11,10 +13,31 @@ export async function redirectServer(options) {
11
13
  const app = express();
12
14
  const port = redirectUrl.port !== '' ? redirectUrl.port : 80;
13
15
  const server = app.listen(port);
14
- const ejs = await import('ejs');
15
16
  let view = 'complete.ejs';
16
17
  let tokens = undefined;
17
18
  let error = undefined;
19
+ /*
20
+ * FIXME Multiple clients with `redirect_uri` on the same localhost port
21
+ * This seems to be some sort of an issue with Express (or node http?) in
22
+ * which, despite a fresh invocation of express() for each redirect
23
+ * listener, every listener subsequent to the first _on the same port_
24
+ * retains the original routing stack of the first listener on that port.
25
+ * I have tried:
26
+ * - Setting a manual delay (up to 10 seconds) between the receipt of
27
+ * the token and resolving it to allow the server to close.
28
+ * - Using a mutex semaphore to ensure that no two instances of
29
+ * Localhost are running simultaneously
30
+ * - Separating the routing into a separate Router middleware
31
+ * - Manually removing the routing stack (which does, at least, break
32
+ * the routing of the subsequent instances, supporting the idea that
33
+ * the app is getting reused by Express)
34
+ */
35
+ if (portRegistry.includes(port)) {
36
+ throw new Error(`Multiple OAuth clients are attempting to redirect to port ${port}. This will result in failure. Please reconfigure your credentials so that each client is redirecting to a distinct port on http://localhost (e.g. 3000, 3001, 3002)`);
37
+ }
38
+ else {
39
+ portRegistry.push(port);
40
+ }
18
41
  app.get('/authorize', async (req, res) => {
19
42
  const viewPath = path.resolve(import.meta.dirname, views, 'authorize');
20
43
  if (ejs && fs.existsSync(viewPath)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oauth2-cli",
3
- "version": "0.1.6",
3
+ "version": "0.2.1",
4
4
  "description": "Acquire API access tokens via OAuth 2.0 within CLI tools",
5
5
  "homepage": "https://github.com/battis/oauth2-cli/tree/main/packages/oauth2-cli#readme",
6
6
  "repository": {
@@ -18,18 +18,18 @@
18
18
  "dependencies": {
19
19
  "async-mutex": "^0.5.0",
20
20
  "express": "^4.21.2",
21
- "open": "^10.1.0",
22
- "openid-client": "^6.3.3",
23
- "@battis/oauth2-configure": "0.1.1"
21
+ "open": "^10.2.0",
22
+ "openid-client": "^6.8.0",
23
+ "@battis/oauth2-configure": "0.1.3"
24
24
  },
25
25
  "devDependencies": {
26
- "@tsconfig/node20": "^20.1.4",
26
+ "@tsconfig/node20": "^20.1.6",
27
27
  "@types/ejs": "^3.1.5",
28
- "@types/express": "^5.0.0",
29
- "commit-and-tag-version": "^12.5.0",
28
+ "@types/express": "^5.0.3",
29
+ "commit-and-tag-version": "^12.6.0",
30
30
  "del-cli": "^6.0.0",
31
31
  "npm-run-all": "^4.1.5",
32
- "typescript": "^5.8.2"
32
+ "typescript": "^5.9.2"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "ejs": "*"
package/src/Localhost.ts CHANGED
@@ -5,6 +5,10 @@ import path from 'node:path';
5
5
  import open from 'open';
6
6
  import * as OpenIDClient from 'openid-client';
7
7
 
8
+ const ejs = await import('ejs');
9
+
10
+ const portRegistry: (number | string)[] = [];
11
+
8
12
  type Options = Configuration.Options & {
9
13
  authorization_url: string;
10
14
  redirect_uri: string;
@@ -34,11 +38,34 @@ export async function redirectServer(options: Options) {
34
38
  const app = express();
35
39
  const port = redirectUrl.port !== '' ? redirectUrl.port : 80;
36
40
  const server = app.listen(port);
37
- const ejs = await import('ejs');
38
41
  let view = 'complete.ejs';
39
42
  let tokens: OpenIDClient.TokenEndpointResponse | undefined = undefined;
40
43
  let error: unknown = undefined;
41
44
 
45
+ /*
46
+ * FIXME Multiple clients with `redirect_uri` on the same localhost port
47
+ * This seems to be some sort of an issue with Express (or node http?) in
48
+ * which, despite a fresh invocation of express() for each redirect
49
+ * listener, every listener subsequent to the first _on the same port_
50
+ * retains the original routing stack of the first listener on that port.
51
+ * I have tried:
52
+ * - Setting a manual delay (up to 10 seconds) between the receipt of
53
+ * the token and resolving it to allow the server to close.
54
+ * - Using a mutex semaphore to ensure that no two instances of
55
+ * Localhost are running simultaneously
56
+ * - Separating the routing into a separate Router middleware
57
+ * - Manually removing the routing stack (which does, at least, break
58
+ * the routing of the subsequent instances, supporting the idea that
59
+ * the app is getting reused by Express)
60
+ */
61
+ if (portRegistry.includes(port)) {
62
+ throw new Error(
63
+ `Multiple OAuth clients are attempting to redirect to port ${port}. This will result in failure. Please reconfigure your credentials so that each client is redirecting to a distinct port on http://localhost (e.g. 3000, 3001, 3002)`
64
+ );
65
+ } else {
66
+ portRegistry.push(port);
67
+ }
68
+
42
69
  app.get('/authorize', async (req, res) => {
43
70
  const viewPath = path.resolve(import.meta.dirname, views, 'authorize');
44
71
  if (ejs && fs.existsSync(viewPath)) {