oauth2-cli 0.5.0 → 0.6.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 +29 -0
- package/README.md +87 -1
- package/dist/Client.d.ts +111 -45
- package/dist/Client.js +175 -112
- package/dist/Credentials.d.ts +29 -0
- package/dist/Errors/BadResponse.d.ts +3 -0
- package/dist/Errors/BadResponse.js +7 -0
- package/dist/Errors/IndeterminateConfiguration.d.ts +3 -0
- package/dist/Errors/IndeterminateConfiguration.js +5 -0
- package/dist/Errors/MissingAccessToken.d.ts +3 -0
- package/dist/Errors/MissingAccessToken.js +5 -0
- package/dist/Errors/PortCollision.d.ts +3 -0
- package/dist/Errors/PortCollision.js +5 -0
- package/dist/Errors/index.d.ts +4 -0
- package/dist/Errors/index.js +4 -0
- package/dist/Request/Body.d.ts +3 -0
- package/dist/Request/Body.js +19 -0
- package/dist/Request/Headers.d.ts +3 -0
- package/dist/Request/Headers.js +20 -0
- package/dist/Request/Injection.d.ts +23 -0
- package/dist/Request/Injection.js +1 -0
- package/dist/Request/Scope.d.ts +2 -0
- package/dist/Request/Scope.js +6 -0
- package/dist/Request/URL.d.ts +4 -0
- package/dist/Request/URL.js +12 -0
- package/dist/Request/URLSearchParams.d.ts +6 -0
- package/dist/Request/URLSearchParams.js +37 -0
- package/dist/Request/index.d.ts +6 -0
- package/dist/Request/index.js +6 -0
- package/dist/Session.d.ts +47 -0
- package/dist/Session.js +77 -0
- package/dist/{FileStorage.d.ts → Token/FileStorage.d.ts} +2 -3
- package/dist/{FileStorage.js → Token/FileStorage.js} +3 -4
- package/dist/Token/Response.d.ts +2 -0
- package/dist/Token/Response.js +1 -0
- package/dist/Token/TokenStorage.d.ts +4 -0
- package/dist/Token/TokenStorage.js +1 -0
- package/dist/Token/addHelpers.d.ts +8 -0
- package/dist/Token/addHelpers.js +44 -0
- package/dist/Token/index.d.ts +3 -0
- package/dist/Token/index.js +3 -0
- package/dist/WebServer.d.ts +64 -0
- package/dist/WebServer.js +116 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -3
- package/package.json +12 -8
- package/dist/Localhost.d.ts +0 -14
- package/dist/Localhost.js +0 -88
- package/dist/Token.d.ts +0 -18
- package/dist/Token.js +0 -26
- package/dist/TokenStorage.d.ts +0 -5
- /package/dist/{TokenStorage.js → Credentials.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './Client.js';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
2
|
+
export * as Credentials from './Credentials.js';
|
|
3
|
+
export * as Errors from './Errors/index.js';
|
|
4
|
+
export * as Request from './Request/index.js';
|
|
5
|
+
export * as Token from './Token/index.js';
|
|
6
|
+
export * from './WebServer.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './Client.js';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
2
|
+
export * as Credentials from './Credentials.js';
|
|
3
|
+
export * as Errors from './Errors/index.js';
|
|
4
|
+
export * as Request from './Request/index.js';
|
|
5
|
+
export * as Token from './Token/index.js';
|
|
6
|
+
export * from './WebServer.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oauth2-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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": {
|
|
@@ -16,19 +16,23 @@
|
|
|
16
16
|
"main": "./dist/index.js",
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"@qui-cli/colors": "^3.2.3",
|
|
19
20
|
"async-mutex": "^0.5.0",
|
|
20
21
|
"express": "^5.2.1",
|
|
22
|
+
"gcrtl": "^0.1.6",
|
|
23
|
+
"oauth4webapi": "^3.8.4",
|
|
21
24
|
"open": "^11.0.0",
|
|
22
|
-
"openid-client": "^6.8.
|
|
23
|
-
"
|
|
25
|
+
"openid-client": "^6.8.2",
|
|
26
|
+
"ora": "^9.3.0"
|
|
24
27
|
},
|
|
25
28
|
"devDependencies": {
|
|
26
|
-
"@battis/
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
+
"@battis/descriptive-types": "^0.2.6",
|
|
30
|
+
"@battis/typescript-tricks": "^0.7.7",
|
|
31
|
+
"@tsconfig/node24": "^24.0.4",
|
|
29
32
|
"@types/express": "^5.0.6",
|
|
33
|
+
"@types/node": "^24.10.13",
|
|
30
34
|
"commit-and-tag-version": "^12.6.1",
|
|
31
|
-
"del-cli": "^
|
|
35
|
+
"del-cli": "^7.0.0",
|
|
32
36
|
"npm-run-all": "^4.1.5",
|
|
33
37
|
"typescript": "^5.9.3"
|
|
34
38
|
},
|
|
@@ -49,6 +53,6 @@
|
|
|
49
53
|
"build": "run-s build:*",
|
|
50
54
|
"build:clean": "run-s clean",
|
|
51
55
|
"build:compile": "tsc",
|
|
52
|
-
"
|
|
56
|
+
"version": "commit-and-tag-version"
|
|
53
57
|
}
|
|
54
58
|
}
|
package/dist/Localhost.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as Configuration from '@battis/oauth2-configure';
|
|
2
|
-
import * as OpenIDClient from 'openid-client';
|
|
3
|
-
type Options = Configuration.Options & {
|
|
4
|
-
authorization_url: string;
|
|
5
|
-
redirect_uri: string;
|
|
6
|
-
headers?: Record<string, string>;
|
|
7
|
-
code_verifier?: string;
|
|
8
|
-
state?: string;
|
|
9
|
-
resolve: (tokens?: OpenIDClient.TokenEndpointResponse) => void;
|
|
10
|
-
reject: (error: unknown) => void;
|
|
11
|
-
views?: string;
|
|
12
|
-
};
|
|
13
|
-
export declare function redirectServer(options: Options): Promise<void>;
|
|
14
|
-
export {};
|
package/dist/Localhost.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import * as Configuration from '@battis/oauth2-configure';
|
|
2
|
-
import express from 'express';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import open from 'open';
|
|
6
|
-
import * as OpenIDClient from 'openid-client';
|
|
7
|
-
const ejs = await import('ejs');
|
|
8
|
-
const portRegistry = [];
|
|
9
|
-
export async function redirectServer(options) {
|
|
10
|
-
const { authorization_url, redirect_uri, code_verifier, state, headers, resolve, reject, views = '../views' } = options;
|
|
11
|
-
const redirectUrl = new URL(redirect_uri);
|
|
12
|
-
const configuration = await Configuration.acquire(options);
|
|
13
|
-
const app = express();
|
|
14
|
-
const port = redirectUrl.port !== '' ? redirectUrl.port : 80;
|
|
15
|
-
const server = app.listen(port);
|
|
16
|
-
let view = 'complete.ejs';
|
|
17
|
-
let tokens = undefined;
|
|
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
|
-
}
|
|
41
|
-
app.get('/authorize', async (req, res) => {
|
|
42
|
-
const viewPath = path.resolve(import.meta.dirname, views, 'authorize');
|
|
43
|
-
if (ejs && fs.existsSync(viewPath)) {
|
|
44
|
-
res.send(await ejs.renderFile(viewPath));
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
res.redirect(authorization_url);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
app.get(redirectUrl.pathname, async (req, res) => {
|
|
51
|
-
try {
|
|
52
|
-
const currentUrl = new URL(req.originalUrl, redirect_uri);
|
|
53
|
-
tokens = await OpenIDClient.authorizationCodeGrant(configuration, currentUrl, {
|
|
54
|
-
pkceCodeVerifier: code_verifier,
|
|
55
|
-
expectedState: state
|
|
56
|
-
},
|
|
57
|
-
// @ts-expect-error 2322 undocumented arg pass-through to oauth4webapi
|
|
58
|
-
{ headers });
|
|
59
|
-
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
error = e;
|
|
62
|
-
view = 'error.ejs';
|
|
63
|
-
}
|
|
64
|
-
if (!tokens && !error) {
|
|
65
|
-
error = 'No tokens received in response to authorization code';
|
|
66
|
-
}
|
|
67
|
-
if (ejs) {
|
|
68
|
-
res.send(await ejs.renderFile(path.resolve(import.meta.dirname, views, view), {
|
|
69
|
-
tokens,
|
|
70
|
-
error
|
|
71
|
-
}));
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
res.send(error || 'You may close this window.');
|
|
75
|
-
}
|
|
76
|
-
server.close();
|
|
77
|
-
if (error) {
|
|
78
|
-
reject(error);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
resolve(tokens);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
app.get('*path', (_, res) => {
|
|
85
|
-
res.status(404).send();
|
|
86
|
-
});
|
|
87
|
-
open(`http://localhost:${port}/authorize`);
|
|
88
|
-
}
|
package/dist/Token.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as OpenIDClient from 'openid-client';
|
|
2
|
-
interface TokenResponse extends OpenIDClient.TokenEndpointResponse {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
}
|
|
5
|
-
export declare class Token implements TokenResponse {
|
|
6
|
-
readonly access_token: string;
|
|
7
|
-
readonly token_type: Lowercase<string>;
|
|
8
|
-
readonly timestamp?: any;
|
|
9
|
-
readonly refresh_token?: string;
|
|
10
|
-
readonly refresh_token_expires_in?: number;
|
|
11
|
-
readonly scope?: string;
|
|
12
|
-
readonly id_token?: string;
|
|
13
|
-
readonly expires_in?: number;
|
|
14
|
-
private constructor();
|
|
15
|
-
static fromResponse(response?: OpenIDClient.TokenEndpointResponse, refresh_token?: string): Token | undefined;
|
|
16
|
-
hasExpired(): boolean;
|
|
17
|
-
}
|
|
18
|
-
export {};
|
package/dist/Token.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export class Token {
|
|
2
|
-
access_token;
|
|
3
|
-
token_type;
|
|
4
|
-
timestamp;
|
|
5
|
-
refresh_token;
|
|
6
|
-
refresh_token_expires_in;
|
|
7
|
-
scope;
|
|
8
|
-
id_token;
|
|
9
|
-
expires_in;
|
|
10
|
-
constructor(response) {
|
|
11
|
-
this.access_token = response.access_token;
|
|
12
|
-
this.token_type = response.token_type;
|
|
13
|
-
this.timestamp = response.timestamp;
|
|
14
|
-
Object.assign(this, response);
|
|
15
|
-
}
|
|
16
|
-
static fromResponse(response, refresh_token) {
|
|
17
|
-
if (response) {
|
|
18
|
-
return new Token({ refresh_token, timestamp: Date.now(), ...response });
|
|
19
|
-
}
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
hasExpired() {
|
|
23
|
-
return (this.expires_in === undefined ||
|
|
24
|
-
Date.now() > this.timestamp + this.expires_in);
|
|
25
|
-
}
|
|
26
|
-
}
|
package/dist/TokenStorage.d.ts
DELETED
|
File without changes
|