@flipstream/sdk 0.4.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 +42 -0
- package/README.md +325 -20
- package/dist/auth/discovery.d.ts +2 -0
- package/dist/auth/discovery.js +4 -1
- package/dist/auth/discovery.js.map +1 -1
- package/dist/auth/signIn.d.ts +11 -2
- package/dist/auth/signIn.js +19 -27
- package/dist/auth/signIn.js.map +1 -1
- package/dist/auth/tokenEndpoint.d.ts +18 -0
- package/dist/auth/tokenEndpoint.js +36 -0
- package/dist/auth/tokenEndpoint.js.map +1 -0
- package/dist/core/fetch.d.ts +8 -0
- package/dist/core/fetch.js +36 -11
- package/dist/core/fetch.js.map +1 -1
- package/dist/core/result.d.ts +4 -2
- package/dist/core/result.js +3 -1
- package/dist/core/result.js.map +1 -1
- package/dist/flipstream.d.ts +7 -0
- package/dist/flipstream.js +14 -4
- package/dist/flipstream.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/node/clientSecret.d.ts +41 -0
- package/dist/node/clientSecret.js +124 -0
- package/dist/node/clientSecret.js.map +1 -0
- package/dist/node/fileLock.d.ts +27 -0
- package/dist/node/fileLock.js +267 -0
- package/dist/node/fileLock.js.map +1 -0
- package/dist/node/fileStore.d.ts +19 -0
- package/dist/node/fileStore.js +135 -0
- package/dist/node/fileStore.js.map +1 -0
- package/dist/node/headless.d.ts +7 -2
- package/dist/node/headless.js +15 -2
- package/dist/node/headless.js.map +1 -1
- package/dist/node/index.d.ts +9 -0
- package/dist/node/index.js +9 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/keychainChild.d.ts +1 -0
- package/dist/node/keychainChild.js +100 -0
- package/dist/node/keychainChild.js.map +1 -0
- package/dist/node/keychainStore.d.ts +30 -0
- package/dist/node/keychainStore.js +150 -0
- package/dist/node/keychainStore.js.map +1 -0
- package/dist/node/loopback.d.ts +24 -5
- package/dist/node/loopback.js +80 -23
- package/dist/node/loopback.js.map +1 -1
- package/dist/node/session.d.ts +224 -0
- package/dist/node/session.js +622 -0
- package/dist/node/session.js.map +1 -0
- package/dist/node/store.d.ts +44 -0
- package/dist/node/store.js +91 -0
- package/dist/node/store.js.map +1 -0
- package/dist/query/health.d.ts +16 -0
- package/dist/query/health.js +18 -0
- package/dist/query/health.js.map +1 -0
- package/dist/query/query.d.ts +8 -0
- package/dist/query/query.js +12 -0
- package/dist/query/query.js.map +1 -1
- package/dist/version.gen.d.ts +2 -0
- package/dist/version.gen.js +4 -0
- package/dist/version.gen.js.map +1 -0
- package/package.json +18 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keychainChild.js","sourceRoot":"","sources":["../../src/node/keychainChild.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,wDAAwD;AACxD,MAAM,QAAQ,GAAG,CAAC,CAAC,kBAAkB,CAAC,IAAI,EAAE;IAC1C,CAAC,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IAClF,CAAC,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IACrF,CAAC,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CA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O,CAAC,CAAC,CAAA;AACrH,qGAAqG;AACrG,iGAAiG;AACjG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type TokenStore } from './store.js';
|
|
2
|
+
export interface KeychainStoreOptions {
|
|
3
|
+
/** The item's service: your app's own name, such as `io.example.cli`. */
|
|
4
|
+
readonly service: string;
|
|
5
|
+
/** The item's account, such as the issuer the tokens are for. */
|
|
6
|
+
readonly account: string;
|
|
7
|
+
/**
|
|
8
|
+
* How long one step may take before it is ended, as `store_failed`: 30 s unless you say. A
|
|
9
|
+
* keychain prompt that a person must answer may need longer. Through `session.token()`, a read
|
|
10
|
+
* longer than the caller's 15 s wait is `unavailable`: a longer limit helps the app's own
|
|
11
|
+
* `tokens`, `save` and `clear`, and a refresh, which goes on after the caller's wait.
|
|
12
|
+
*/
|
|
13
|
+
readonly timeoutMs?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The tokens in the system's own credential store, for a CLI or a tool on the person's own machine:
|
|
17
|
+
* the macOS keychain, Windows' Credential Manager, or the Secret Service on Linux (GNOME Keyring,
|
|
18
|
+
* KWallet). One item (`service`, `account`) holds them; a save is one write, seen whole once it has
|
|
19
|
+
* succeeded, or not at all.
|
|
20
|
+
*
|
|
21
|
+
* - **It needs `@napi-rs/keyring`** (`npm install @napi-rs/keyring`), which nothing else in the
|
|
22
|
+
* SDK uses. Without it, every step fails as `store_failed`, and says so.
|
|
23
|
+
* - **Linux without a Secret Service** (a server, a container) fails as `store_failed`: use
|
|
24
|
+
* `fileStore` there.
|
|
25
|
+
* - **Each step runs in a process of its own,** ended after `timeoutMs` (30 s). It is
|
|
26
|
+
* `process.execPath`, so it needs a Node that runs a script: not an Electron app (without
|
|
27
|
+
* `ELECTRON_RUN_AS_NODE`), a Node single-executable application, or a compiled Bun binary.
|
|
28
|
+
* - **Tokens over 2,560 bytes** fail the save, with nothing written.
|
|
29
|
+
*/
|
|
30
|
+
export declare function keychainStore(options: KeychainStoreOptions): TokenStore;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { parse, storeOf } from './store.js';
|
|
6
|
+
/*
|
|
7
|
+
* Through `@napi-rs/keyring` (D481), an optional peer dependency that only this store needs, in a
|
|
8
|
+
* child process for each step that is killed at the step's deadline (D485): a keychain call that
|
|
9
|
+
* parks forever (cli#119) can't be ended in this process, not even by exiting it. The tokens go to
|
|
10
|
+
* the child on its standard input, never as an argument or in its environment.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* The child script beside this module, found when a step runs, never when the module loads: where
|
|
14
|
+
* import.meta.url is empty (an esbuild CommonJS bundle, say), only the keychain's steps fail, and
|
|
15
|
+
* the rest of this entry still loads.
|
|
16
|
+
*/
|
|
17
|
+
function childScript() {
|
|
18
|
+
try {
|
|
19
|
+
return fileURLToPath(new URL('./keychainChild.js', import.meta.url));
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const TIMEOUT_MS = 30_000;
|
|
26
|
+
// setTimeout's ceiling: a longer delay is cut to 1 ms, which would end every step at once.
|
|
27
|
+
const MAX_TIMEOUT_MS = 2_147_483_647;
|
|
28
|
+
/**
|
|
29
|
+
* The most a saved secret may hold, on every platform: Windows' Credential Manager keeps at most
|
|
30
|
+
* 2,560 bytes (CRED_MAX_CREDENTIAL_BLOB_SIZE). The macOS keychain and the Secret Service set no
|
|
31
|
+
* lower limit, and one limit everywhere means tokens that save on one platform save on all.
|
|
32
|
+
*/
|
|
33
|
+
const LIMIT_BYTES = 2_560;
|
|
34
|
+
/**
|
|
35
|
+
* The tokens in the system's own credential store, for a CLI or a tool on the person's own machine:
|
|
36
|
+
* the macOS keychain, Windows' Credential Manager, or the Secret Service on Linux (GNOME Keyring,
|
|
37
|
+
* KWallet). One item (`service`, `account`) holds them; a save is one write, seen whole once it has
|
|
38
|
+
* succeeded, or not at all.
|
|
39
|
+
*
|
|
40
|
+
* - **It needs `@napi-rs/keyring`** (`npm install @napi-rs/keyring`), which nothing else in the
|
|
41
|
+
* SDK uses. Without it, every step fails as `store_failed`, and says so.
|
|
42
|
+
* - **Linux without a Secret Service** (a server, a container) fails as `store_failed`: use
|
|
43
|
+
* `fileStore` there.
|
|
44
|
+
* - **Each step runs in a process of its own,** ended after `timeoutMs` (30 s). It is
|
|
45
|
+
* `process.execPath`, so it needs a Node that runs a script: not an Electron app (without
|
|
46
|
+
* `ELECTRON_RUN_AS_NODE`), a Node single-executable application, or a compiled Bun binary.
|
|
47
|
+
* - **Tokens over 2,560 bytes** fail the save, with nothing written.
|
|
48
|
+
*/
|
|
49
|
+
export function keychainStore(options) {
|
|
50
|
+
const { service, account, timeoutMs = TIMEOUT_MS } = options;
|
|
51
|
+
if (service === '' || account === '')
|
|
52
|
+
throw new TypeError('the keychain store needs a service and an account');
|
|
53
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > MAX_TIMEOUT_MS)
|
|
54
|
+
throw new TypeError(`timeoutMs must be a whole number of ms, from 1 to ${MAX_TIMEOUT_MS}`);
|
|
55
|
+
const item = { service, account };
|
|
56
|
+
return storeOf(`keychain:${JSON.stringify([service, account])}`, async () => {
|
|
57
|
+
const saved = await inChild({ op: 'get', ...item }, timeoutMs);
|
|
58
|
+
return saved === null ? null : parse(saved);
|
|
59
|
+
}, async (tokens) => {
|
|
60
|
+
if (tokens === null) {
|
|
61
|
+
await inChild({ op: 'delete', ...item }, timeoutMs);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const secret = JSON.stringify(tokens);
|
|
65
|
+
if (Buffer.byteLength(secret, 'utf8') > LIMIT_BYTES)
|
|
66
|
+
throw new Error(`the tokens are too long for the keychain store (over ${LIMIT_BYTES} bytes): nothing was saved`);
|
|
67
|
+
await inChild({ op: 'set', ...item, secret }, timeoutMs);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const STEP = { get: 'read', set: 'save', delete: 'delete' };
|
|
71
|
+
const zAnswer = z.union([
|
|
72
|
+
z.strictObject({ ok: z.literal(true), value: z.string().nullable() }),
|
|
73
|
+
z.strictObject({ ok: z.literal(false), error: z.string(), missing: z.literal(true).exactOptional() }),
|
|
74
|
+
]);
|
|
75
|
+
/**
|
|
76
|
+
* One step in the child: the saved secret (`get`), or null, for none or for a step that saves
|
|
77
|
+
* nothing back. A child that can't start, dies, or answers anything else has said nothing about the
|
|
78
|
+
* keychain, so each of those throws: never null, which would read as nobody signed in.
|
|
79
|
+
*/
|
|
80
|
+
function inChild(request, timeoutMs) {
|
|
81
|
+
const script = childScript();
|
|
82
|
+
if (script === undefined)
|
|
83
|
+
return Promise.reject(new Error("the keychain store can't find its child script, keychainChild.js: this module's import.meta.url is empty, as a CommonJS bundle may leave it"));
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
let settled = false;
|
|
86
|
+
const settle = (finish) => {
|
|
87
|
+
if (settled)
|
|
88
|
+
return;
|
|
89
|
+
settled = true;
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
finish();
|
|
92
|
+
};
|
|
93
|
+
// The answer comes on a pipe of its own (fd 3), apart from anything else printed to stdout.
|
|
94
|
+
const child = spawn(process.execPath, [script], { stdio: ['pipe', 'ignore', 'ignore', 'pipe'], windowsHide: true });
|
|
95
|
+
const [stdin, , , answers] = child.stdio;
|
|
96
|
+
// SIGKILL: a process stuck in the kernel runs no handler.
|
|
97
|
+
const timer = setTimeout(() => {
|
|
98
|
+
child.kill('SIGKILL');
|
|
99
|
+
settle(() => {
|
|
100
|
+
reject(new Error(`the keychain didn't answer within ${timeoutMs / 1000} s`));
|
|
101
|
+
});
|
|
102
|
+
}, timeoutMs);
|
|
103
|
+
child.on('error', (error) => {
|
|
104
|
+
settle(() => {
|
|
105
|
+
reject(new Error("the keychain step couldn't start", { cause: error }));
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
if (stdin === null || !(answers instanceof Readable)) {
|
|
109
|
+
child.kill('SIGKILL');
|
|
110
|
+
settle(() => {
|
|
111
|
+
reject(new Error("the keychain step's pipes didn't open"));
|
|
112
|
+
});
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// A child that died early closes the pipe under the write; the close below reports it.
|
|
116
|
+
stdin.on('error', () => undefined);
|
|
117
|
+
// One line, and the pipe then stays open as the child's heartbeat until it exits.
|
|
118
|
+
stdin.write(`${JSON.stringify(request)}\n`);
|
|
119
|
+
let out = '';
|
|
120
|
+
answers.setEncoding('utf8');
|
|
121
|
+
answers.on('data', (chunk) => {
|
|
122
|
+
out += chunk;
|
|
123
|
+
});
|
|
124
|
+
child.on('close', () => {
|
|
125
|
+
settle(() => {
|
|
126
|
+
const answer = answerOf(out);
|
|
127
|
+
if (answer === undefined)
|
|
128
|
+
reject(new Error('the keychain step gave no readable answer'));
|
|
129
|
+
else if (answer.ok)
|
|
130
|
+
resolve(answer.value);
|
|
131
|
+
else if (answer.missing === true)
|
|
132
|
+
reject(new Error('the keychain store needs the optional package @napi-rs/keyring, which is not installed: npm install @napi-rs/keyring'));
|
|
133
|
+
else
|
|
134
|
+
reject(new Error(`the keychain refused the ${STEP[request.op]}: ${answer.error}`));
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function answerOf(out) {
|
|
140
|
+
let parsed;
|
|
141
|
+
try {
|
|
142
|
+
parsed = JSON.parse(out.trim());
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
const answer = zAnswer.safeParse(parsed);
|
|
148
|
+
return answer.success ? answer.data : undefined;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=keychainStore.js.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A;qBACnF,IAAI,MAAM,CAAC,EAAE;oBAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;qBACpC,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI;oBAAE,MAAM,CAAC,IAAI,KAAK,CAAC,sHAAsH,CAAC,CAAC,CAAA;;oBACtK,MAAM,CAAC,IAAI,KAAK,CAAC,4BAA4B,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;YACzF,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,GAAW;IAC3B,IAAI,MAAe,CAAA;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IACxC,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;AACjD,CAAC"}
|
package/dist/node/loopback.d.ts
CHANGED
|
@@ -1,21 +1,34 @@
|
|
|
1
1
|
import { type Server } from 'node:http';
|
|
2
2
|
import { type SignInError, type SignInRequest, type Tokens } from '../auth/signIn.js';
|
|
3
3
|
import type { AuthCallOptions } from '../auth/transport.js';
|
|
4
|
+
import { type PastedRedirect } from './headless.js';
|
|
4
5
|
export interface LoopbackSignInOptions extends Omit<SignInRequest, 'redirectUri'>, AuthCallOptions {
|
|
5
6
|
/**
|
|
6
7
|
* Shows the person where to sign in: opens their browser, or prints the URL. Called once, when
|
|
7
8
|
* the port is open. The SDK opens nothing itself and writes nothing to the terminal.
|
|
8
9
|
*/
|
|
9
10
|
readonly open: (url: string) => void | Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Reads the address the person pastes back when their browser can't reach this machine's port (a
|
|
13
|
+
* remote session), for this same sign-in. Called once, just after `open`; prompting is the app's.
|
|
14
|
+
* Whichever comes first is taken, the port's redirect or the paste, and a paste is checked as
|
|
15
|
+
* `parsePastedRedirect` checks one. `signal` fires once a paste can no longer be taken (the port's
|
|
16
|
+
* redirect came first, or the sign-in ended): stop reading then. A rejection is `paste_failed`.
|
|
17
|
+
*/
|
|
18
|
+
readonly readPasted?: (signal: AbortSignal) => Promise<string>;
|
|
10
19
|
/** The pages the browser shows after the redirect; neutral ones when left out (HTML). */
|
|
11
20
|
readonly page?: {
|
|
12
21
|
readonly signedIn: string;
|
|
13
22
|
readonly failed: string;
|
|
14
23
|
};
|
|
15
|
-
/** How long to wait for the redirect: 5 minutes when left out. */
|
|
24
|
+
/** How long to wait for the redirect, on the port or pasted: 5 minutes when left out. */
|
|
16
25
|
readonly timeoutMs?: number;
|
|
17
26
|
}
|
|
18
27
|
export type LoopbackError = SignInError
|
|
28
|
+
/** The pasted address isn't a URL, or isn't this sign-in's redirect. Nothing was sent. */
|
|
29
|
+
| Extract<PastedRedirect, {
|
|
30
|
+
readonly ok: false;
|
|
31
|
+
}>['error']
|
|
19
32
|
/** The port couldn't be opened. */
|
|
20
33
|
| {
|
|
21
34
|
readonly kind: 'listen_failed';
|
|
@@ -25,6 +38,11 @@ export type LoopbackError = SignInError
|
|
|
25
38
|
| {
|
|
26
39
|
readonly kind: 'open_failed';
|
|
27
40
|
readonly cause: unknown;
|
|
41
|
+
}
|
|
42
|
+
/** `readPasted` rejected before a redirect was taken. */
|
|
43
|
+
| {
|
|
44
|
+
readonly kind: 'paste_failed';
|
|
45
|
+
readonly cause: unknown;
|
|
28
46
|
};
|
|
29
47
|
export type LoopbackResult = {
|
|
30
48
|
readonly ok: true;
|
|
@@ -35,10 +53,11 @@ export type LoopbackResult = {
|
|
|
35
53
|
};
|
|
36
54
|
/**
|
|
37
55
|
* Signs the person in through their browser, with the redirect `http://127.0.0.1:<port>/callback`
|
|
38
|
-
* on a port of the system's choosing, bound to 127.0.0.1 only. The redirect
|
|
39
|
-
* `finishSignIn` checks one (its state first), and its code
|
|
40
|
-
* if it comes within `timeoutMs
|
|
41
|
-
* `timeout`, `aborted`,
|
|
56
|
+
* on a port of the system's choosing, bound to 127.0.0.1 only. The redirect, on the port or pasted
|
|
57
|
+
* (`readPasted`), is checked as `finishSignIn` checks one (its state first), and its code
|
|
58
|
+
* exchanged. The first redirect decides, if it comes within `timeoutMs`, and only its code is ever
|
|
59
|
+
* exchanged; the port is closed on every path: signed in, refused, `timeout`, `aborted`,
|
|
60
|
+
* `open_failed` or `paste_failed`.
|
|
42
61
|
*/
|
|
43
62
|
export declare function signInWithLoopback(options: LoopbackSignInOptions): Promise<LoopbackResult>;
|
|
44
63
|
type Listening = {
|
package/dist/node/loopback.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createServer } from 'node:http';
|
|
2
2
|
import { finishSignIn, startSignIn } from '../auth/signIn.js';
|
|
3
|
+
import { parsePastedRedirect } from './headless.js';
|
|
3
4
|
const WAIT_MS = 300_000;
|
|
4
5
|
const PAGE = (heading, text) => `<!doctype html><html lang="en"><head><meta charset="utf-8"><title>${heading}</title></head>` +
|
|
5
6
|
`<body style="font-family:system-ui,sans-serif;max-width:32rem;margin:4rem auto;padding:0 1rem">` +
|
|
@@ -7,15 +8,17 @@ const PAGE = (heading, text) => `<!doctype html><html lang="en"><head><meta char
|
|
|
7
8
|
// The code is good once, and is then exchanged; still, it leaves the address bar.
|
|
8
9
|
`<script>try{history.replaceState(null,'',location.pathname)}catch(e){}</script></body></html>`;
|
|
9
10
|
const PAGES = { signedIn: PAGE('Signed in', 'You can close this tab.'), failed: PAGE('Sign-in failed', 'Return to the app for details.') };
|
|
11
|
+
const asError = (error) => (error instanceof Error ? error : new Error(String(error)));
|
|
10
12
|
/**
|
|
11
13
|
* Signs the person in through their browser, with the redirect `http://127.0.0.1:<port>/callback`
|
|
12
|
-
* on a port of the system's choosing, bound to 127.0.0.1 only. The redirect
|
|
13
|
-
* `finishSignIn` checks one (its state first), and its code
|
|
14
|
-
* if it comes within `timeoutMs
|
|
15
|
-
* `timeout`, `aborted`,
|
|
14
|
+
* on a port of the system's choosing, bound to 127.0.0.1 only. The redirect, on the port or pasted
|
|
15
|
+
* (`readPasted`), is checked as `finishSignIn` checks one (its state first), and its code
|
|
16
|
+
* exchanged. The first redirect decides, if it comes within `timeoutMs`, and only its code is ever
|
|
17
|
+
* exchanged; the port is closed on every path: signed in, refused, `timeout`, `aborted`,
|
|
18
|
+
* `open_failed` or `paste_failed`.
|
|
16
19
|
*/
|
|
17
20
|
export async function signInWithLoopback(options) {
|
|
18
|
-
const { signal } = options;
|
|
21
|
+
const { signal, readPasted } = options;
|
|
19
22
|
// A function, so each look reads the signal as it is now, past the awaits between them.
|
|
20
23
|
const aborted = () => signal?.aborted === true;
|
|
21
24
|
if (aborted())
|
|
@@ -26,20 +29,53 @@ export async function signInWithLoopback(options) {
|
|
|
26
29
|
return { ok: false, error: { kind: 'listen_failed', cause: listening.cause } };
|
|
27
30
|
const { server, close } = listening;
|
|
28
31
|
const redirectUri = `http://127.0.0.1:${String(listening.port)}/callback`;
|
|
32
|
+
// The reader's signal: it fires once a paste can no longer be taken.
|
|
33
|
+
const reading = new AbortController();
|
|
29
34
|
let timer;
|
|
30
35
|
let onAbort;
|
|
31
|
-
const redirect = { taken: false };
|
|
32
36
|
try {
|
|
33
37
|
const { url, pending } = await startSignIn({ server: options.server, clientId: options.clientId, scopes: options.scopes, redirectUri });
|
|
34
38
|
// An abort while the port opened, or the URL was made, fired no event this could still hear.
|
|
35
39
|
if (aborted())
|
|
36
40
|
return { ok: false, error: { kind: 'aborted' } };
|
|
37
|
-
|
|
41
|
+
return await new Promise((resolve, reject) => {
|
|
42
|
+
/*
|
|
43
|
+
* One phase, so the sign-in ends once and one code is exchanged (D446). `listening`: no
|
|
44
|
+
* redirect yet; the timeout, a failing opener or reader, or a refused paste ends the wait.
|
|
45
|
+
* `exchanging`: one redirect was taken, and only its exchange or an abort decides now; the
|
|
46
|
+
* port answers anything else with the failure page, and a paste is dropped. `done`: settled.
|
|
47
|
+
*/
|
|
48
|
+
let phase = 'listening';
|
|
49
|
+
const settle = (result) => {
|
|
50
|
+
phase = 'done';
|
|
51
|
+
resolve(result);
|
|
52
|
+
};
|
|
53
|
+
const fail = (error) => {
|
|
54
|
+
phase = 'done';
|
|
55
|
+
reject(asError(error));
|
|
56
|
+
};
|
|
57
|
+
const endWait = (error) => {
|
|
58
|
+
if (phase === 'listening')
|
|
59
|
+
settle({ ok: false, error });
|
|
60
|
+
};
|
|
61
|
+
const exchanged = (result) => {
|
|
62
|
+
if (phase === 'exchanging')
|
|
63
|
+
settle(result);
|
|
64
|
+
};
|
|
65
|
+
// Takes the redirect: the one exchange of this sign-in.
|
|
66
|
+
const exchange = (callbackUrl) => {
|
|
67
|
+
phase = 'exchanging';
|
|
68
|
+
// The redirect came in time: the exchange has its own deadline (`finishSignIn`).
|
|
69
|
+
clearTimeout(timer);
|
|
70
|
+
reading.abort();
|
|
71
|
+
return finishSignIn(callbackUrl, pending, { signal, fetch: options.fetch });
|
|
72
|
+
};
|
|
38
73
|
timer = setTimeout(() => {
|
|
39
|
-
|
|
74
|
+
endWait({ kind: 'timeout' });
|
|
40
75
|
}, options.timeoutMs ?? WAIT_MS);
|
|
41
76
|
onAbort = () => {
|
|
42
|
-
|
|
77
|
+
if (phase !== 'done')
|
|
78
|
+
settle({ ok: false, error: { kind: 'aborted' } });
|
|
43
79
|
};
|
|
44
80
|
signal?.addEventListener('abort', onAbort, { once: true });
|
|
45
81
|
server.on('request', (request, response) => {
|
|
@@ -47,34 +83,55 @@ export async function signInWithLoopback(options) {
|
|
|
47
83
|
// where nothing would catch it.
|
|
48
84
|
const target = request.url ?? '/';
|
|
49
85
|
const callbackUrl = URL.canParse(target, redirectUri) ? new URL(target, redirectUri) : null;
|
|
50
|
-
if (callbackUrl?.pathname !== '/callback' ||
|
|
86
|
+
if (callbackUrl?.pathname !== '/callback' || phase !== 'listening') {
|
|
51
87
|
void send(response, callbackUrl === null ? 400 : 404, pages.failed);
|
|
52
88
|
return;
|
|
53
89
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
clearTimeout(timer);
|
|
57
|
-
finishSignIn(callbackUrl, pending, { signal, fetch: options.fetch }).then(async (result) => {
|
|
90
|
+
// The page is sent before the sign-in settles, so closing the port can't cut it short.
|
|
91
|
+
exchange(callbackUrl).then(async (result) => {
|
|
58
92
|
await send(response, result.ok ? 200 : 400, result.ok ? pages.signedIn : pages.failed);
|
|
59
|
-
|
|
93
|
+
exchanged(result);
|
|
60
94
|
}, async (error) => {
|
|
61
95
|
await send(response, 500, pages.failed);
|
|
62
|
-
|
|
96
|
+
fail(error);
|
|
63
97
|
});
|
|
64
98
|
});
|
|
99
|
+
// Neither is awaited: an `open` or a reader that never settles (one waiting on a browser
|
|
100
|
+
// process, or on a person) must not hold back the redirect, the timeout or an abort.
|
|
101
|
+
// `open` is called here, so one that throws at once has ended the wait before the reader
|
|
102
|
+
// would be called: no prompt for a sign-in that already failed.
|
|
103
|
+
let opening = undefined;
|
|
104
|
+
try {
|
|
105
|
+
opening = options.open(url);
|
|
106
|
+
}
|
|
107
|
+
catch (cause) {
|
|
108
|
+
endWait({ kind: 'open_failed', cause });
|
|
109
|
+
}
|
|
110
|
+
Promise.resolve(opening).then(undefined, (cause) => {
|
|
111
|
+
endWait({ kind: 'open_failed', cause });
|
|
112
|
+
});
|
|
113
|
+
if (readPasted !== undefined) {
|
|
114
|
+
Promise.resolve()
|
|
115
|
+
.then(() => (phase === 'listening' ? readPasted(reading.signal) : undefined))
|
|
116
|
+
.then((text) => {
|
|
117
|
+
if (phase !== 'listening')
|
|
118
|
+
return;
|
|
119
|
+
const pasted = parsePastedRedirect(typeof text === 'string' ? text : '', pending);
|
|
120
|
+
if (pasted.ok)
|
|
121
|
+
exchange(pasted.callbackUrl).then(exchanged, fail);
|
|
122
|
+
else
|
|
123
|
+
endWait(pasted.error);
|
|
124
|
+
}, (cause) => {
|
|
125
|
+
endWait({ kind: 'paste_failed', cause });
|
|
126
|
+
});
|
|
127
|
+
}
|
|
65
128
|
});
|
|
66
|
-
// Not awaited on its own: an `open` that never settles (one waiting on a browser process)
|
|
67
|
-
// must not hold back the redirect, the timeout or an abort.
|
|
68
|
-
// Once a redirect is taken, its exchange decides: an opener failing later loses nothing.
|
|
69
|
-
const openFailed = Promise.resolve()
|
|
70
|
-
.then(() => options.open(url))
|
|
71
|
-
.then(() => new Promise(() => undefined), (cause) => redirect.taken ? new Promise(() => undefined) : Promise.resolve({ ok: false, error: { kind: 'open_failed', cause } }));
|
|
72
|
-
return await Promise.race([settled, openFailed]);
|
|
73
129
|
}
|
|
74
130
|
finally {
|
|
75
131
|
clearTimeout(timer);
|
|
76
132
|
if (onAbort !== undefined)
|
|
77
133
|
signal?.removeEventListener('abort', onAbort);
|
|
134
|
+
reading.abort();
|
|
78
135
|
await close();
|
|
79
136
|
}
|
|
80
137
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loopback.js","sourceRoot":"","sources":["../../src/node/loopback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAA;AAEhG,OAAO,EAAE,YAAY,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"loopback.js","sourceRoot":"","sources":["../../src/node/loopback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAA;AAEhG,OAAO,EAAE,YAAY,EAAE,WAAW,EAAwE,MAAM,mBAAmB,CAAA;AAEnI,OAAO,EAAE,mBAAmB,EAAuB,MAAM,eAAe,CAAA;AAyCxE,MAAM,OAAO,GAAG,OAAO,CAAA;AAEvB,MAAM,IAAI,GAAG,CAAC,OAAe,EAAE,IAAY,EAAU,EAAE,CACr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