@celljs/ta-host 4.17.0 → 4.19.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/esm/node/account-service.d.ts +73 -0
- package/esm/node/account-service.js +304 -0
- package/esm/node/app-commands.d.ts +1 -1
- package/esm/node/app-commands.js +46 -29
- package/esm/node/credentials.d.ts +12 -0
- package/esm/node/credentials.js +35 -0
- package/esm/node/host-protocol.d.ts +2 -0
- package/esm/node/host-protocol.js +2 -0
- package/esm/node/index.d.ts +3 -0
- package/esm/node/index.js +3 -0
- package/esm/node/keep-awake.d.ts +3 -0
- package/esm/node/keep-awake.js +6 -1
- package/esm/node/package-hosts.d.ts +4 -0
- package/esm/node/package-hosts.js +18 -1
- package/esm/node/relay-bridge.js +1 -1
- package/esm/node/rooms-bridge.d.ts +10 -1
- package/esm/node/rooms-bridge.js +25 -0
- package/esm/node/screen-share/desktop-picture.d.ts +51 -0
- package/esm/node/screen-share/desktop-picture.js +133 -0
- package/esm/node/screen-share/desktop-session.d.ts +128 -0
- package/esm/node/screen-share/desktop-session.js +437 -0
- package/esm/node/screen-share/desktop-targets.d.ts +24 -0
- package/esm/node/screen-share/desktop-targets.js +80 -0
- package/esm/node/screen-share/desktop-viewer.d.ts +146 -0
- package/esm/node/screen-share/desktop-viewer.js +339 -0
- package/esm/node/screen-share/index.d.ts +8 -0
- package/esm/node/screen-share/index.js +9 -0
- package/esm/node/screen-share/rfb-client.d.ts +54 -0
- package/esm/node/screen-share/rfb-client.js +179 -0
- package/esm/node/screen-share/rfb-des.d.ts +11 -0
- package/esm/node/screen-share/rfb-des.js +143 -0
- package/esm/node/screen-share/rfb-encodings.d.ts +71 -0
- package/esm/node/screen-share/rfb-encodings.js +288 -0
- package/esm/node/screen-share/rfb-framebuffer.d.ts +16 -0
- package/esm/node/screen-share/rfb-framebuffer.js +53 -0
- package/esm/node/screen-share/rfb-protocol.d.ts +90 -0
- package/esm/node/screen-share/rfb-protocol.js +36 -0
- package/esm/node/screen-share/rfb-reader.d.ts +34 -0
- package/esm/node/screen-share/rfb-reader.js +110 -0
- package/esm/node/screen-share/rfb-security.d.ts +30 -0
- package/esm/node/screen-share/rfb-security.js +136 -0
- package/esm/node/screen-share/rfb-test-server.d.ts +37 -0
- package/esm/node/screen-share/rfb-test-server.js +116 -0
- package/esm/node/screen-share/screen-share-server-impl.d.ts +37 -0
- package/esm/node/screen-share/screen-share-server-impl.js +76 -0
- package/esm/node/screen-share/screen-shares.d.ts +123 -0
- package/esm/node/screen-share/screen-shares.js +463 -0
- package/esm/node/session-info-util.d.ts +10 -11
- package/esm/node/session-info-util.js +16 -94
- package/esm/node/settings-store.d.ts +1 -1
- package/esm/node/settings-store.js +7 -4
- package/esm/node/sign-in/access-store.d.ts +1 -1
- package/esm/node/sign-in/access-store.js +4 -1
- package/esm/node/sign-in/index.d.ts +2 -0
- package/esm/node/sign-in/index.js +2 -0
- package/esm/node/sign-in/polled-sign-in.d.ts +50 -0
- package/esm/node/sign-in/polled-sign-in.js +83 -0
- package/esm/node/sign-in/sign-in-devices.d.ts +55 -0
- package/esm/node/sign-in/sign-in-devices.js +113 -0
- package/esm/node/sign-in/sign-in-flow.d.ts +38 -4
- package/esm/node/sign-in/sign-in-flow.js +79 -4
- package/esm/node/sign-in/sign-in-pages.d.ts +8 -0
- package/esm/node/sign-in/sign-in-pages.js +137 -8
- package/esm/node/sign-in/sign-in-provider.d.ts +6 -0
- package/esm/node/sign-in/sign-in-provider.js +15 -0
- package/esm/node/sources-extension.d.ts +10 -0
- package/esm/node/sources-extension.js +18 -0
- package/esm/node/ta-server-impl.js +3 -3
- package/esm/node/ta-session-factory.js +2 -0
- package/esm/node/team/team-calls.js +35 -0
- package/esm/node/voice-bridge.d.ts +3 -1
- package/esm/node/voice-bridge.js +10 -3
- package/esm/node/voices-file.d.ts +5 -0
- package/esm/node/voices-file.js +14 -3
- package/esm/node/working-directory.d.ts +8 -2
- package/esm/node/working-directory.js +7 -0
- package/lib/node/account-service.d.ts +74 -0
- package/lib/node/account-service.js +307 -0
- package/lib/node/app-commands.d.ts +1 -1
- package/lib/node/app-commands.js +46 -29
- package/lib/node/credentials.d.ts +13 -0
- package/lib/node/credentials.js +38 -0
- package/lib/node/host-protocol.d.ts +2 -0
- package/lib/node/host-protocol.js +3 -1
- package/lib/node/index.d.ts +3 -0
- package/lib/node/index.js +3 -0
- package/lib/node/keep-awake.d.ts +3 -0
- package/lib/node/keep-awake.js +6 -1
- package/lib/node/package-hosts.d.ts +4 -0
- package/lib/node/package-hosts.js +17 -0
- package/lib/node/relay-bridge.js +1 -1
- package/lib/node/rooms-bridge.d.ts +10 -1
- package/lib/node/rooms-bridge.js +25 -0
- package/lib/node/screen-share/desktop-picture.d.ts +52 -0
- package/lib/node/screen-share/desktop-picture.js +136 -0
- package/lib/node/screen-share/desktop-session.d.ts +129 -0
- package/lib/node/screen-share/desktop-session.js +442 -0
- package/lib/node/screen-share/desktop-targets.d.ts +25 -0
- package/lib/node/screen-share/desktop-targets.js +84 -0
- package/lib/node/screen-share/desktop-viewer.d.ts +147 -0
- package/lib/node/screen-share/desktop-viewer.js +343 -0
- package/lib/node/screen-share/index.d.ts +9 -0
- package/lib/node/screen-share/index.js +25 -0
- package/lib/node/screen-share/rfb-client.d.ts +55 -0
- package/lib/node/screen-share/rfb-client.js +183 -0
- package/lib/node/screen-share/rfb-des.d.ts +12 -0
- package/lib/node/screen-share/rfb-des.js +146 -0
- package/lib/node/screen-share/rfb-encodings.d.ts +72 -0
- package/lib/node/screen-share/rfb-encodings.js +295 -0
- package/lib/node/screen-share/rfb-framebuffer.d.ts +17 -0
- package/lib/node/screen-share/rfb-framebuffer.js +57 -0
- package/lib/node/screen-share/rfb-protocol.d.ts +91 -0
- package/lib/node/screen-share/rfb-protocol.js +39 -0
- package/lib/node/screen-share/rfb-reader.d.ts +35 -0
- package/lib/node/screen-share/rfb-reader.js +115 -0
- package/lib/node/screen-share/rfb-security.d.ts +31 -0
- package/lib/node/screen-share/rfb-security.js +141 -0
- package/lib/node/screen-share/rfb-test-server.d.ts +38 -0
- package/lib/node/screen-share/rfb-test-server.js +120 -0
- package/lib/node/screen-share/screen-share-server-impl.d.ts +38 -0
- package/lib/node/screen-share/screen-share-server-impl.js +79 -0
- package/lib/node/screen-share/screen-shares.d.ts +124 -0
- package/lib/node/screen-share/screen-shares.js +464 -0
- package/lib/node/session-info-util.d.ts +10 -11
- package/lib/node/session-info-util.js +15 -93
- package/lib/node/settings-store.d.ts +1 -1
- package/lib/node/settings-store.js +6 -3
- package/lib/node/sign-in/access-store.d.ts +1 -1
- package/lib/node/sign-in/access-store.js +4 -1
- package/lib/node/sign-in/index.d.ts +2 -0
- package/lib/node/sign-in/index.js +2 -0
- package/lib/node/sign-in/polled-sign-in.d.ts +51 -0
- package/lib/node/sign-in/polled-sign-in.js +87 -0
- package/lib/node/sign-in/sign-in-devices.d.ts +56 -0
- package/lib/node/sign-in/sign-in-devices.js +117 -0
- package/lib/node/sign-in/sign-in-flow.d.ts +38 -4
- package/lib/node/sign-in/sign-in-flow.js +80 -5
- package/lib/node/sign-in/sign-in-pages.d.ts +8 -0
- package/lib/node/sign-in/sign-in-pages.js +136 -7
- package/lib/node/sign-in/sign-in-provider.d.ts +6 -0
- package/lib/node/sign-in/sign-in-provider.js +15 -0
- package/lib/node/sources-extension.d.ts +11 -0
- package/lib/node/sources-extension.js +22 -0
- package/lib/node/ta-server-impl.js +2 -2
- package/lib/node/ta-session-factory.js +2 -0
- package/lib/node/team/team-calls.js +35 -0
- package/lib/node/voice-bridge.d.ts +3 -1
- package/lib/node/voice-bridge.js +9 -2
- package/lib/node/voices-file.d.ts +5 -0
- package/lib/node/voices-file.js +14 -3
- package/lib/node/working-directory.d.ts +8 -2
- package/lib/node/working-directory.js +7 -0
- package/package.json +14 -10
|
@@ -207,7 +207,7 @@ let TaSettingsStoreImpl = class TaSettingsStoreImpl {
|
|
|
207
207
|
}
|
|
208
208
|
async get(cwd) {
|
|
209
209
|
const { userFile, projectFile, trusted } = await this.files(cwd);
|
|
210
|
-
const [user, project, { models, modelNames, providerNames }] = await Promise.all([this.read(userFile), this.read(projectFile), this.models()]);
|
|
210
|
+
const [user, project, { models, agents, modelNames, providerNames }] = await Promise.all([this.read(userFile), this.read(projectFile), this.models()]);
|
|
211
211
|
return {
|
|
212
212
|
user: TaSettingsUtil.read(user),
|
|
213
213
|
project: TaSettingsUtil.read(project),
|
|
@@ -216,6 +216,7 @@ let TaSettingsStoreImpl = class TaSettingsStoreImpl {
|
|
|
216
216
|
projectFile,
|
|
217
217
|
projectTrusted: trusted !== false,
|
|
218
218
|
models,
|
|
219
|
+
agents,
|
|
219
220
|
modelNames,
|
|
220
221
|
providerNames,
|
|
221
222
|
};
|
|
@@ -315,10 +316,12 @@ let TaSettingsStoreImpl = class TaSettingsStoreImpl {
|
|
|
315
316
|
providerNames[provider.id] = provider.name;
|
|
316
317
|
}
|
|
317
318
|
}
|
|
318
|
-
|
|
319
|
+
const name = (model) => `${model.provider}/${model.id}`;
|
|
320
|
+
const agents = available.filter(model => String(model.api).startsWith(ta_protocol_1.TA_AGENT_API_PREFIX)).map(name);
|
|
321
|
+
return { models: available.map(name), agents, modelNames, providerNames };
|
|
319
322
|
}
|
|
320
323
|
catch (_a) {
|
|
321
|
-
return { models: [], modelNames: {}, providerNames: {} };
|
|
324
|
+
return { models: [], agents: [], modelNames: {}, providerNames: {} };
|
|
322
325
|
}
|
|
323
326
|
}
|
|
324
327
|
async reloadSessions(scope, cwd) {
|
|
@@ -25,7 +25,7 @@ interface AccessFile {
|
|
|
25
25
|
export declare namespace AccessUtil {
|
|
26
26
|
/** Logins and addresses are the same whatever their case; the ids of WeChat and `sub`s are not. */
|
|
27
27
|
function normalize(account: string): string;
|
|
28
|
-
/** `google:*@corp.com` lets in every address of the domain; anything else, one account. */
|
|
28
|
+
/** `google:*@corp.com` lets in every address of the domain, `oidc:*` every account of the provider; anything else, one account. */
|
|
29
29
|
function matches(pattern: string, account: string): boolean;
|
|
30
30
|
/** TA_ALLOWED_USERS: accounts separated by commas, spaces or new lines. */
|
|
31
31
|
function parseList(list: string | undefined): string[];
|
|
@@ -17,9 +17,12 @@ var AccessUtil;
|
|
|
17
17
|
return value.startsWith('github:') || value.includes('@') ? value.toLowerCase() : value;
|
|
18
18
|
}
|
|
19
19
|
AccessUtil.normalize = normalize;
|
|
20
|
-
/** `google:*@corp.com` lets in every address of the domain; anything else, one account. */
|
|
20
|
+
/** `google:*@corp.com` lets in every address of the domain, `oidc:*` every account of the provider; anything else, one account. */
|
|
21
21
|
function matches(pattern, account) {
|
|
22
22
|
const [want, have] = [normalize(pattern), normalize(account)];
|
|
23
|
+
if (want.endsWith(':*') && want.indexOf(':') === want.length - 2) {
|
|
24
|
+
return have.startsWith(want.slice(0, -1)) && have.length > want.length - 1;
|
|
25
|
+
}
|
|
23
26
|
const star = want.indexOf(':*@');
|
|
24
27
|
if (star > 0) {
|
|
25
28
|
return have.startsWith(want.slice(0, star + 1)) && have.endsWith(want.slice(star + 2));
|
|
@@ -16,6 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./access-server-impl"), exports);
|
|
18
18
|
__exportStar(require("./access-store"), exports);
|
|
19
|
+
__exportStar(require("./polled-sign-in"), exports);
|
|
20
|
+
__exportStar(require("./sign-in-devices"), exports);
|
|
19
21
|
__exportStar(require("./sign-in-flow"), exports);
|
|
20
22
|
__exportStar(require("./sign-in-middleware"), exports);
|
|
21
23
|
__exportStar(require("./sign-in-pages"), exports);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { TaSignInProvider } from '@celljs/ta-protocol';
|
|
2
|
+
import { type SignInAccount } from './sign-in-provider';
|
|
3
|
+
/**
|
|
4
|
+
* A provider the browser signs in at without coming back to Ta: the request is pushed to it (PAR, RFC 9126), the user
|
|
5
|
+
* agrees in a browser, and Ta asks it for the result until it has one (a company's sign-in for CLIs, as
|
|
6
|
+
* `<par endpoint>/poll`). Needs no secret and no address to come back to: a client id is all.
|
|
7
|
+
*/
|
|
8
|
+
export interface PolledSignInProvider extends TaSignInProvider {
|
|
9
|
+
readonly polled: true;
|
|
10
|
+
/** A sign-in under way: where the browser goes, how long it is good for, and its result asked for. */
|
|
11
|
+
begin(): Promise<PolledSignIn>;
|
|
12
|
+
}
|
|
13
|
+
export interface PolledSignIn {
|
|
14
|
+
url: string;
|
|
15
|
+
/** Seconds. */
|
|
16
|
+
expiresIn: number;
|
|
17
|
+
/** The account once agreed to; `pending` while not yet. Throws once refused or too late. */
|
|
18
|
+
poll(): Promise<SignInAccount | 'pending'>;
|
|
19
|
+
}
|
|
20
|
+
interface PolledConfiguration {
|
|
21
|
+
authorization_endpoint: string;
|
|
22
|
+
token_endpoint: string;
|
|
23
|
+
userinfo_endpoint: string;
|
|
24
|
+
pushed_authorization_request_endpoint: string;
|
|
25
|
+
}
|
|
26
|
+
export interface PushedSignInOptions {
|
|
27
|
+
/** The account is `<id>:<sub>`. */
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
issuer: string;
|
|
31
|
+
clientId: string;
|
|
32
|
+
/** What the provider shows the user its sign-in is for, when it knows several of one client. */
|
|
33
|
+
cliId?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The server of `issuer` (its openid-configuration says where): PAR, then `<par endpoint>/poll`, the code and userinfo. The
|
|
37
|
+
* account is `<id>:<username>` (as TA_GATEWAY_ADMINS and Settings, Access name it), `<id>:<sub>` without one.
|
|
38
|
+
*/
|
|
39
|
+
export declare class PushedSignIn implements PolledSignInProvider {
|
|
40
|
+
protected readonly options: PushedSignInOptions;
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly name: string;
|
|
43
|
+
readonly polled: true;
|
|
44
|
+
protected configuration?: Promise<PolledConfiguration>;
|
|
45
|
+
constructor(options: PushedSignInOptions);
|
|
46
|
+
begin(): Promise<PolledSignIn>;
|
|
47
|
+
protected poll(config: PolledConfiguration, url: string, verifier: string): Promise<SignInAccount | 'pending'>;
|
|
48
|
+
protected discover(): Promise<PolledConfiguration>;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=polled-sign-in.d.ts.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PushedSignIn = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const sign_in_flow_1 = require("./sign-in-flow");
|
|
6
|
+
const sign_in_provider_1 = require("./sign-in-provider");
|
|
7
|
+
/**
|
|
8
|
+
* The server of `issuer` (its openid-configuration says where): PAR, then `<par endpoint>/poll`, the code and userinfo. The
|
|
9
|
+
* account is `<id>:<username>` (as TA_GATEWAY_ADMINS and Settings, Access name it), `<id>:<sub>` without one.
|
|
10
|
+
*/
|
|
11
|
+
class PushedSignIn {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
this.polled = true;
|
|
15
|
+
this.id = options.id;
|
|
16
|
+
this.name = options.name;
|
|
17
|
+
}
|
|
18
|
+
async begin() {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const config = await this.discover();
|
|
21
|
+
if (!config.pushed_authorization_request_endpoint) {
|
|
22
|
+
throw new sign_in_provider_1.SignInError(`${this.name}: no pushed authorization requests`);
|
|
23
|
+
}
|
|
24
|
+
const { verifier, challenge } = sign_in_flow_1.SignInUtil.pkce();
|
|
25
|
+
const pushed = await sign_in_provider_1.SignInHttp.json(config.pushed_authorization_request_endpoint, sign_in_provider_1.SignInHttp.form({
|
|
26
|
+
client_id: this.options.clientId,
|
|
27
|
+
response_type: 'code',
|
|
28
|
+
code_challenge: challenge,
|
|
29
|
+
code_challenge_method: 'S256',
|
|
30
|
+
state: (0, node_crypto_1.randomBytes)(18).toString('base64url'),
|
|
31
|
+
scope: 'openid profile email',
|
|
32
|
+
login_only: 'true',
|
|
33
|
+
}));
|
|
34
|
+
if (!pushed.request_uri) {
|
|
35
|
+
throw new sign_in_provider_1.SignInError(`${this.name}: ${(_b = (_a = pushed.error_description) !== null && _a !== void 0 ? _a : pushed.error) !== null && _b !== void 0 ? _b : 'no request'}`);
|
|
36
|
+
}
|
|
37
|
+
const requestUri = pushed.request_uri;
|
|
38
|
+
const url = sign_in_provider_1.SignInHttp.url(config.authorization_endpoint, { client_id: this.options.clientId, request_uri: requestUri, cliId: this.options.cliId });
|
|
39
|
+
const poll = sign_in_provider_1.SignInHttp.url(`${config.pushed_authorization_request_endpoint}/poll`, { request_uri: requestUri, client_id: this.options.clientId });
|
|
40
|
+
return { url, expiresIn: Number(pushed.expires_in) || 300, poll: () => this.poll(config, poll, verifier) };
|
|
41
|
+
}
|
|
42
|
+
async poll(config, url, verifier) {
|
|
43
|
+
var _a;
|
|
44
|
+
var _b, _c, _d, _e;
|
|
45
|
+
const response = await fetch(url, { headers: { Accept: 'application/json' }, signal: AbortSignal.timeout(10000) });
|
|
46
|
+
if (response.status === 404) {
|
|
47
|
+
throw new sign_in_provider_1.SignInError(`${this.name}: the sign-in expired`);
|
|
48
|
+
}
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
// Down for a moment: asked again.
|
|
51
|
+
return 'pending';
|
|
52
|
+
}
|
|
53
|
+
const result = (await response.json().catch(() => ({})));
|
|
54
|
+
if (result.status === 'pending' || (result.status === 'completed' && !result.code) || !result.status) {
|
|
55
|
+
return 'pending';
|
|
56
|
+
}
|
|
57
|
+
if (result.status !== 'completed' || !result.code) {
|
|
58
|
+
throw new sign_in_provider_1.SignInError(`${this.name}: ${(_c = (_b = result.error_description) !== null && _b !== void 0 ? _b : result.error) !== null && _c !== void 0 ? _c : result.status}`);
|
|
59
|
+
}
|
|
60
|
+
const token = await sign_in_provider_1.SignInHttp.json(config.token_endpoint, sign_in_provider_1.SignInHttp.form({
|
|
61
|
+
grant_type: 'authorization_code',
|
|
62
|
+
code: result.code,
|
|
63
|
+
code_verifier: verifier,
|
|
64
|
+
client_id: this.options.clientId,
|
|
65
|
+
...(result.redirect_uri ? { redirect_uri: result.redirect_uri } : {}),
|
|
66
|
+
}));
|
|
67
|
+
if (!token.access_token) {
|
|
68
|
+
throw new sign_in_provider_1.SignInError(`${this.name}: ${(_e = (_d = token.error_description) !== null && _d !== void 0 ? _d : token.error) !== null && _e !== void 0 ? _e : 'no access token'}`);
|
|
69
|
+
}
|
|
70
|
+
const user = await sign_in_provider_1.SignInHttp.json(config.userinfo_endpoint, { headers: { Authorization: `Bearer ${token.access_token}`, Accept: 'application/json' } });
|
|
71
|
+
// The login a company's people know each other by (`username`), else the id it gives: `iam:<login>`, as `user:<login>` of a link.
|
|
72
|
+
const login = (_a = (user.username || user.preferred_username || user.sub)) === null || _a === void 0 ? void 0 : _a.trim();
|
|
73
|
+
if (!login) {
|
|
74
|
+
throw new sign_in_provider_1.SignInError(`${this.name}: the account has no id`);
|
|
75
|
+
}
|
|
76
|
+
return { id: `${this.id}:${login}`, name: user.name || user.nickname || login, avatar: user.picture };
|
|
77
|
+
}
|
|
78
|
+
discover() {
|
|
79
|
+
if (!this.configuration) {
|
|
80
|
+
this.configuration = sign_in_provider_1.SignInHttp.json(`${this.options.issuer.replace(/\/+$/, '')}/.well-known/openid-configuration`);
|
|
81
|
+
this.configuration.catch(() => (this.configuration = undefined));
|
|
82
|
+
}
|
|
83
|
+
return this.configuration;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.PushedSignIn = PushedSignIn;
|
|
87
|
+
//# sourceMappingURL=polled-sign-in.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { TaDeviceSignInState } from '@celljs/ta-protocol';
|
|
2
|
+
import type { AccessStore } from './access-store';
|
|
3
|
+
import type { SignInAccount } from './sign-in-provider';
|
|
4
|
+
/** How long the user has to sign in in a browser once the device asked. */
|
|
5
|
+
export declare const DEVICE_CODE_TTL_MS: number;
|
|
6
|
+
/** How long a device signed in by an account not let in yet waits for it to be: it gets its token once it is. */
|
|
7
|
+
export declare const DEVICE_WAIT_TTL_MS: number;
|
|
8
|
+
/** How often a device polls. */
|
|
9
|
+
export declare const DEVICE_POLL_MS = 2000;
|
|
10
|
+
/** Devices under way at most: anyone may ask for a code. */
|
|
11
|
+
export declare const MAX_DEVICE_SIGN_INS = 1000;
|
|
12
|
+
interface DeviceSignIn {
|
|
13
|
+
device: string;
|
|
14
|
+
code: string;
|
|
15
|
+
/** What the device says it is, for the list of sign-ins. */
|
|
16
|
+
name?: string;
|
|
17
|
+
at: number;
|
|
18
|
+
/** Who signed in for it, in a browser. */
|
|
19
|
+
account?: SignInAccount;
|
|
20
|
+
}
|
|
21
|
+
export declare namespace SignInDevicesUtil {
|
|
22
|
+
/** `ABCD-EFGH`: 25⁸ codes, of which a few hundred live at once, each for minutes. */
|
|
23
|
+
function code(): string;
|
|
24
|
+
/** A code as the user may type it: any case, with or without its dash. */
|
|
25
|
+
function normalize(code: string): string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Devices signing in as OAuth 2.0's device flow (TA_DEVICE_SIGN_IN_PATH): kept in memory, as the sign-ins under way
|
|
29
|
+
* of SignInFlow; a device that asked before a restart asks again. Whether an account is let in stays the store's: a
|
|
30
|
+
* device of one not let in waits, its account among the requests, and gets its token once let in.
|
|
31
|
+
*/
|
|
32
|
+
export declare class SignInDevices {
|
|
33
|
+
protected readonly store: AccessStore;
|
|
34
|
+
protected readonly byCode: Map<string, DeviceSignIn>;
|
|
35
|
+
protected readonly byDevice: Map<string, DeviceSignIn>;
|
|
36
|
+
constructor(store: AccessStore);
|
|
37
|
+
start(name: string | undefined, now?: number): {
|
|
38
|
+
device: string;
|
|
39
|
+
code: string;
|
|
40
|
+
expiresAt: number;
|
|
41
|
+
};
|
|
42
|
+
/** What the device of a code said it is (its user agent), for the page that lets it in to show; none once used or late. */
|
|
43
|
+
name(code: string, now?: number): string | undefined;
|
|
44
|
+
/** Whether a code waits for someone to sign in for it, as a browser takes it to the provider and back. */
|
|
45
|
+
open(code: string, now?: number): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* `account` signed in for the device of `code`, in a browser: let in, the device gets its token at its next poll; not,
|
|
48
|
+
* it waits among the requests. False for a code unknown, too late or signed in for already.
|
|
49
|
+
*/
|
|
50
|
+
signedIn(code: string, account: SignInAccount, now?: number): boolean;
|
|
51
|
+
poll(device: string, now?: number): TaDeviceSignInState;
|
|
52
|
+
protected remove(entry: DeviceSignIn): void;
|
|
53
|
+
protected prune(now: number): void;
|
|
54
|
+
}
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=sign-in-devices.d.ts.map
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignInDevices = exports.SignInDevicesUtil = exports.MAX_DEVICE_SIGN_INS = exports.DEVICE_POLL_MS = exports.DEVICE_WAIT_TTL_MS = exports.DEVICE_CODE_TTL_MS = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
/** How long the user has to sign in in a browser once the device asked. */
|
|
6
|
+
exports.DEVICE_CODE_TTL_MS = 10 * 60 * 1000;
|
|
7
|
+
/** How long a device signed in by an account not let in yet waits for it to be: it gets its token once it is. */
|
|
8
|
+
exports.DEVICE_WAIT_TTL_MS = 24 * 3600 * 1000;
|
|
9
|
+
/** How often a device polls. */
|
|
10
|
+
exports.DEVICE_POLL_MS = 2000;
|
|
11
|
+
/** Devices under way at most: anyone may ask for a code. */
|
|
12
|
+
exports.MAX_DEVICE_SIGN_INS = 1000;
|
|
13
|
+
/** No 0/O, 1/I/L, 2/Z, 5/S, 8/B: read off one screen and checked against another. */
|
|
14
|
+
const ALPHABET = 'ACDEFGHJKMNPQRTUVWXY34679';
|
|
15
|
+
var SignInDevicesUtil;
|
|
16
|
+
(function (SignInDevicesUtil) {
|
|
17
|
+
/** `ABCD-EFGH`: 25⁸ codes, of which a few hundred live at once, each for minutes. */
|
|
18
|
+
function code() {
|
|
19
|
+
let text = '';
|
|
20
|
+
for (let i = 0; i < 8; i++) {
|
|
21
|
+
text += ALPHABET[(0, node_crypto_1.randomInt)(ALPHABET.length)];
|
|
22
|
+
}
|
|
23
|
+
return `${text.slice(0, 4)}-${text.slice(4)}`;
|
|
24
|
+
}
|
|
25
|
+
SignInDevicesUtil.code = code;
|
|
26
|
+
/** A code as the user may type it: any case, with or without its dash. */
|
|
27
|
+
function normalize(code) {
|
|
28
|
+
const plain = code.toUpperCase().replace(/[^A-Z0-9]/g, '');
|
|
29
|
+
return plain.length === 8 ? `${plain.slice(0, 4)}-${plain.slice(4)}` : '';
|
|
30
|
+
}
|
|
31
|
+
SignInDevicesUtil.normalize = normalize;
|
|
32
|
+
})(SignInDevicesUtil || (exports.SignInDevicesUtil = SignInDevicesUtil = {}));
|
|
33
|
+
/**
|
|
34
|
+
* Devices signing in as OAuth 2.0's device flow (TA_DEVICE_SIGN_IN_PATH): kept in memory, as the sign-ins under way
|
|
35
|
+
* of SignInFlow; a device that asked before a restart asks again. Whether an account is let in stays the store's: a
|
|
36
|
+
* device of one not let in waits, its account among the requests, and gets its token once let in.
|
|
37
|
+
*/
|
|
38
|
+
class SignInDevices {
|
|
39
|
+
constructor(store) {
|
|
40
|
+
this.store = store;
|
|
41
|
+
this.byCode = new Map();
|
|
42
|
+
this.byDevice = new Map();
|
|
43
|
+
}
|
|
44
|
+
start(name, now = Date.now()) {
|
|
45
|
+
this.prune(now);
|
|
46
|
+
for (const oldest of this.byCode.values()) {
|
|
47
|
+
if (this.byCode.size < exports.MAX_DEVICE_SIGN_INS) {
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
this.remove(oldest);
|
|
51
|
+
}
|
|
52
|
+
let code = SignInDevicesUtil.code();
|
|
53
|
+
while (this.byCode.has(code)) {
|
|
54
|
+
code = SignInDevicesUtil.code();
|
|
55
|
+
}
|
|
56
|
+
const entry = { device: (0, node_crypto_1.randomBytes)(32).toString('base64url'), code, name: (name === null || name === void 0 ? void 0 : name.trim().slice(0, 100)) || undefined, at: now };
|
|
57
|
+
this.byCode.set(code, entry);
|
|
58
|
+
this.byDevice.set(entry.device, entry);
|
|
59
|
+
return { device: entry.device, code, expiresAt: now + exports.DEVICE_CODE_TTL_MS };
|
|
60
|
+
}
|
|
61
|
+
/** What the device of a code said it is (its user agent), for the page that lets it in to show; none once used or late. */
|
|
62
|
+
name(code, now = Date.now()) {
|
|
63
|
+
const entry = this.byCode.get(SignInDevicesUtil.normalize(code));
|
|
64
|
+
return entry && !entry.account && now - entry.at <= exports.DEVICE_CODE_TTL_MS ? entry.name : undefined;
|
|
65
|
+
}
|
|
66
|
+
/** Whether a code waits for someone to sign in for it, as a browser takes it to the provider and back. */
|
|
67
|
+
open(code, now = Date.now()) {
|
|
68
|
+
const entry = this.byCode.get(SignInDevicesUtil.normalize(code));
|
|
69
|
+
return Boolean(entry && !entry.account && now - entry.at <= exports.DEVICE_CODE_TTL_MS);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* `account` signed in for the device of `code`, in a browser: let in, the device gets its token at its next poll; not,
|
|
73
|
+
* it waits among the requests. False for a code unknown, too late or signed in for already.
|
|
74
|
+
*/
|
|
75
|
+
signedIn(code, account, now = Date.now()) {
|
|
76
|
+
const entry = this.byCode.get(SignInDevicesUtil.normalize(code));
|
|
77
|
+
if (!entry || entry.account || now - entry.at > exports.DEVICE_CODE_TTL_MS) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
entry.account = account;
|
|
81
|
+
entry.at = now;
|
|
82
|
+
if (!this.store.allows(account.id)) {
|
|
83
|
+
this.store.request(account, now);
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
poll(device, now = Date.now()) {
|
|
88
|
+
const entry = this.byDevice.get(device);
|
|
89
|
+
if (!entry || now - entry.at > (entry.account ? exports.DEVICE_WAIT_TTL_MS : exports.DEVICE_CODE_TTL_MS)) {
|
|
90
|
+
if (entry) {
|
|
91
|
+
this.remove(entry);
|
|
92
|
+
}
|
|
93
|
+
return { status: 'expired' };
|
|
94
|
+
}
|
|
95
|
+
if (!entry.account) {
|
|
96
|
+
return { status: 'pending' };
|
|
97
|
+
}
|
|
98
|
+
if (!this.store.allows(entry.account.id)) {
|
|
99
|
+
return { status: 'waiting', account: entry.account.id };
|
|
100
|
+
}
|
|
101
|
+
this.remove(entry);
|
|
102
|
+
return { status: 'done', token: this.store.signIn(entry.account, entry.name, now), account: entry.account.id };
|
|
103
|
+
}
|
|
104
|
+
remove(entry) {
|
|
105
|
+
this.byCode.delete(entry.code);
|
|
106
|
+
this.byDevice.delete(entry.device);
|
|
107
|
+
}
|
|
108
|
+
prune(now) {
|
|
109
|
+
for (const entry of this.byCode.values()) {
|
|
110
|
+
if (now - entry.at > (entry.account ? exports.DEVICE_WAIT_TTL_MS : exports.DEVICE_CODE_TTL_MS)) {
|
|
111
|
+
this.remove(entry);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.SignInDevices = SignInDevices;
|
|
117
|
+
//# sourceMappingURL=sign-in-devices.js.map
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { IncomingMessage } from 'node:http';
|
|
2
2
|
import type { AccessStore } from './access-store';
|
|
3
|
+
import type { PolledSignInProvider } from './polled-sign-in';
|
|
4
|
+
import { SignInDevices } from './sign-in-devices';
|
|
3
5
|
import { type SignInAccount, type SignInProvider } from './sign-in-provider';
|
|
4
6
|
/** Sign-ins under way at most: anyone may start one without a token, and each is kept until it ends or expires. */
|
|
5
7
|
export declare const MAX_PENDING_SIGN_INS = 1000;
|
|
8
|
+
/** How often a polled provider is asked whether the user agreed. */
|
|
9
|
+
export declare const POLL_MS = 2000;
|
|
6
10
|
interface Pending {
|
|
7
11
|
provider: string;
|
|
8
12
|
verifier: string;
|
|
@@ -11,13 +15,20 @@ interface Pending {
|
|
|
11
15
|
bind: boolean;
|
|
12
16
|
/** Only says who signed in (TaHostAccounts.verify): lets no one into ta serve. */
|
|
13
17
|
verify?: true;
|
|
18
|
+
/** For the device of this code (SignInDevices), not the browser: the browser gets no token. */
|
|
19
|
+
device?: string;
|
|
14
20
|
at: number;
|
|
15
21
|
}
|
|
22
|
+
/** In with a token, told to wait, or signed in for a device (`allowed`: it gets its token at once, else once let in). */
|
|
16
23
|
export type SignInResult = {
|
|
17
24
|
token: string;
|
|
18
25
|
account: SignInAccount;
|
|
19
26
|
} | {
|
|
20
27
|
denied: SignInAccount;
|
|
28
|
+
} | {
|
|
29
|
+
device: string;
|
|
30
|
+
account: SignInAccount;
|
|
31
|
+
allowed: boolean;
|
|
21
32
|
};
|
|
22
33
|
export declare namespace SignInUtil {
|
|
23
34
|
/**
|
|
@@ -41,8 +52,31 @@ export declare class SignInFlow {
|
|
|
41
52
|
providers: SignInProvider[];
|
|
42
53
|
readonly store: AccessStore;
|
|
43
54
|
readonly publicUrl?: string | undefined;
|
|
44
|
-
|
|
55
|
+
/** Those the browser signs in at without coming back (PolledSignInProvider): for devices, whose code they sign in for. */
|
|
56
|
+
polled: PolledSignInProvider[];
|
|
57
|
+
constructor(providers: SignInProvider[], store: AccessStore, publicUrl?: string | undefined,
|
|
58
|
+
/** Those the browser signs in at without coming back (PolledSignInProvider): for devices, whose code they sign in for. */
|
|
59
|
+
polled?: PolledSignInProvider[]);
|
|
60
|
+
/** What Ta asks each polled provider for, by the code of the device it is for: one at a time for a code. */
|
|
61
|
+
protected readonly polling: Map<string, {
|
|
62
|
+
stopped: boolean;
|
|
63
|
+
}>;
|
|
64
|
+
protected pollMs: number;
|
|
65
|
+
/**
|
|
66
|
+
* Signs in with a polled provider for the device of `code`: where the browser goes; Ta asks the provider until it says
|
|
67
|
+
* who agreed, and lets the device in as them (SignInDevices.signedIn), or until it is too late or the code taken.
|
|
68
|
+
*/
|
|
69
|
+
startPolled(providerId: string, code: string, now?: number): Promise<string>;
|
|
70
|
+
protected pollUntil(provider: PolledSignInProvider, signIn: {
|
|
71
|
+
poll(): Promise<SignInAccount | 'pending'>;
|
|
72
|
+
}, code: string, run: {
|
|
73
|
+
stopped: boolean;
|
|
74
|
+
}, deadline: number): Promise<void>;
|
|
75
|
+
/** Stops what is asked of polled providers: the server closes. */
|
|
76
|
+
stopPolling(): void;
|
|
45
77
|
protected readonly pending: Map<string, Pending>;
|
|
78
|
+
/** The devices that sign in through a browser (TA_DEVICE_SIGN_IN_PATH). */
|
|
79
|
+
readonly devices: SignInDevices;
|
|
46
80
|
protected readonly binds: Map<string, {
|
|
47
81
|
provider: string;
|
|
48
82
|
at: number;
|
|
@@ -50,8 +84,8 @@ export declare class SignInFlow {
|
|
|
50
84
|
provider(id: string): SignInProvider | undefined;
|
|
51
85
|
/** A link, used once, that signs in with `provider` and lets the account in. */
|
|
52
86
|
bindUrl(provider: string, now?: number): string;
|
|
53
|
-
/** Where the browser goes, and the state that comes back with it. */
|
|
54
|
-
start(providerId: string, origin: string, bind?: string, now?: number): Promise<{
|
|
87
|
+
/** Where the browser goes, and the state that comes back with it; with `device`, it signs in for the device of that code. */
|
|
88
|
+
start(providerId: string, origin: string, bind?: string, now?: number, device?: string): Promise<{
|
|
55
89
|
url: string;
|
|
56
90
|
state: string;
|
|
57
91
|
}>;
|
|
@@ -62,7 +96,7 @@ export declare class SignInFlow {
|
|
|
62
96
|
}>;
|
|
63
97
|
/** The account of a sign-in of {@link startVerify}: no token, nothing let in. */
|
|
64
98
|
verify(state: string, code: string, now?: number): Promise<SignInAccount>;
|
|
65
|
-
protected begin(providerId: string, redirectUri: string, kind: Pick<Pending, 'bind' | 'verify'>, now: number): Promise<{
|
|
99
|
+
protected begin(providerId: string, redirectUri: string, kind: Pick<Pending, 'bind' | 'verify' | 'device'>, now: number): Promise<{
|
|
66
100
|
url: string;
|
|
67
101
|
state: string;
|
|
68
102
|
}>;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SignInFlow = exports.SignInUtil = exports.MAX_PENDING_SIGN_INS = void 0;
|
|
3
|
+
exports.SignInFlow = exports.SignInUtil = exports.POLL_MS = exports.MAX_PENDING_SIGN_INS = void 0;
|
|
4
4
|
const node_crypto_1 = require("node:crypto");
|
|
5
5
|
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
6
|
+
const sign_in_devices_1 = require("./sign-in-devices");
|
|
6
7
|
const sign_in_provider_1 = require("./sign-in-provider");
|
|
7
8
|
/** How long the browser has with the provider, and a link of {@link SignInFlow.bindUrl}. */
|
|
8
9
|
const PENDING_TTL_MS = 10 * 60 * 1000;
|
|
9
10
|
const BIND_TTL_MS = 5 * 60 * 1000;
|
|
10
11
|
/** Sign-ins under way at most: anyone may start one without a token, and each is kept until it ends or expires. */
|
|
11
12
|
exports.MAX_PENDING_SIGN_INS = 1000;
|
|
13
|
+
/** How often a polled provider is asked whether the user agreed. */
|
|
14
|
+
exports.POLL_MS = 2000;
|
|
12
15
|
var SignInUtil;
|
|
13
16
|
(function (SignInUtil) {
|
|
14
17
|
/**
|
|
@@ -42,12 +45,75 @@ var SignInUtil;
|
|
|
42
45
|
* gateway (`ta gateway`) use it alike.
|
|
43
46
|
*/
|
|
44
47
|
class SignInFlow {
|
|
45
|
-
constructor(providers, store, publicUrl
|
|
48
|
+
constructor(providers, store, publicUrl,
|
|
49
|
+
/** Those the browser signs in at without coming back (PolledSignInProvider): for devices, whose code they sign in for. */
|
|
50
|
+
polled = []) {
|
|
46
51
|
this.providers = providers;
|
|
47
52
|
this.store = store;
|
|
48
53
|
this.publicUrl = publicUrl;
|
|
54
|
+
this.polled = polled;
|
|
55
|
+
/** What Ta asks each polled provider for, by the code of the device it is for: one at a time for a code. */
|
|
56
|
+
this.polling = new Map();
|
|
57
|
+
this.pollMs = exports.POLL_MS;
|
|
49
58
|
this.pending = new Map();
|
|
50
59
|
this.binds = new Map();
|
|
60
|
+
this.devices = new sign_in_devices_1.SignInDevices(store);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Signs in with a polled provider for the device of `code`: where the browser goes; Ta asks the provider until it says
|
|
64
|
+
* who agreed, and lets the device in as them (SignInDevices.signedIn), or until it is too late or the code taken.
|
|
65
|
+
*/
|
|
66
|
+
async startPolled(providerId, code, now = Date.now()) {
|
|
67
|
+
const provider = this.polled.find(one => one.id === providerId);
|
|
68
|
+
if (!provider) {
|
|
69
|
+
throw new sign_in_provider_1.SignInError(`No provider ${providerId}`);
|
|
70
|
+
}
|
|
71
|
+
if (!this.devices.open(code, now)) {
|
|
72
|
+
throw new sign_in_provider_1.SignInError('The code of the device expired or is not known here');
|
|
73
|
+
}
|
|
74
|
+
if (!this.polling.has(code) && this.polling.size >= exports.MAX_PENDING_SIGN_INS) {
|
|
75
|
+
throw new sign_in_provider_1.SignInError('Too many sign-ins under way');
|
|
76
|
+
}
|
|
77
|
+
const signIn = await provider.begin();
|
|
78
|
+
const previous = this.polling.get(code);
|
|
79
|
+
if (previous) {
|
|
80
|
+
previous.stopped = true;
|
|
81
|
+
}
|
|
82
|
+
const run = { stopped: false };
|
|
83
|
+
this.polling.set(code, run);
|
|
84
|
+
void this.pollUntil(provider, signIn, code, run, now + signIn.expiresIn * 1000);
|
|
85
|
+
return signIn.url;
|
|
86
|
+
}
|
|
87
|
+
async pollUntil(provider, signIn, code, run, deadline) {
|
|
88
|
+
try {
|
|
89
|
+
while (!run.stopped && Date.now() < deadline && this.devices.open(code)) {
|
|
90
|
+
await new Promise(resolve => setTimeout(resolve, this.pollMs));
|
|
91
|
+
if (run.stopped) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const answer = await signIn.poll().catch(error => (error instanceof sign_in_provider_1.SignInError ? error : 'pending'));
|
|
95
|
+
if (answer instanceof sign_in_provider_1.SignInError) {
|
|
96
|
+
console.warn(`signing in with ${provider.id} failed: ${answer.message}`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (answer !== 'pending') {
|
|
100
|
+
this.devices.signedIn(code, answer);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
if (this.polling.get(code) === run) {
|
|
107
|
+
this.polling.delete(code);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Stops what is asked of polled providers: the server closes. */
|
|
112
|
+
stopPolling() {
|
|
113
|
+
for (const run of this.polling.values()) {
|
|
114
|
+
run.stopped = true;
|
|
115
|
+
}
|
|
116
|
+
this.polling.clear();
|
|
51
117
|
}
|
|
52
118
|
provider(id) {
|
|
53
119
|
return this.providers.find(provider => provider.id === id);
|
|
@@ -58,14 +124,17 @@ class SignInFlow {
|
|
|
58
124
|
this.binds.set(nonce, { provider, at: now });
|
|
59
125
|
return `${ta_protocol_1.TA_SIGN_IN_PATH}/${provider}?bind=${nonce}`;
|
|
60
126
|
}
|
|
61
|
-
/** Where the browser goes, and the state that comes back with it. */
|
|
62
|
-
async start(providerId, origin, bind, now = Date.now()) {
|
|
127
|
+
/** Where the browser goes, and the state that comes back with it; with `device`, it signs in for the device of that code. */
|
|
128
|
+
async start(providerId, origin, bind, now = Date.now(), device) {
|
|
63
129
|
this.prune(now);
|
|
64
130
|
const binding = bind ? this.binds.get(bind) : undefined;
|
|
65
131
|
if (bind) {
|
|
66
132
|
this.binds.delete(bind);
|
|
67
133
|
}
|
|
68
|
-
|
|
134
|
+
if (device !== undefined && !this.devices.open(device, now)) {
|
|
135
|
+
throw new sign_in_provider_1.SignInError('The code of the device expired or is not known here');
|
|
136
|
+
}
|
|
137
|
+
return this.begin(providerId, SignInUtil.redirectUri(origin, providerId), { bind: (binding === null || binding === void 0 ? void 0 : binding.provider) === providerId, ...(device !== undefined ? { device } : {}) }, now);
|
|
69
138
|
}
|
|
70
139
|
/** A sign-in that only says who it is ({@link verify}), coming back to `redirectUri`: the page of a relay, say. */
|
|
71
140
|
startVerify(providerId, redirectUri, now = Date.now()) {
|
|
@@ -111,6 +180,12 @@ class SignInFlow {
|
|
|
111
180
|
if (pending.bind) {
|
|
112
181
|
this.store.allow(account.id, account.name, now);
|
|
113
182
|
}
|
|
183
|
+
if (pending.device !== undefined) {
|
|
184
|
+
if (!this.devices.signedIn(pending.device, account, now)) {
|
|
185
|
+
throw new sign_in_provider_1.SignInError('The code of the device expired or was used');
|
|
186
|
+
}
|
|
187
|
+
return { device: pending.device, account, allowed: this.store.allows(account.id) };
|
|
188
|
+
}
|
|
114
189
|
if (!this.store.allows(account.id)) {
|
|
115
190
|
this.store.request(account, now);
|
|
116
191
|
return { denied: account };
|
|
@@ -11,6 +11,14 @@ export declare namespace SignInPageUtil {
|
|
|
11
11
|
outcome: TaSignInOutcome;
|
|
12
12
|
account?: string;
|
|
13
13
|
}): string;
|
|
14
|
+
/**
|
|
15
|
+
* The page of the web client for the device of `code` (TA_DEVICE_SIGN_IN_PATH): where the user lets it in, and after
|
|
16
|
+
* the provider how it went (`done`: it gets its token; `waiting`: once the account is let in; `failed`).
|
|
17
|
+
*/
|
|
18
|
+
function deviceBack(code: string, outcome?: 'done' | 'waiting' | 'failed', from?: string): string;
|
|
19
|
+
function json(response: ServerResponse, status: number, body: unknown): void;
|
|
20
|
+
/** A small JSON body; undefined for one too big or not JSON. */
|
|
21
|
+
function body(request: IncomingMessage, max?: number): Promise<Record<string, unknown> | undefined>;
|
|
14
22
|
function redirect(response: ServerResponse, location: string): void;
|
|
15
23
|
function end(response: ServerResponse, status: number, body?: string): void;
|
|
16
24
|
}
|