@celljs/ta-host 4.13.1 → 4.15.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/README.en.md +3 -1
- package/README.md +3 -1
- package/esm/node/auth-server-impl.d.ts +12 -2
- package/esm/node/auth-server-impl.js +102 -3
- package/esm/node/custom-providers.d.ts +50 -0
- package/esm/node/custom-providers.js +335 -0
- package/esm/node/host-protocol.d.ts +17 -1
- package/esm/node/host-protocol.js +1 -0
- package/esm/node/index.d.ts +2 -0
- package/esm/node/index.js +2 -0
- package/esm/node/package-hosts.d.ts +2 -1
- package/esm/node/package-hosts.js +6 -2
- package/esm/node/presence-book.d.ts +38 -0
- package/esm/node/presence-book.js +159 -0
- package/esm/node/presence-server-impl.d.ts +13 -0
- package/esm/node/presence-server-impl.js +45 -0
- package/esm/node/rooms-bridge.d.ts +6 -1
- package/esm/node/rooms-bridge.js +21 -3
- package/esm/node/session-list-feed.js +2 -1
- package/esm/node/sign-in/access-server-impl.d.ts +5 -1
- package/esm/node/sign-in/access-server-impl.js +22 -1
- package/esm/node/sign-in/sign-in-flow.d.ts +14 -1
- package/esm/node/sign-in/sign-in-flow.js +24 -7
- package/esm/node/sign-in/sign-in-provider.d.ts +84 -1
- package/esm/node/sign-in/sign-in-provider.js +194 -7
- package/esm/node/sign-in/ta-sign-in.d.ts +12 -3
- package/esm/node/sign-in/ta-sign-in.js +36 -4
- package/esm/node/ta-server-impl.d.ts +7 -0
- package/esm/node/ta-server-impl.js +44 -7
- package/esm/node/ta-session-registry.d.ts +10 -3
- package/esm/node/ta-session-registry.js +29 -3
- package/esm/node/ta-session.d.ts +2 -0
- package/esm/node/ta-session.js +6 -0
- package/esm/node/team/host-team.d.ts +2 -1
- package/esm/node/team/host-team.js +11 -1
- package/esm/node/team/index.d.ts +1 -0
- package/esm/node/team/index.js +1 -0
- package/esm/node/team/member-accounts.d.ts +30 -0
- package/esm/node/team/member-accounts.js +117 -0
- package/esm/node/team/team-calls.d.ts +2 -1
- package/esm/node/team/team-calls.js +11 -0
- package/esm/node/team/team-gate.js +1 -1
- package/esm/node/team/team-protocol.d.ts +5 -1
- package/esm/node/team/team-protocol.js +2 -0
- package/esm/node/web-extension-util.js +1 -0
- package/lib/node/auth-server-impl.d.ts +12 -2
- package/lib/node/auth-server-impl.js +101 -2
- package/lib/node/custom-providers.d.ts +51 -0
- package/lib/node/custom-providers.js +338 -0
- package/lib/node/host-protocol.d.ts +17 -1
- package/lib/node/host-protocol.js +2 -1
- package/lib/node/index.d.ts +2 -0
- package/lib/node/index.js +2 -0
- package/lib/node/package-hosts.d.ts +2 -1
- package/lib/node/package-hosts.js +5 -1
- package/lib/node/presence-book.d.ts +39 -0
- package/lib/node/presence-book.js +162 -0
- package/lib/node/presence-server-impl.d.ts +14 -0
- package/lib/node/presence-server-impl.js +48 -0
- package/lib/node/rooms-bridge.d.ts +6 -1
- package/lib/node/rooms-bridge.js +20 -2
- package/lib/node/session-list-feed.js +2 -1
- package/lib/node/sign-in/access-server-impl.d.ts +5 -1
- package/lib/node/sign-in/access-server-impl.js +21 -0
- package/lib/node/sign-in/sign-in-flow.d.ts +14 -1
- package/lib/node/sign-in/sign-in-flow.js +24 -7
- package/lib/node/sign-in/sign-in-provider.d.ts +84 -1
- package/lib/node/sign-in/sign-in-provider.js +197 -9
- package/lib/node/sign-in/ta-sign-in.d.ts +12 -3
- package/lib/node/sign-in/ta-sign-in.js +36 -4
- package/lib/node/ta-server-impl.d.ts +7 -0
- package/lib/node/ta-server-impl.js +43 -6
- package/lib/node/ta-session-registry.d.ts +10 -3
- package/lib/node/ta-session-registry.js +27 -1
- package/lib/node/ta-session.d.ts +2 -0
- package/lib/node/ta-session.js +6 -0
- package/lib/node/team/host-team.d.ts +2 -1
- package/lib/node/team/host-team.js +10 -0
- package/lib/node/team/index.d.ts +1 -0
- package/lib/node/team/index.js +1 -0
- package/lib/node/team/member-accounts.d.ts +31 -0
- package/lib/node/team/member-accounts.js +120 -0
- package/lib/node/team/team-calls.d.ts +2 -1
- package/lib/node/team/team-calls.js +11 -0
- package/lib/node/team/team-gate.js +1 -1
- package/lib/node/team/team-protocol.d.ts +5 -1
- package/lib/node/team/team-protocol.js +3 -1
- package/lib/node/web-extension-util.js +1 -0
- package/package.json +12 -12
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TaPresenceServerImpl = void 0;
|
|
13
|
+
const core_1 = require("@celljs/core");
|
|
14
|
+
const rpc_1 = require("@celljs/rpc");
|
|
15
|
+
const node_1 = require("@celljs/rpc/lib/node");
|
|
16
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
17
|
+
const host_protocol_1 = require("./host-protocol");
|
|
18
|
+
const team_protocol_1 = require("./team/team-protocol");
|
|
19
|
+
/**
|
|
20
|
+
* What each page says it is at (TaPresenceServer). A page is at a conversation only when it is open and the page may
|
|
21
|
+
* see it: no one shows at one they may not see, nor at one made up.
|
|
22
|
+
*/
|
|
23
|
+
let TaPresenceServerImpl = class TaPresenceServerImpl {
|
|
24
|
+
async report(state) {
|
|
25
|
+
const connection = node_1.RpcContext.requireConnection();
|
|
26
|
+
const sessionId = typeof (state === null || state === void 0 ? void 0 : state.sessionId) === 'string' ? state.sessionId : undefined;
|
|
27
|
+
const session = sessionId ? this.sessions.list().find(one => one.id === sessionId) : undefined;
|
|
28
|
+
const seen = !!session && this.visibility.sessions(connection, [{ cwd: session.cwd, sessionFile: session.pi.sessionFile }]).length > 0;
|
|
29
|
+
this.book.report(connection, seen ? { sessionId, typing: (state === null || state === void 0 ? void 0 : state.typing) === true } : {});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.TaPresenceServerImpl = TaPresenceServerImpl;
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, core_1.Autowired)(host_protocol_1.TaPresenceBook),
|
|
35
|
+
__metadata("design:type", Object)
|
|
36
|
+
], TaPresenceServerImpl.prototype, "book", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, core_1.Autowired)(host_protocol_1.TaSessionRegistry),
|
|
39
|
+
__metadata("design:type", Object)
|
|
40
|
+
], TaPresenceServerImpl.prototype, "sessions", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, core_1.Autowired)(team_protocol_1.TaVisibility),
|
|
43
|
+
__metadata("design:type", Object)
|
|
44
|
+
], TaPresenceServerImpl.prototype, "visibility", void 0);
|
|
45
|
+
exports.TaPresenceServerImpl = TaPresenceServerImpl = __decorate([
|
|
46
|
+
(0, rpc_1.Rpc)(ta_protocol_1.TaPresenceServer)
|
|
47
|
+
], TaPresenceServerImpl);
|
|
48
|
+
//# sourceMappingURL=presence-server-impl.js.map
|
|
@@ -2,6 +2,7 @@ import { type Application, ApplicationLifecycle } from '@celljs/core';
|
|
|
2
2
|
import { type RpcConnection } from '@celljs/rpc/lib/node';
|
|
3
3
|
import { type TaFriend, type TaFriendRequest, type TaIdentity, type TaRoomEvent, type TaRoomInfo, type TaRoomRequest, TaRoomServer, type TaRooms, type TaRoomValue, type TaRoomWatch } from '@celljs/ta-protocol';
|
|
4
4
|
import type { RelayHubs } from '@celljs/ta-relay/lib/node';
|
|
5
|
+
import { ExtensionDataStore } from './extension-data';
|
|
5
6
|
import { type RelayBridge } from './relay-bridge';
|
|
6
7
|
/** The id of {@link RoomsBridge}. */
|
|
7
8
|
export declare const ROOMS_BRIDGE: unique symbol;
|
|
@@ -12,16 +13,20 @@ export declare const ROOMS_BRIDGE: unique symbol;
|
|
|
12
13
|
*/
|
|
13
14
|
export declare class RoomsBridge implements ApplicationLifecycle<Application> {
|
|
14
15
|
protected readonly relay: RelayBridge;
|
|
16
|
+
protected readonly data: ExtensionDataStore;
|
|
17
|
+
protected stopLook?: () => void;
|
|
15
18
|
/** The connections that watch, and what they hear: messages and the state too, or the state of some keys. */
|
|
16
19
|
protected readonly watchers: Map<RpcConnection, TaRoomWatch>;
|
|
17
20
|
get hubs(): RelayHubs;
|
|
18
21
|
readonly rooms: TaRooms;
|
|
19
22
|
onStart(): void;
|
|
20
23
|
onStop(): void;
|
|
24
|
+
/** The look of this Ta others see is the double's, as the user picked it on a page (TA_DOUBLE_LOOK). */
|
|
25
|
+
protected keepLook(): Promise<void>;
|
|
21
26
|
/** `watch` undefined: no more. */
|
|
22
27
|
watch(connection: RpcConnection, watch: TaRoomWatch | undefined): void;
|
|
23
28
|
protected broadcast(event: TaRoomEvent): void;
|
|
24
|
-
protected static identity({ id, name, shared }: TaIdentity): TaIdentity;
|
|
29
|
+
protected static identity({ id, name, look, shared }: TaIdentity): TaIdentity;
|
|
25
30
|
}
|
|
26
31
|
/** The rooms for clients (TaRoomServer): those of RoomsBridge, what goes wrong said as the errors of Ta. */
|
|
27
32
|
export declare class TaRoomServerImpl implements TaRoomServer {
|
package/lib/node/rooms-bridge.js
CHANGED
|
@@ -15,6 +15,7 @@ const core_1 = require("@celljs/core");
|
|
|
15
15
|
const rpc_1 = require("@celljs/rpc");
|
|
16
16
|
const node_1 = require("@celljs/rpc/lib/node");
|
|
17
17
|
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
18
|
+
const extension_data_1 = require("./extension-data");
|
|
18
19
|
const relay_bridge_1 = require("./relay-bridge");
|
|
19
20
|
const ta_errors_1 = require("./ta-errors");
|
|
20
21
|
/** The id of {@link RoomsBridge}. */
|
|
@@ -65,10 +66,23 @@ let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
|
|
|
65
66
|
onStart() {
|
|
66
67
|
this.hubs.onEvent(event => this.broadcast(event));
|
|
67
68
|
this.hubs.start();
|
|
69
|
+
void this.keepLook();
|
|
70
|
+
this.stopLook = this.data.onChange((name, key, cwd) => {
|
|
71
|
+
if (name === ta_protocol_1.TA_DOUBLE_LOOK.name && key === ta_protocol_1.TA_DOUBLE_LOOK.key && cwd === undefined) {
|
|
72
|
+
void this.keepLook();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
68
75
|
}
|
|
69
76
|
onStop() {
|
|
77
|
+
var _a;
|
|
78
|
+
(_a = this.stopLook) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
70
79
|
this.hubs.stop();
|
|
71
80
|
}
|
|
81
|
+
/** The look of this Ta others see is the double's, as the user picked it on a page (TA_DOUBLE_LOOK). */
|
|
82
|
+
async keepLook() {
|
|
83
|
+
const look = await this.data.get(ta_protocol_1.TA_DOUBLE_LOOK.name, ta_protocol_1.TA_DOUBLE_LOOK.key).catch(() => undefined);
|
|
84
|
+
await this.hubs.setLook(typeof look === 'string' && look ? look : ta_protocol_1.TA_DOUBLE_LOOK.initial).catch(() => undefined);
|
|
85
|
+
}
|
|
72
86
|
/** `watch` undefined: no more. */
|
|
73
87
|
watch(connection, watch) {
|
|
74
88
|
if (watch === undefined) {
|
|
@@ -90,8 +104,8 @@ let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
|
|
|
90
104
|
}
|
|
91
105
|
}
|
|
92
106
|
}
|
|
93
|
-
static identity({ id, name, shared }) {
|
|
94
|
-
return { id, name, ...(shared ? { shared } : {}) };
|
|
107
|
+
static identity({ id, name, look, shared }) {
|
|
108
|
+
return { id, name, ...(look ? { look } : {}), ...(shared ? { shared } : {}) };
|
|
95
109
|
}
|
|
96
110
|
};
|
|
97
111
|
exports.RoomsBridge = RoomsBridge;
|
|
@@ -99,6 +113,10 @@ __decorate([
|
|
|
99
113
|
(0, core_1.Autowired)({ id: relay_bridge_1.RELAY_BRIDGE, detached: true }),
|
|
100
114
|
__metadata("design:type", Function)
|
|
101
115
|
], RoomsBridge.prototype, "relay", void 0);
|
|
116
|
+
__decorate([
|
|
117
|
+
(0, core_1.Autowired)(extension_data_1.ExtensionDataStore),
|
|
118
|
+
__metadata("design:type", Object)
|
|
119
|
+
], RoomsBridge.prototype, "data", void 0);
|
|
102
120
|
exports.RoomsBridge = RoomsBridge = RoomsBridge_1 = __decorate([
|
|
103
121
|
(0, core_1.Component)([exports.ROOMS_BRIDGE, core_1.ApplicationLifecycle])
|
|
104
122
|
], RoomsBridge);
|
|
@@ -59,7 +59,6 @@ class SessionListFeed {
|
|
|
59
59
|
const wait = Math.max(0, watcher.lastAt + this.intervalMs - performance.now());
|
|
60
60
|
watcher.timer = setTimeout(() => {
|
|
61
61
|
watcher.timer = undefined;
|
|
62
|
-
watcher.lastAt = performance.now();
|
|
63
62
|
if (connection.closed) {
|
|
64
63
|
return;
|
|
65
64
|
}
|
|
@@ -68,6 +67,8 @@ class SessionListFeed {
|
|
|
68
67
|
if (json === watcher.sent) {
|
|
69
68
|
return;
|
|
70
69
|
}
|
|
70
|
+
// Only a list sent counts against the interval: what did not change this one does not hold back the next.
|
|
71
|
+
watcher.lastAt = performance.now();
|
|
71
72
|
watcher.sent = json;
|
|
72
73
|
connection
|
|
73
74
|
.client(ta_protocol_1.TaClient)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RpcConnectionManager } from '@celljs/rpc/lib/node';
|
|
2
|
-
import { type TaAccessInfo, TaAccessServer } from '@celljs/ta-protocol';
|
|
2
|
+
import { type TaAccessInfo, TaAccessServer, type TaSignInConfig, type TaSignInKind } from '@celljs/ta-protocol';
|
|
3
|
+
import { type RelayBridge } from '../relay-bridge';
|
|
3
4
|
import { type TaAccess } from '../ta-access';
|
|
4
5
|
import { type TaSignIn } from './ta-sign-in';
|
|
5
6
|
/** Who may sign in with an account, for anyone in; a browser that loses its sign-in is cut off at once. */
|
|
@@ -7,6 +8,9 @@ export declare class TaAccessServerImpl implements TaAccessServer {
|
|
|
7
8
|
protected readonly signIn: TaSignIn;
|
|
8
9
|
protected readonly access: TaAccess;
|
|
9
10
|
protected readonly connections: RpcConnectionManager;
|
|
11
|
+
protected readonly relay: RelayBridge;
|
|
12
|
+
getSignInConfig(): Promise<TaSignInConfig>;
|
|
13
|
+
setSignInProvider(id: TaSignInKind, fields: Record<string, string> | null): Promise<void>;
|
|
10
14
|
getAccess(): Promise<TaAccessInfo>;
|
|
11
15
|
bindUrl(provider: string): Promise<string>;
|
|
12
16
|
allow(account: string, name?: string): Promise<void>;
|
|
@@ -14,6 +14,8 @@ const core_1 = require("@celljs/core");
|
|
|
14
14
|
const rpc_1 = require("@celljs/rpc");
|
|
15
15
|
const node_1 = require("@celljs/rpc/lib/node");
|
|
16
16
|
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
17
|
+
const relay_team_1 = require("@celljs/ta-relay/lib/common/relay-team");
|
|
18
|
+
const relay_bridge_1 = require("../relay-bridge");
|
|
17
19
|
const ta_access_1 = require("../ta-access");
|
|
18
20
|
const ta_errors_1 = require("../ta-errors");
|
|
19
21
|
const access_store_1 = require("./access-store");
|
|
@@ -21,6 +23,21 @@ const ta_sign_in_1 = require("./ta-sign-in");
|
|
|
21
23
|
const ACCOUNT = /^[a-z][a-z0-9-]*:\S+$/;
|
|
22
24
|
/** Who may sign in with an account, for anyone in; a browser that loses its sign-in is cut off at once. */
|
|
23
25
|
let TaAccessServerImpl = class TaAccessServerImpl {
|
|
26
|
+
async getSignInConfig() {
|
|
27
|
+
const join = `${this.relay.relayFor('devices').replace(/\/+$/, '')}${relay_team_1.RELAY_JOIN_PATH}`;
|
|
28
|
+
const serve = this.signIn.publicUrl ? `${this.signIn.publicUrl}${ta_protocol_1.TA_SIGN_IN_PATH}/<provider>/callback` : undefined;
|
|
29
|
+
return { providers: this.signIn.setups(), callbacks: { join, ...(serve ? { serve } : {}) } };
|
|
30
|
+
}
|
|
31
|
+
setSignInProvider(id, fields) {
|
|
32
|
+
return ta_errors_1.TaErrors.guard(async () => {
|
|
33
|
+
try {
|
|
34
|
+
this.signIn.setProvider(id, fields && typeof fields === 'object' ? fields : null);
|
|
35
|
+
}
|
|
36
|
+
catch (failure) {
|
|
37
|
+
throw ta_errors_1.TaErrors.invalidArgument(failure instanceof Error ? failure.message : String(failure), 'Give the id and the secret the provider gave.');
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
24
41
|
async getAccess() {
|
|
25
42
|
var _a;
|
|
26
43
|
const providers = this.signIn.providers.map(({ id, name }) => ({ id, name }));
|
|
@@ -79,6 +96,10 @@ __decorate([
|
|
|
79
96
|
(0, core_1.Autowired)(node_1.RpcConnectionManager),
|
|
80
97
|
__metadata("design:type", Object)
|
|
81
98
|
], TaAccessServerImpl.prototype, "connections", void 0);
|
|
99
|
+
__decorate([
|
|
100
|
+
(0, core_1.Autowired)({ id: relay_bridge_1.RELAY_BRIDGE, detached: true }),
|
|
101
|
+
__metadata("design:type", Function)
|
|
102
|
+
], TaAccessServerImpl.prototype, "relay", void 0);
|
|
82
103
|
exports.TaAccessServerImpl = TaAccessServerImpl = __decorate([
|
|
83
104
|
(0, rpc_1.Rpc)(ta_protocol_1.TaAccessServer)
|
|
84
105
|
], TaAccessServerImpl);
|
|
@@ -9,6 +9,8 @@ interface Pending {
|
|
|
9
9
|
redirectUri: string;
|
|
10
10
|
/** Lets the account in: started by someone already in. */
|
|
11
11
|
bind: boolean;
|
|
12
|
+
/** Only says who signed in (TaHostAccounts.verify): lets no one into ta serve. */
|
|
13
|
+
verify?: true;
|
|
12
14
|
at: number;
|
|
13
15
|
}
|
|
14
16
|
export type SignInResult = {
|
|
@@ -36,7 +38,7 @@ export declare namespace SignInUtil {
|
|
|
36
38
|
* gateway (`ta gateway`) use it alike.
|
|
37
39
|
*/
|
|
38
40
|
export declare class SignInFlow {
|
|
39
|
-
|
|
41
|
+
providers: SignInProvider[];
|
|
40
42
|
readonly store: AccessStore;
|
|
41
43
|
readonly publicUrl?: string | undefined;
|
|
42
44
|
constructor(providers: SignInProvider[], store: AccessStore, publicUrl?: string | undefined);
|
|
@@ -53,6 +55,17 @@ export declare class SignInFlow {
|
|
|
53
55
|
url: string;
|
|
54
56
|
state: string;
|
|
55
57
|
}>;
|
|
58
|
+
/** A sign-in that only says who it is ({@link verify}), coming back to `redirectUri`: the page of a relay, say. */
|
|
59
|
+
startVerify(providerId: string, redirectUri: string, now?: number): Promise<{
|
|
60
|
+
url: string;
|
|
61
|
+
state: string;
|
|
62
|
+
}>;
|
|
63
|
+
/** The account of a sign-in of {@link startVerify}: no token, nothing let in. */
|
|
64
|
+
verify(state: string, code: string, now?: number): Promise<SignInAccount>;
|
|
65
|
+
protected begin(providerId: string, redirectUri: string, kind: Pick<Pending, 'bind' | 'verify'>, now: number): Promise<{
|
|
66
|
+
url: string;
|
|
67
|
+
state: string;
|
|
68
|
+
}>;
|
|
56
69
|
/** The browser came back from the provider with a code: in with a token of its own, or told to wait. */
|
|
57
70
|
finish(providerId: string, state: string, code: string, device?: string, now?: number): Promise<SignInResult>;
|
|
58
71
|
protected prune(now: number): void;
|
|
@@ -60,15 +60,33 @@ class SignInFlow {
|
|
|
60
60
|
}
|
|
61
61
|
/** Where the browser goes, and the state that comes back with it. */
|
|
62
62
|
async start(providerId, origin, bind, now = Date.now()) {
|
|
63
|
-
const provider = this.provider(providerId);
|
|
64
|
-
if (!provider) {
|
|
65
|
-
throw new sign_in_provider_1.SignInError(`No provider ${providerId}`);
|
|
66
|
-
}
|
|
67
63
|
this.prune(now);
|
|
68
64
|
const binding = bind ? this.binds.get(bind) : undefined;
|
|
69
65
|
if (bind) {
|
|
70
66
|
this.binds.delete(bind);
|
|
71
67
|
}
|
|
68
|
+
return this.begin(providerId, SignInUtil.redirectUri(origin, providerId), { bind: (binding === null || binding === void 0 ? void 0 : binding.provider) === providerId }, now);
|
|
69
|
+
}
|
|
70
|
+
/** A sign-in that only says who it is ({@link verify}), coming back to `redirectUri`: the page of a relay, say. */
|
|
71
|
+
startVerify(providerId, redirectUri, now = Date.now()) {
|
|
72
|
+
this.prune(now);
|
|
73
|
+
return this.begin(providerId, redirectUri, { bind: false, verify: true }, now);
|
|
74
|
+
}
|
|
75
|
+
/** The account of a sign-in of {@link startVerify}: no token, nothing let in. */
|
|
76
|
+
async verify(state, code, now = Date.now()) {
|
|
77
|
+
const pending = this.pending.get(state);
|
|
78
|
+
this.pending.delete(state);
|
|
79
|
+
const provider = pending && this.provider(pending.provider);
|
|
80
|
+
if (!(pending === null || pending === void 0 ? void 0 : pending.verify) || !provider || now - pending.at > PENDING_TTL_MS) {
|
|
81
|
+
throw new sign_in_provider_1.SignInError('The sign-in expired or was not started here');
|
|
82
|
+
}
|
|
83
|
+
return provider.account({ code, redirectUri: pending.redirectUri, verifier: pending.verifier });
|
|
84
|
+
}
|
|
85
|
+
async begin(providerId, redirectUri, kind, now) {
|
|
86
|
+
const provider = this.provider(providerId);
|
|
87
|
+
if (!provider) {
|
|
88
|
+
throw new sign_in_provider_1.SignInError(`No provider ${providerId}`);
|
|
89
|
+
}
|
|
72
90
|
// The oldest goes first: a flood of starts takes no more memory, and costs only sign-ins as old.
|
|
73
91
|
for (const oldest of this.pending.keys()) {
|
|
74
92
|
if (this.pending.size < exports.MAX_PENDING_SIGN_INS) {
|
|
@@ -78,8 +96,7 @@ class SignInFlow {
|
|
|
78
96
|
}
|
|
79
97
|
const state = (0, node_crypto_1.randomBytes)(18).toString('base64url');
|
|
80
98
|
const { verifier, challenge } = SignInUtil.pkce();
|
|
81
|
-
|
|
82
|
-
this.pending.set(state, { provider: provider.id, verifier, redirectUri, bind: (binding === null || binding === void 0 ? void 0 : binding.provider) === provider.id, at: now });
|
|
99
|
+
this.pending.set(state, { provider: provider.id, verifier, redirectUri, ...kind, at: now });
|
|
83
100
|
return { url: await provider.authorizeUrl({ redirectUri, state, challenge }), state };
|
|
84
101
|
}
|
|
85
102
|
/** The browser came back from the provider with a code: in with a token of its own, or told to wait. */
|
|
@@ -87,7 +104,7 @@ class SignInFlow {
|
|
|
87
104
|
const pending = this.pending.get(state);
|
|
88
105
|
this.pending.delete(state);
|
|
89
106
|
const provider = this.provider(providerId);
|
|
90
|
-
if (!pending || !provider || pending.provider !== providerId || now - pending.at > PENDING_TTL_MS) {
|
|
107
|
+
if (!pending || pending.verify || !provider || pending.provider !== providerId || now - pending.at > PENDING_TTL_MS) {
|
|
91
108
|
throw new sign_in_provider_1.SignInError('The sign-in expired or was not started here');
|
|
92
109
|
}
|
|
93
110
|
const account = await provider.account({ code, redirectUri: pending.redirectUri, verifier: pending.verifier });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TaSignInProvider } from '@celljs/ta-protocol';
|
|
1
|
+
import type { TaSignInKind, TaSignInProvider, TaSignInSetup } from '@celljs/ta-protocol';
|
|
2
2
|
/** Who signed in, as the provider says: `id` is the account as TA_ALLOWED_USERS names it (`github:<login>`). */
|
|
3
3
|
export interface SignInAccount {
|
|
4
4
|
id: string;
|
|
@@ -36,6 +36,8 @@ export interface GitHubEndpoints {
|
|
|
36
36
|
authorize: string;
|
|
37
37
|
token: string;
|
|
38
38
|
user: string;
|
|
39
|
+
/** Where a code to type is asked for (the device flow). */
|
|
40
|
+
device: string;
|
|
39
41
|
}
|
|
40
42
|
/** GitHub's OAuth apps; the account is `github:<login>`. GitHub Enterprise Server has the same at its own address. */
|
|
41
43
|
export declare class GitHubSignIn implements SignInProvider {
|
|
@@ -45,6 +47,8 @@ export declare class GitHubSignIn implements SignInProvider {
|
|
|
45
47
|
readonly id = "github";
|
|
46
48
|
readonly name = "GitHub";
|
|
47
49
|
static endpoints(url?: string): GitHubEndpoints;
|
|
50
|
+
/** Who a token of GitHub is. */
|
|
51
|
+
static user(endpoints: GitHubEndpoints, token: string): Promise<SignInAccount>;
|
|
48
52
|
constructor(clientId: string, clientSecret: string, endpoints?: GitHubEndpoints);
|
|
49
53
|
authorizeUrl({ redirectUri, state, challenge }: {
|
|
50
54
|
redirectUri: string;
|
|
@@ -57,6 +61,40 @@ export declare class GitHubSignIn implements SignInProvider {
|
|
|
57
61
|
verifier: string;
|
|
58
62
|
}): Promise<SignInAccount>;
|
|
59
63
|
}
|
|
64
|
+
/** A code to type at the provider, and how often to ask whether it was (OAuth 2.0's device authorization, RFC 8628). */
|
|
65
|
+
export interface DeviceCode {
|
|
66
|
+
deviceCode: string;
|
|
67
|
+
userCode: string;
|
|
68
|
+
uri: string;
|
|
69
|
+
/** Seconds between asks. */
|
|
70
|
+
interval: number;
|
|
71
|
+
/** Seconds the code is good for. */
|
|
72
|
+
expiresIn: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A provider one signs in with by typing a code at it, the device flow: no secret and no address to come back to, so
|
|
76
|
+
* Ta ships one of its own and anyone's Ta knows who asks to come in without setting anything up (TaHostAccounts). It
|
|
77
|
+
* lets no one into ta serve: that is SignInFlow, with a provider of the operator's.
|
|
78
|
+
*/
|
|
79
|
+
export interface DeviceSignInProvider extends TaSignInProvider {
|
|
80
|
+
readonly device: true;
|
|
81
|
+
code(): Promise<DeviceCode>;
|
|
82
|
+
/** The account once the code was typed and agreed to; `pending` while not yet, `slowDown` when asked too often. */
|
|
83
|
+
poll(deviceCode: string): Promise<SignInAccount | 'pending' | 'slowDown'>;
|
|
84
|
+
}
|
|
85
|
+
/** GitHub's device flow, with Ta's own OAuth app by default; the account is `github:<login>`, as GitHubSignIn's. */
|
|
86
|
+
export declare class GitHubDeviceSignIn implements DeviceSignInProvider {
|
|
87
|
+
protected readonly clientId: string;
|
|
88
|
+
protected readonly endpoints: GitHubEndpoints;
|
|
89
|
+
readonly id = "github";
|
|
90
|
+
readonly name = "GitHub";
|
|
91
|
+
readonly device: true;
|
|
92
|
+
/** Ta's own OAuth app on GitHub.com, its device flow on: a client id is public, and the device flow needs no secret. */
|
|
93
|
+
static readonly CLIENT_ID = "Ov23lip46sRQDlDM1xt7";
|
|
94
|
+
constructor(clientId?: string, endpoints?: GitHubEndpoints);
|
|
95
|
+
code(): Promise<DeviceCode>;
|
|
96
|
+
poll(deviceCode: string): Promise<SignInAccount | 'pending' | 'slowDown'>;
|
|
97
|
+
}
|
|
60
98
|
interface OidcConfiguration {
|
|
61
99
|
authorization_endpoint: string;
|
|
62
100
|
token_endpoint: string;
|
|
@@ -126,6 +164,51 @@ export declare class WeChatSignIn implements SignInProvider {
|
|
|
126
164
|
export declare namespace SignInProviders {
|
|
127
165
|
/** TA_PUBLIC_URL without its trailing `/`. */
|
|
128
166
|
function publicUrl(env: Record<string, string | undefined>): string | undefined;
|
|
167
|
+
/** Each kind of provider: its name, its fields in sign-in.json with the variable of the environment of each, and its secret's. */
|
|
168
|
+
const KINDS: readonly {
|
|
169
|
+
id: TaSignInKind;
|
|
170
|
+
name: string;
|
|
171
|
+
fields: Record<string, string>;
|
|
172
|
+
required: string[];
|
|
173
|
+
secret: [string, string];
|
|
174
|
+
}[];
|
|
175
|
+
/** How each kind is set up, by the environment first, then sign-in.json; no secret in it. */
|
|
176
|
+
function setups(env: Record<string, string | undefined>, config: Config | undefined): TaSignInSetup[];
|
|
177
|
+
/**
|
|
178
|
+
* sign-in.json with a kind set up anew (`null`: taken out): the fields given, trimmed; an empty secret keeps the
|
|
179
|
+
* one kept. Throws for a kind it does not know, or one without what it needs.
|
|
180
|
+
*/
|
|
181
|
+
function withProvider(config: Config | undefined, id: string, input: Record<string, unknown> | null): Config;
|
|
182
|
+
/** sign-in.json of the agent directory: the same providers as the environment, for a Ta not started from a shell. */
|
|
183
|
+
interface Config {
|
|
184
|
+
github?: {
|
|
185
|
+
clientId?: string;
|
|
186
|
+
clientSecret?: string;
|
|
187
|
+
url?: string;
|
|
188
|
+
};
|
|
189
|
+
google?: {
|
|
190
|
+
clientId?: string;
|
|
191
|
+
clientSecret?: string;
|
|
192
|
+
};
|
|
193
|
+
wechat?: {
|
|
194
|
+
appId?: string;
|
|
195
|
+
appSecret?: string;
|
|
196
|
+
};
|
|
197
|
+
oidc?: {
|
|
198
|
+
issuer?: string;
|
|
199
|
+
clientId?: string;
|
|
200
|
+
clientSecret?: string;
|
|
201
|
+
name?: string;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/** The environment's variables that sign-in.json stands for: what the environment sets wins. */
|
|
205
|
+
function withConfig(env: Record<string, string | undefined>, config: Config | undefined): Record<string, string | undefined>;
|
|
206
|
+
/**
|
|
207
|
+
* GitHub by a code, for those asking to come in, when GitHub is not set up with its secret (which goes there and back
|
|
208
|
+
* instead): `TA_GITHUB_DEVICE` is `off`, or `<client id>` or `<client id>@<address of GitHub>` of an OAuth app of
|
|
209
|
+
* one's own with its device flow on; by default Ta's own, on GitHub.com.
|
|
210
|
+
*/
|
|
211
|
+
function device(env: Record<string, string | undefined>): DeviceSignInProvider | undefined;
|
|
129
212
|
/**
|
|
130
213
|
* The providers the operator configured in the environment of ta serve: a provider is offered when it
|
|
131
214
|
* has its id and its secret.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SignInProviders = exports.WeChatSignIn = exports.OidcSignIn = exports.GitHubSignIn = exports.SignInHttp = exports.SignInError = void 0;
|
|
3
|
+
exports.SignInProviders = exports.WeChatSignIn = exports.OidcSignIn = exports.GitHubDeviceSignIn = exports.GitHubSignIn = exports.SignInHttp = exports.SignInError = void 0;
|
|
4
4
|
/** A sign-in that failed with the provider (a code refused, an account without what it needs). */
|
|
5
5
|
class SignInError extends Error {
|
|
6
6
|
}
|
|
@@ -48,7 +48,22 @@ class GitHubSignIn {
|
|
|
48
48
|
static endpoints(url = 'https://github.com') {
|
|
49
49
|
const base = url.replace(/\/+$/, '');
|
|
50
50
|
const api = base === 'https://github.com' ? 'https://api.github.com' : `${base}/api/v3`;
|
|
51
|
-
return {
|
|
51
|
+
return {
|
|
52
|
+
authorize: `${base}/login/oauth/authorize`,
|
|
53
|
+
token: `${base}/login/oauth/access_token`,
|
|
54
|
+
user: `${api}/user`,
|
|
55
|
+
device: `${base}/login/device/code`,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Who a token of GitHub is. */
|
|
59
|
+
static async user(endpoints, token) {
|
|
60
|
+
const user = await SignInHttp.json(endpoints.user, {
|
|
61
|
+
headers: { Authorization: `Bearer ${token}`, Accept: 'application/vnd.github+json', 'User-Agent': 'Ta' },
|
|
62
|
+
});
|
|
63
|
+
if (!user.login) {
|
|
64
|
+
throw new SignInError('GitHub: the user has no login');
|
|
65
|
+
}
|
|
66
|
+
return { id: `github:${user.login.toLowerCase()}`, name: user.name || user.login, avatar: user.avatar_url };
|
|
52
67
|
}
|
|
53
68
|
constructor(clientId, clientSecret, endpoints = GitHubSignIn.endpoints()) {
|
|
54
69
|
this.clientId = clientId;
|
|
@@ -74,16 +89,51 @@ class GitHubSignIn {
|
|
|
74
89
|
if (!token.access_token) {
|
|
75
90
|
throw new SignInError(`GitHub: ${(_b = (_a = token.error_description) !== null && _a !== void 0 ? _a : token.error) !== null && _b !== void 0 ? _b : 'no access token'}`);
|
|
76
91
|
}
|
|
77
|
-
|
|
78
|
-
headers: { Authorization: `Bearer ${token.access_token}`, Accept: 'application/vnd.github+json', 'User-Agent': 'Ta' },
|
|
79
|
-
});
|
|
80
|
-
if (!user.login) {
|
|
81
|
-
throw new SignInError('GitHub: the user has no login');
|
|
82
|
-
}
|
|
83
|
-
return { id: `github:${user.login.toLowerCase()}`, name: user.name || user.login, avatar: user.avatar_url };
|
|
92
|
+
return GitHubSignIn.user(this.endpoints, token.access_token);
|
|
84
93
|
}
|
|
85
94
|
}
|
|
86
95
|
exports.GitHubSignIn = GitHubSignIn;
|
|
96
|
+
/** GitHub's device flow, with Ta's own OAuth app by default; the account is `github:<login>`, as GitHubSignIn's. */
|
|
97
|
+
class GitHubDeviceSignIn {
|
|
98
|
+
constructor(clientId = GitHubDeviceSignIn.CLIENT_ID, endpoints = GitHubSignIn.endpoints()) {
|
|
99
|
+
this.clientId = clientId;
|
|
100
|
+
this.endpoints = endpoints;
|
|
101
|
+
this.id = 'github';
|
|
102
|
+
this.name = 'GitHub';
|
|
103
|
+
this.device = true;
|
|
104
|
+
}
|
|
105
|
+
async code() {
|
|
106
|
+
var _a, _b, _c, _d;
|
|
107
|
+
const answer = await SignInHttp.json(this.endpoints.device, SignInHttp.form({ client_id: this.clientId, scope: 'read:user' }));
|
|
108
|
+
if (!answer.device_code || !answer.user_code || !answer.verification_uri || !/^https?:\/\//.test(answer.verification_uri)) {
|
|
109
|
+
throw new SignInError(`GitHub: ${(_b = (_a = answer.error_description) !== null && _a !== void 0 ? _a : answer.error) !== null && _b !== void 0 ? _b : 'no code'}`);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
deviceCode: answer.device_code,
|
|
113
|
+
userCode: answer.user_code,
|
|
114
|
+
uri: answer.verification_uri,
|
|
115
|
+
interval: Number((_c = answer.interval) !== null && _c !== void 0 ? _c : 5),
|
|
116
|
+
expiresIn: Number((_d = answer.expires_in) !== null && _d !== void 0 ? _d : 900),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async poll(deviceCode) {
|
|
120
|
+
var _a, _b;
|
|
121
|
+
const token = await SignInHttp.json(this.endpoints.token, SignInHttp.form({ client_id: this.clientId, device_code: deviceCode, grant_type: 'urn:ietf:params:oauth:grant-type:device_code' }));
|
|
122
|
+
if (token.access_token) {
|
|
123
|
+
return GitHubSignIn.user(this.endpoints, token.access_token);
|
|
124
|
+
}
|
|
125
|
+
if (token.error === 'authorization_pending') {
|
|
126
|
+
return 'pending';
|
|
127
|
+
}
|
|
128
|
+
if (token.error === 'slow_down') {
|
|
129
|
+
return 'slowDown';
|
|
130
|
+
}
|
|
131
|
+
throw new SignInError(`GitHub: ${(_b = (_a = token.error_description) !== null && _a !== void 0 ? _a : token.error) !== null && _b !== void 0 ? _b : 'no access token'}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.GitHubDeviceSignIn = GitHubDeviceSignIn;
|
|
135
|
+
/** Ta's own OAuth app on GitHub.com, its device flow on: a client id is public, and the device flow needs no secret. */
|
|
136
|
+
GitHubDeviceSignIn.CLIENT_ID = 'Ov23lip46sRQDlDM1xt7';
|
|
87
137
|
/**
|
|
88
138
|
* OpenID Connect, found from the issuer (`/.well-known/openid-configuration`): Google, and the provider of
|
|
89
139
|
* the operator (Microsoft Entra, Okta, Keycloak, Authing...). The account is `<id>:<email>` when the
|
|
@@ -202,6 +252,144 @@ var SignInProviders;
|
|
|
202
252
|
return ((_a = env.TA_PUBLIC_URL) === null || _a === void 0 ? void 0 : _a.trim().replace(/\/+$/, '')) || undefined;
|
|
203
253
|
}
|
|
204
254
|
SignInProviders.publicUrl = publicUrl;
|
|
255
|
+
/** Each kind of provider: its name, its fields in sign-in.json with the variable of the environment of each, and its secret's. */
|
|
256
|
+
SignInProviders.KINDS = [
|
|
257
|
+
{
|
|
258
|
+
id: 'github',
|
|
259
|
+
name: 'GitHub',
|
|
260
|
+
fields: { clientId: 'TA_GITHUB_CLIENT_ID', url: 'TA_GITHUB_URL' },
|
|
261
|
+
required: ['clientId'],
|
|
262
|
+
secret: ['clientSecret', 'TA_GITHUB_CLIENT_SECRET'],
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
id: 'google',
|
|
266
|
+
name: 'Google',
|
|
267
|
+
fields: { clientId: 'TA_GOOGLE_CLIENT_ID' },
|
|
268
|
+
required: ['clientId'],
|
|
269
|
+
secret: ['clientSecret', 'TA_GOOGLE_CLIENT_SECRET'],
|
|
270
|
+
},
|
|
271
|
+
{ id: 'wechat', name: 'WeChat', fields: { appId: 'TA_WECHAT_APP_ID' }, required: ['appId'], secret: ['appSecret', 'TA_WECHAT_APP_SECRET'] },
|
|
272
|
+
{
|
|
273
|
+
id: 'oidc',
|
|
274
|
+
name: 'SSO',
|
|
275
|
+
fields: { issuer: 'TA_OIDC_ISSUER', clientId: 'TA_OIDC_CLIENT_ID', name: 'TA_OIDC_NAME' },
|
|
276
|
+
required: ['issuer', 'clientId'],
|
|
277
|
+
secret: ['clientSecret', 'TA_OIDC_CLIENT_SECRET'],
|
|
278
|
+
},
|
|
279
|
+
];
|
|
280
|
+
/** How each kind is set up, by the environment first, then sign-in.json; no secret in it. */
|
|
281
|
+
function setups(env, config) {
|
|
282
|
+
return SignInProviders.KINDS.map(kind => {
|
|
283
|
+
var _a;
|
|
284
|
+
const file = ((_a = config === null || config === void 0 ? void 0 : config[kind.id]) !== null && _a !== void 0 ? _a : {});
|
|
285
|
+
const fromEnv = !!env[kind.secret[1]] || Object.values(kind.fields).some(key => !!env[key]);
|
|
286
|
+
const value = (field) => (fromEnv ? env[kind.fields[field]] : typeof file[field] === 'string' ? file[field] : undefined);
|
|
287
|
+
const fields = {};
|
|
288
|
+
for (const field of Object.keys(kind.fields)) {
|
|
289
|
+
const one = value(field);
|
|
290
|
+
if (one) {
|
|
291
|
+
fields[field] = one;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const secret = fromEnv ? !!env[kind.secret[1]] : typeof file[kind.secret[0]] === 'string' && !!file[kind.secret[0]];
|
|
295
|
+
const configured = secret && kind.required.every(field => !!fields[field]);
|
|
296
|
+
const any = fromEnv || Object.keys(fields).length > 0 || secret;
|
|
297
|
+
return {
|
|
298
|
+
id: kind.id,
|
|
299
|
+
name: kind.id === 'oidc' && fields.name ? fields.name : kind.name,
|
|
300
|
+
configured,
|
|
301
|
+
...(any ? { source: fromEnv ? 'env' : 'file' } : {}),
|
|
302
|
+
fields,
|
|
303
|
+
secret,
|
|
304
|
+
};
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
SignInProviders.setups = setups;
|
|
308
|
+
/**
|
|
309
|
+
* sign-in.json with a kind set up anew (`null`: taken out): the fields given, trimmed; an empty secret keeps the
|
|
310
|
+
* one kept. Throws for a kind it does not know, or one without what it needs.
|
|
311
|
+
*/
|
|
312
|
+
function withProvider(config, id, input) {
|
|
313
|
+
var _a;
|
|
314
|
+
const kind = SignInProviders.KINDS.find(one => one.id === id);
|
|
315
|
+
if (!kind) {
|
|
316
|
+
throw new SignInError(`No such way to sign in: ${id}`);
|
|
317
|
+
}
|
|
318
|
+
const next = { ...(config !== null && config !== void 0 ? config : {}) };
|
|
319
|
+
if (!input) {
|
|
320
|
+
delete next[kind.id];
|
|
321
|
+
return next;
|
|
322
|
+
}
|
|
323
|
+
const kept = ((_a = next[kind.id]) !== null && _a !== void 0 ? _a : {});
|
|
324
|
+
const one = {};
|
|
325
|
+
for (const field of Object.keys(kind.fields)) {
|
|
326
|
+
const value = typeof input[field] === 'string' ? input[field].trim().slice(0, 500) : '';
|
|
327
|
+
if (value) {
|
|
328
|
+
one[field] = value;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
const secret = typeof input[kind.secret[0]] === 'string' ? input[kind.secret[0]].trim().slice(0, 500) : '';
|
|
332
|
+
const keptSecret = typeof kept[kind.secret[0]] === 'string' ? kept[kind.secret[0]] : '';
|
|
333
|
+
if (secret || keptSecret) {
|
|
334
|
+
one[kind.secret[0]] = secret || keptSecret;
|
|
335
|
+
}
|
|
336
|
+
const missing = [...kind.required, kind.secret[0]].filter(field => !one[field]);
|
|
337
|
+
if (missing.length) {
|
|
338
|
+
throw new SignInError(`${kind.name} needs ${missing.join(', ')}`);
|
|
339
|
+
}
|
|
340
|
+
if (one.issuer && !/^https:\/\//.test(one.issuer) && !/^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?(\/|$)/.test(one.issuer)) {
|
|
341
|
+
throw new SignInError('The issuer is an https address.');
|
|
342
|
+
}
|
|
343
|
+
if (one.url && !/^https?:\/\//.test(one.url)) {
|
|
344
|
+
throw new SignInError('The address of GitHub Enterprise is an http(s) address.');
|
|
345
|
+
}
|
|
346
|
+
next[kind.id] = one;
|
|
347
|
+
return next;
|
|
348
|
+
}
|
|
349
|
+
SignInProviders.withProvider = withProvider;
|
|
350
|
+
/** The environment's variables that sign-in.json stands for: what the environment sets wins. */
|
|
351
|
+
function withConfig(env, config) {
|
|
352
|
+
const { github, google, wechat, oidc } = config !== null && config !== void 0 ? config : {};
|
|
353
|
+
const file = {
|
|
354
|
+
TA_GITHUB_CLIENT_ID: github === null || github === void 0 ? void 0 : github.clientId,
|
|
355
|
+
TA_GITHUB_CLIENT_SECRET: github === null || github === void 0 ? void 0 : github.clientSecret,
|
|
356
|
+
TA_GITHUB_URL: github === null || github === void 0 ? void 0 : github.url,
|
|
357
|
+
TA_GOOGLE_CLIENT_ID: google === null || google === void 0 ? void 0 : google.clientId,
|
|
358
|
+
TA_GOOGLE_CLIENT_SECRET: google === null || google === void 0 ? void 0 : google.clientSecret,
|
|
359
|
+
TA_WECHAT_APP_ID: wechat === null || wechat === void 0 ? void 0 : wechat.appId,
|
|
360
|
+
TA_WECHAT_APP_SECRET: wechat === null || wechat === void 0 ? void 0 : wechat.appSecret,
|
|
361
|
+
TA_OIDC_ISSUER: oidc === null || oidc === void 0 ? void 0 : oidc.issuer,
|
|
362
|
+
TA_OIDC_CLIENT_ID: oidc === null || oidc === void 0 ? void 0 : oidc.clientId,
|
|
363
|
+
TA_OIDC_CLIENT_SECRET: oidc === null || oidc === void 0 ? void 0 : oidc.clientSecret,
|
|
364
|
+
TA_OIDC_NAME: oidc === null || oidc === void 0 ? void 0 : oidc.name,
|
|
365
|
+
};
|
|
366
|
+
const merged = { ...env };
|
|
367
|
+
for (const [key, value] of Object.entries(file)) {
|
|
368
|
+
if (typeof value === 'string' && value && !env[key]) {
|
|
369
|
+
merged[key] = value;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return merged;
|
|
373
|
+
}
|
|
374
|
+
SignInProviders.withConfig = withConfig;
|
|
375
|
+
/**
|
|
376
|
+
* GitHub by a code, for those asking to come in, when GitHub is not set up with its secret (which goes there and back
|
|
377
|
+
* instead): `TA_GITHUB_DEVICE` is `off`, or `<client id>` or `<client id>@<address of GitHub>` of an OAuth app of
|
|
378
|
+
* one's own with its device flow on; by default Ta's own, on GitHub.com.
|
|
379
|
+
*/
|
|
380
|
+
function device(env) {
|
|
381
|
+
var _a;
|
|
382
|
+
var _b;
|
|
383
|
+
const value = (_b = (_a = env.TA_GITHUB_DEVICE) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
|
|
384
|
+
if (value === 'off' || (env.TA_GITHUB_CLIENT_ID && env.TA_GITHUB_CLIENT_SECRET)) {
|
|
385
|
+
return undefined;
|
|
386
|
+
}
|
|
387
|
+
const at = value.indexOf('@');
|
|
388
|
+
const clientId = at < 0 ? value : value.slice(0, at);
|
|
389
|
+
const url = at < 0 ? undefined : value.slice(at + 1);
|
|
390
|
+
return new GitHubDeviceSignIn(clientId || GitHubDeviceSignIn.CLIENT_ID, GitHubSignIn.endpoints(url || undefined));
|
|
391
|
+
}
|
|
392
|
+
SignInProviders.device = device;
|
|
205
393
|
/**
|
|
206
394
|
* The providers the operator configured in the environment of ta serve: a provider is offered when it
|
|
207
395
|
* has its id and its secret.
|