oauth2-cli 0.1.6 → 0.2.0

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,39 @@
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.0](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.1.6...oauth2-cli/0.2.0) (2025-03-09)
6
+
7
+ ### Features
8
+
9
+ - **oauth2-cli:** detect and warn about reused localhost ports ([3431d84](https://github.com/battis/oauth2-cli/commit/3431d84d47251dd9fba47b23bbfd3dcf653fc7d3))
10
+
11
+ ### Bug Fixes
6
12
 
13
+ - **oauth2-configure:** remove redundant caching ([7294e6a](https://github.com/battis/oauth2-cli/commit/7294e6a7aec373f72abc7c9e7c2ce4c659e3cba5))
14
+
15
+ ## [0.1.6](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.1.5...oauth2-cli/0.1.6) (2025-03-08)
7
16
 
8
17
  ### Features
9
18
 
10
- * **oauth2-cli:** export Credentials type for convenience ([f000b56](https://github.com/battis/oauth2-cli/commit/f000b56a587c021d64a294ff33d42fa3966afd38))
19
+ - **oauth2-cli:** export Credentials type for convenience ([f000b56](https://github.com/battis/oauth2-cli/commit/f000b56a587c021d64a294ff33d42fa3966afd38))
11
20
 
12
21
  ## [0.1.5](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.1.4...oauth2-cli/0.1.5) (2025-03-07)
13
22
 
14
-
15
23
  ### Features
16
24
 
17
- * **oauth2-cli:** attempt to reuse refresh_token if none returned ([8210698](https://github.com/battis/oauth2-cli/commit/82106982e508c1f5f54a16590594daa47f80d57d))
25
+ - **oauth2-cli:** attempt to reuse refresh_token if none returned ([8210698](https://github.com/battis/oauth2-cli/commit/82106982e508c1f5f54a16590594daa47f80d57d))
18
26
 
19
27
  ## [0.1.4](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.1.3...oauth2-cli/0.1.4) (2025-03-06)
20
28
 
21
-
22
29
  ### Features
23
30
 
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))
27
-
31
+ - **oauth2-cli:** cache token in memory ([68ac632](https://github.com/battis/oauth2-cli/commit/68ac6323031cbcaa0dd7b444dcd6da62b4f9a48d))
32
+ - **oauth2-cli:** Client.request() and Client.requestJSON() ([50c1198](https://github.com/battis/oauth2-cli/commit/50c11985c0ae8f135932d05bae2bf74ff1cd29df))
33
+ - **oauth2-cli:** deprecate TokenManager (replaced by Client) ([991ac42](https://github.com/battis/oauth2-cli/commit/991ac42eb2cc83b4b31e60856faf192233cd35f3))
28
34
 
29
35
  ### Bug Fixes
30
36
 
31
- * **oauth2-cli:** improve error window title ([97a4c1c](https://github.com/battis/oauth2-cli/commit/97a4c1c9f98aaacf7ce63fb05a64cfee5f4dd0ce))
37
+ - **oauth2-cli:** improve error window title ([97a4c1c](https://github.com/battis/oauth2-cli/commit/97a4c1c9f98aaacf7ce63fb05a64cfee5f4dd0ce))
32
38
 
33
39
  ## [0.1.3](https://github.com/battis/oauth2-cli/compare/oauth2-cli/0.1.2...oauth2-cli/0.1.3) (2025-03-06)
34
40
 
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.0",
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": {
@@ -20,7 +20,7 @@
20
20
  "express": "^4.21.2",
21
21
  "open": "^10.1.0",
22
22
  "openid-client": "^6.3.3",
23
- "@battis/oauth2-configure": "0.1.1"
23
+ "@battis/oauth2-configure": "0.1.2"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@tsconfig/node20": "^20.1.4",
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)) {