@stigmer/cli 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/auth/browser.d.ts +7 -0
- package/auth/browser.d.ts.map +1 -0
- package/auth/browser.js +49 -0
- package/auth/browser.js.map +1 -0
- package/auth/callback-server.d.ts +8 -3
- package/auth/callback-server.d.ts.map +1 -1
- package/auth/callback-server.js +53 -19
- package/auth/callback-server.js.map +1 -1
- package/auth/device.d.ts +23 -0
- package/auth/device.d.ts.map +1 -0
- package/auth/device.js +119 -0
- package/auth/device.js.map +1 -0
- package/auth/index.d.ts +4 -3
- package/auth/index.d.ts.map +1 -1
- package/auth/index.js +4 -3
- package/auth/index.js.map +1 -1
- package/auth/login.d.ts +49 -1
- package/auth/login.d.ts.map +1 -1
- package/auth/login.js +161 -51
- package/auth/login.js.map +1 -1
- package/auth/oidc.d.ts +67 -0
- package/auth/oidc.d.ts.map +1 -0
- package/auth/oidc.js +213 -0
- package/auth/oidc.js.map +1 -0
- package/auth/token.d.ts +17 -23
- package/auth/token.d.ts.map +1 -1
- package/auth/token.js +51 -60
- package/auth/token.js.map +1 -1
- package/client/client.d.ts.map +1 -1
- package/client/client.js +4 -1
- package/client/client.js.map +1 -1
- package/client/current-organization.d.ts +5 -0
- package/client/current-organization.d.ts.map +1 -0
- package/client/current-organization.js +15 -0
- package/client/current-organization.js.map +1 -0
- package/commands/apikey/index.d.ts +16 -1
- package/commands/apikey/index.d.ts.map +1 -1
- package/commands/apikey/index.js +81 -0
- package/commands/apikey/index.js.map +1 -1
- package/commands/app-handover.d.ts +17 -0
- package/commands/app-handover.d.ts.map +1 -0
- package/commands/app-handover.js +155 -0
- package/commands/app-handover.js.map +1 -0
- package/commands/auth/index.d.ts.map +1 -1
- package/commands/auth/index.js +15 -9
- package/commands/auth/index.js.map +1 -1
- package/commands/auth/login.d.ts +7 -2
- package/commands/auth/login.d.ts.map +1 -1
- package/commands/auth/login.js +26 -23
- package/commands/auth/login.js.map +1 -1
- package/commands/auth/whoami.d.ts +5 -0
- package/commands/auth/whoami.d.ts.map +1 -1
- package/commands/auth/whoami.js +13 -1
- package/commands/auth/whoami.js.map +1 -1
- package/commands/coding-agent.d.ts +5 -0
- package/commands/coding-agent.d.ts.map +1 -0
- package/commands/coding-agent.js +30 -0
- package/commands/coding-agent.js.map +1 -0
- package/commands/config/backend.js +20 -6
- package/commands/config/backend.js.map +1 -1
- package/commands/embedding.d.ts +28 -0
- package/commands/embedding.d.ts.map +1 -0
- package/commands/embedding.js +170 -0
- package/commands/embedding.js.map +1 -0
- package/commands/example.d.ts +13 -0
- package/commands/example.d.ts.map +1 -0
- package/commands/example.js +126 -0
- package/commands/example.js.map +1 -0
- package/commands/help.d.ts.map +1 -1
- package/commands/help.js +16 -3
- package/commands/help.js.map +1 -1
- package/commands/load-test/burst.d.ts +64 -0
- package/commands/load-test/burst.d.ts.map +1 -0
- package/commands/load-test/burst.js +202 -0
- package/commands/load-test/burst.js.map +1 -0
- package/commands/load-test/index.d.ts +37 -0
- package/commands/load-test/index.d.ts.map +1 -0
- package/commands/load-test/index.js +154 -0
- package/commands/load-test/index.js.map +1 -0
- package/commands/load-test/report.d.ts +98 -0
- package/commands/load-test/report.d.ts.map +1 -0
- package/commands/load-test/report.js +210 -0
- package/commands/load-test/report.js.map +1 -0
- package/commands/mcp-server.d.ts +3 -3
- package/commands/mcp-server.d.ts.map +1 -1
- package/commands/mcp-server.js +4 -4
- package/commands/mcp-server.js.map +1 -1
- package/commands/setup.d.ts +17 -0
- package/commands/setup.d.ts.map +1 -1
- package/commands/setup.js +71 -1
- package/commands/setup.js.map +1 -1
- package/commands/up.d.ts.map +1 -1
- package/commands/up.js +67 -9
- package/commands/up.js.map +1 -1
- package/commands/usage.d.ts +15 -0
- package/commands/usage.d.ts.map +1 -1
- package/commands/usage.js +52 -2
- package/commands/usage.js.map +1 -1
- package/config/config.d.ts +14 -7
- package/config/config.d.ts.map +1 -1
- package/config/config.js +5 -1
- package/config/config.js.map +1 -1
- package/config/index.d.ts +1 -1
- package/config/index.d.ts.map +1 -1
- package/config/index.js +1 -1
- package/config/index.js.map +1 -1
- package/config/resolve.d.ts +1 -1
- package/config/resolve.d.ts.map +1 -1
- package/config/resolve.js +6 -3
- package/config/resolve.js.map +1 -1
- package/errors/classify.d.ts.map +1 -1
- package/errors/classify.js +10 -1
- package/errors/classify.js.map +1 -1
- package/errors/cli-exit-error.d.ts +3 -1
- package/errors/cli-exit-error.d.ts.map +1 -1
- package/errors/cli-exit-error.js +6 -2
- package/errors/cli-exit-error.js.map +1 -1
- package/errors/handle.d.ts +32 -5
- package/errors/handle.d.ts.map +1 -1
- package/errors/handle.js +67 -8
- package/errors/handle.js.map +1 -1
- package/local/daemon/components.d.ts +28 -1
- package/local/daemon/components.d.ts.map +1 -1
- package/local/daemon/components.js +64 -2
- package/local/daemon/components.js.map +1 -1
- package/local/daemon/host.d.ts.map +1 -1
- package/local/daemon/host.js +6 -2
- package/local/daemon/host.js.map +1 -1
- package/local/daemon/launch.d.ts +12 -4
- package/local/daemon/launch.d.ts.map +1 -1
- package/local/daemon/launch.js +49 -16
- package/local/daemon/launch.js.map +1 -1
- package/local/daemon/types.d.ts +9 -1
- package/local/daemon/types.d.ts.map +1 -1
- package/local/key-check.d.ts +20 -0
- package/local/key-check.d.ts.map +1 -0
- package/local/key-check.js +45 -0
- package/local/key-check.js.map +1 -0
- package/local/model-key-step.d.ts +63 -0
- package/local/model-key-step.d.ts.map +1 -0
- package/local/model-key-step.js +133 -0
- package/local/model-key-step.js.map +1 -0
- package/local/setup/prompt.d.ts.map +1 -1
- package/local/setup/prompt.js +22 -18
- package/local/setup/prompt.js.map +1 -1
- package/local/setup/wizard.d.ts +10 -0
- package/local/setup/wizard.d.ts.map +1 -1
- package/local/setup/wizard.js +40 -17
- package/local/setup/wizard.js.map +1 -1
- package/local/state/lock.d.ts.map +1 -1
- package/local/state/lock.js +123 -36
- package/local/state/lock.js.map +1 -1
- package/local/state/pidfile.d.ts +4 -0
- package/local/state/pidfile.d.ts.map +1 -1
- package/local/state/pidfile.js +12 -3
- package/local/state/pidfile.js.map +1 -1
- package/package.json +12 -9
- package/program.d.ts.map +1 -1
- package/program.js +10 -0
- package/program.js.map +1 -1
- package/resources/get.js +1 -1
- package/resources/get.js.map +1 -1
- package/resources/run/stream.d.ts.map +1 -1
- package/resources/run/stream.js +2 -1
- package/resources/run/stream.js.map +1 -1
- package/resources/stream/render-plaintext.d.ts +3 -0
- package/resources/stream/render-plaintext.d.ts.map +1 -1
- package/resources/stream/render-plaintext.js +20 -2
- package/resources/stream/render-plaintext.js.map +1 -1
- package/resources/usage.d.ts +8 -0
- package/resources/usage.d.ts.map +1 -1
- package/resources/usage.js +37 -0
- package/resources/usage.js.map +1 -1
- package/runtime.d.ts +9 -0
- package/runtime.d.ts.map +1 -1
- package/runtime.js +12 -1
- package/runtime.js.map +1 -1
- package/src/auth/browser.ts +57 -0
- package/src/auth/callback-server.ts +58 -22
- package/src/auth/device.ts +151 -0
- package/src/auth/index.ts +4 -3
- package/src/auth/login.ts +243 -67
- package/src/auth/oidc.ts +270 -0
- package/src/auth/token.ts +53 -90
- package/src/client/client.ts +4 -1
- package/src/client/current-organization.ts +27 -0
- package/src/commands/apikey/index.ts +85 -0
- package/src/commands/app-handover.ts +188 -0
- package/src/commands/auth/index.ts +16 -10
- package/src/commands/auth/login.ts +30 -23
- package/src/commands/auth/whoami.ts +16 -1
- package/src/commands/coding-agent.ts +33 -0
- package/src/commands/config/backend.ts +20 -6
- package/src/commands/embedding.ts +209 -0
- package/src/commands/example.ts +146 -0
- package/src/commands/help.ts +16 -3
- package/src/commands/load-test/burst.ts +291 -0
- package/src/commands/load-test/index.ts +183 -0
- package/src/commands/load-test/report.ts +302 -0
- package/src/commands/mcp-server.ts +5 -5
- package/src/commands/setup.ts +76 -2
- package/src/commands/up.ts +76 -10
- package/src/commands/usage.ts +55 -2
- package/src/config/config.ts +18 -8
- package/src/config/index.ts +1 -0
- package/src/config/resolve.ts +5 -3
- package/src/errors/classify.ts +10 -1
- package/src/errors/cli-exit-error.ts +6 -2
- package/src/errors/handle.ts +74 -8
- package/src/local/daemon/components.ts +66 -2
- package/src/local/daemon/host.ts +6 -2
- package/src/local/daemon/launch.ts +51 -16
- package/src/local/daemon/types.ts +9 -1
- package/src/local/key-check.ts +61 -0
- package/src/local/model-key-step.ts +164 -0
- package/src/local/setup/prompt.ts +22 -18
- package/src/local/setup/wizard.ts +45 -18
- package/src/local/state/lock.ts +116 -35
- package/src/local/state/pidfile.ts +14 -3
- package/src/program.ts +10 -0
- package/src/resources/get.ts +1 -1
- package/src/resources/run/stream.ts +2 -1
- package/src/resources/stream/render-plaintext.ts +20 -2
- package/src/resources/usage.ts +42 -0
- package/src/runtime.ts +17 -1
- package/auth/auth0.d.ts +0 -19
- package/auth/auth0.d.ts.map +0 -1
- package/auth/auth0.js +0 -39
- package/auth/auth0.js.map +0 -1
- package/src/auth/auth0.ts +0 -43
package/auth/login.js
CHANGED
|
@@ -1,81 +1,191 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Signing a person in to the server the CLI points at.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
3
|
+
// The server says how, as it does for the desktop app: `getServerInfo()`'s
|
|
4
|
+
// `native_sign_in` names the issuer, the audience and the public native
|
|
5
|
+
// client. Nothing about any provider is compiled in. The flow:
|
|
6
|
+
// 1. The target: the active named backend, or, from the local daemon
|
|
7
|
+
// (which trusts every caller), the reserved "cloud" entry, created at
|
|
8
|
+
// Stigmer Cloud's address when it is missing.
|
|
9
|
+
// 2. Ask that server how it signs people in. One that trusts every caller
|
|
10
|
+
// has nothing to sign in to; one that signs people in but announces no
|
|
11
|
+
// native client is not set up for installed apps, and the API key is the
|
|
12
|
+
// way in. A provider on another site than the server is named and
|
|
13
|
+
// refused until the person says `--trust-provider` (oidc.ts says why).
|
|
14
|
+
// 3. Read the issuer's discovery document for its endpoints.
|
|
15
|
+
// 4. Sign in through the person's browser (Authorization Code with S256
|
|
16
|
+
// PKCE, the callback on 127.0.0.1:17234-17236, the first free), or, with
|
|
17
|
+
// `--device` or where no browser can open and the issuer offers it, with
|
|
18
|
+
// a code typed on any device (device.ts).
|
|
19
|
+
// 5. Store the token set in that backend's entry beside the issuer and the
|
|
20
|
+
// client it came from, so a refresh goes back to the same provider
|
|
21
|
+
// (token.ts), and make that backend the active one.
|
|
9
22
|
//
|
|
10
|
-
// Progress goes to stderr; the command layer renders the final result.
|
|
11
|
-
|
|
23
|
+
// Progress goes to stderr; the command layer renders the final result. The
|
|
24
|
+
// address is printed before the CLI waits, so a coding agent running this in
|
|
25
|
+
// the background can hand it to the person.
|
|
26
|
+
import { createBackendClient } from "../client/index.js";
|
|
12
27
|
import { CLOUD_BACKEND_NAME, activeBackend, load, save, } from "../config/index.js";
|
|
28
|
+
import { DEFAULT_CLOUD_ENDPOINT } from "../config/resolve.js";
|
|
13
29
|
import { CliExitError, ExitCode } from "../errors/index.js";
|
|
14
30
|
import { log } from "../logger.js";
|
|
15
|
-
import {
|
|
31
|
+
import { canOpenBrowser, openBrowser } from "./browser.js";
|
|
16
32
|
import { CallbackServer } from "./callback-server.js";
|
|
33
|
+
import { deviceInstructions, pollDeviceToken, realTiming, requestDeviceCode } from "./device.js";
|
|
34
|
+
import { authorizeUrl, discover, hostOf, postTokenForm, providerOnServersSite, } from "./oidc.js";
|
|
17
35
|
import { challengeS256, generateState, generateVerifier } from "./pkce.js";
|
|
18
|
-
import { exchangeCode } from "./token.js";
|
|
19
36
|
const LOGIN_TIMEOUT_MS = 5 * 60 * 1000;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
/** The loopback callbacks an operator registers for the native client. */
|
|
38
|
+
export const LOOPBACK_PORTS = [17234, 17235, 17236];
|
|
39
|
+
export const CALLBACK_PATH = "/auth/callback";
|
|
40
|
+
export const defaultLoginDeps = {
|
|
41
|
+
readServerSignIn: readServerSignIn,
|
|
42
|
+
openBrowser: (url) => openBrowser(url),
|
|
43
|
+
canOpenBrowser: () => canOpenBrowser(),
|
|
44
|
+
progress: (text) => process.stderr.write(text),
|
|
45
|
+
timing: realTiming,
|
|
46
|
+
ports: LOOPBACK_PORTS,
|
|
47
|
+
timeoutMs: LOGIN_TIMEOUT_MS,
|
|
48
|
+
};
|
|
49
|
+
export async function login(options = {}, deps = defaultLoginDeps) {
|
|
50
|
+
const target = signInTarget(load());
|
|
51
|
+
const info = await deps.readServerSignIn(target.config);
|
|
52
|
+
const signIn = admitSignIn(target, info, options);
|
|
53
|
+
const discovery = await discover(signIn.issuer);
|
|
54
|
+
const useDevice = options.device === true || (!deps.canOpenBrowser() && discovery.deviceAuthorizationEndpoint !== undefined);
|
|
55
|
+
const tokens = useDevice
|
|
56
|
+
? await signInWithCode(discovery, signIn, deps)
|
|
57
|
+
: await signInWithBrowser(discovery, signIn, target.address, deps);
|
|
58
|
+
persist(target, signIn, tokens);
|
|
59
|
+
return { backendName: target.name, type: target.entry.type, address: target.address, provider: hostOf(signIn.issuer) };
|
|
60
|
+
}
|
|
61
|
+
/** The backend this sign-in is for, and the address its server answers on. */
|
|
62
|
+
export function signInTarget(config) {
|
|
63
|
+
const active = activeBackend(config);
|
|
64
|
+
const name = active.entry === undefined ? CLOUD_BACKEND_NAME : active.name;
|
|
65
|
+
const entry = active.entry ?? config.backends?.[CLOUD_BACKEND_NAME] ?? { type: "cloud" };
|
|
66
|
+
const address = entry.endpoint !== undefined && entry.endpoint !== ""
|
|
67
|
+
? entry.endpoint
|
|
68
|
+
: entry.type === "cloud"
|
|
69
|
+
? DEFAULT_CLOUD_ENDPOINT
|
|
70
|
+
: "";
|
|
71
|
+
if (address === "") {
|
|
72
|
+
throw new CliExitError(`backend "${name}" has no endpoint configured`, ExitCode.Usage, [
|
|
73
|
+
`Re-add it with one: stigmer config backend add ${name} --endpoint <host:port>`,
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
const override = process.env.STIGMER_SERVER_ADDRESS;
|
|
77
|
+
if (override !== undefined && override !== "" && override !== address) {
|
|
78
|
+
throw new CliExitError(`STIGMER_SERVER_ADDRESS points at ${override}, but the sign-in is for backend "${name}" at ${address}`, ExitCode.Usage, ["Unset STIGMER_SERVER_ADDRESS, or add that server as a backend and use it:",
|
|
79
|
+
" stigmer config backend add <name> --endpoint <host:port>",
|
|
80
|
+
" stigmer config backend use <name>"]);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
name,
|
|
84
|
+
entry,
|
|
85
|
+
address,
|
|
86
|
+
config: { ...config, backends: { ...config.backends, [name]: entry }, current_backend: name },
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** The server's announced sign-in, or the refusal that fits what it answered. */
|
|
90
|
+
export function admitSignIn(target, info, options) {
|
|
91
|
+
if (info.authenticationRequired === false) {
|
|
92
|
+
throw new CliExitError(`the server at ${target.address} trusts every caller: there is nothing to sign in to`, ExitCode.Usage, [
|
|
93
|
+
"Commands against it work as they are, e.g.: stigmer list agents",
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
const signIn = info.nativeSignIn;
|
|
97
|
+
if (signIn === undefined || signIn.issuer === "" || signIn.clientId === "") {
|
|
98
|
+
throw new CliExitError(`the server at ${target.address} signs people in, but isn't set up for this app`, ExitCode.Auth, [
|
|
99
|
+
"Its operator registers a native client for installed apps (the desktop app and this CLI).",
|
|
100
|
+
"Until then, sign in to its console, create an API key, and add it:",
|
|
101
|
+
` stigmer config backend add ${target.name} --endpoint ${target.address} --api-key <key>`,
|
|
35
102
|
]);
|
|
36
103
|
}
|
|
104
|
+
if (!providerOnServersSite(target.address, signIn.issuer) && options.trustProvider !== true) {
|
|
105
|
+
throw new CliExitError(`${hostOf(target.address)} signs people in at ${hostOf(signIn.issuer)}, on another site`, ExitCode.Auth, [
|
|
106
|
+
"A server can name another site's sign-in to collect tokens that site's servers accept.",
|
|
107
|
+
"If you trust this server and its provider, run: stigmer auth login --trust-provider",
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
return signIn;
|
|
111
|
+
}
|
|
112
|
+
async function signInWithBrowser(discovery, signIn, address, deps) {
|
|
37
113
|
const verifier = generateVerifier();
|
|
38
|
-
const codeChallenge = challengeS256(verifier);
|
|
39
114
|
const state = generateState();
|
|
40
|
-
const server = new CallbackServer(
|
|
115
|
+
const server = new CallbackServer(deps.ports, CALLBACK_PATH);
|
|
41
116
|
await server.start();
|
|
42
117
|
try {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
118
|
+
const url = authorizeUrl({
|
|
119
|
+
discovery,
|
|
120
|
+
signIn,
|
|
121
|
+
redirectUri: server.redirectUri,
|
|
122
|
+
state,
|
|
123
|
+
codeChallenge: challengeS256(verifier),
|
|
124
|
+
});
|
|
125
|
+
deps.progress(`Signing in to ${hostOf(address)} at ${hostOf(signIn.issuer)}. Opening your browser...\n`);
|
|
126
|
+
deps.progress(`If it doesn't open, visit:\n${url}\n\n`);
|
|
46
127
|
try {
|
|
47
|
-
await
|
|
128
|
+
await deps.openBrowser(url);
|
|
48
129
|
}
|
|
49
130
|
catch (err) {
|
|
50
131
|
log.debug(`failed to open browser automatically: ${err.message}`);
|
|
51
|
-
|
|
132
|
+
deps.progress("Could not open the browser automatically. Please open the address above.\n");
|
|
52
133
|
}
|
|
53
|
-
const callback = await server.waitForCallback(
|
|
134
|
+
const callback = await server.waitForCallback(deps.timeoutMs);
|
|
54
135
|
if (callback.state !== state) {
|
|
55
136
|
throw new CliExitError("OAuth state mismatch — possible CSRF attack, aborting login", ExitCode.Auth);
|
|
56
137
|
}
|
|
57
|
-
|
|
138
|
+
return await postTokenForm(discovery.tokenEndpoint, {
|
|
139
|
+
grant_type: "authorization_code",
|
|
140
|
+
client_id: signIn.clientId,
|
|
58
141
|
code: callback.code,
|
|
59
|
-
|
|
142
|
+
redirect_uri: server.redirectUri,
|
|
143
|
+
code_verifier: verifier,
|
|
60
144
|
});
|
|
61
|
-
const config = load();
|
|
62
|
-
const active = activeBackend(config);
|
|
63
|
-
// A cloud-type backend keeps its own login; anything else (the local
|
|
64
|
-
// daemon) lands on the reserved "cloud" entry and switches to it.
|
|
65
|
-
const targetName = active.entry?.type === "cloud" ? active.name : CLOUD_BACKEND_NAME;
|
|
66
|
-
const backends = (config.backends ??= {});
|
|
67
|
-
backends[targetName] = {
|
|
68
|
-
...(backends[targetName] ?? { type: "cloud" }),
|
|
69
|
-
type: "cloud",
|
|
70
|
-
token: tokens.accessToken,
|
|
71
|
-
refresh_token: tokens.refreshToken,
|
|
72
|
-
token_expiry: tokens.expiresAt,
|
|
73
|
-
};
|
|
74
|
-
config.current_backend = targetName;
|
|
75
|
-
save(config);
|
|
76
145
|
}
|
|
77
146
|
finally {
|
|
78
147
|
await server.shutdown();
|
|
79
148
|
}
|
|
80
149
|
}
|
|
150
|
+
async function signInWithCode(discovery, signIn, deps) {
|
|
151
|
+
const code = await requestDeviceCode(discovery, signIn);
|
|
152
|
+
deps.progress(deviceInstructions(code));
|
|
153
|
+
return pollDeviceToken(discovery, signIn, code, deps.timing);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Store the token set in the backend's entry, as the file is on disk now (a
|
|
157
|
+
* command saved while the browser was open survives), and make it active;
|
|
158
|
+
* refused when the entry was re-pointed at another server meanwhile, since
|
|
159
|
+
* the token would then be sent there.
|
|
160
|
+
*/
|
|
161
|
+
function persist(target, signIn, tokens) {
|
|
162
|
+
const { name, entry } = target;
|
|
163
|
+
const config = load();
|
|
164
|
+
const backends = (config.backends ??= {});
|
|
165
|
+
const onDisk = backends[name];
|
|
166
|
+
if (onDisk !== undefined && signInTarget({ ...config, current_backend: name }).address !== target.address) {
|
|
167
|
+
throw new CliExitError(`backend "${name}" was pointed at another server while you signed in; nothing was saved`, ExitCode.Auth, ["Sign in again: stigmer auth login"]);
|
|
168
|
+
}
|
|
169
|
+
backends[name] = {
|
|
170
|
+
...(onDisk ?? entry),
|
|
171
|
+
token: tokens.accessToken,
|
|
172
|
+
refresh_token: tokens.refreshToken,
|
|
173
|
+
token_expiry: tokens.expiresAt,
|
|
174
|
+
oidc_issuer: signIn.issuer,
|
|
175
|
+
oidc_client_id: signIn.clientId,
|
|
176
|
+
};
|
|
177
|
+
config.current_backend = name;
|
|
178
|
+
save(config);
|
|
179
|
+
}
|
|
180
|
+
/** Ask the target's server how it signs people in, with no credential. */
|
|
181
|
+
async function readServerSignIn(config) {
|
|
182
|
+
const client = createBackendClient({ config, getAccessToken: async () => null });
|
|
183
|
+
await client.connect();
|
|
184
|
+
const info = await client.serverInfo();
|
|
185
|
+
const native = info.nativeSignIn;
|
|
186
|
+
return {
|
|
187
|
+
authenticationRequired: info.authenticationRequired,
|
|
188
|
+
nativeSignIn: native === undefined ? undefined : { issuer: native.issuer, audience: native.audience, clientId: native.clientId },
|
|
189
|
+
};
|
|
190
|
+
}
|
|
81
191
|
//# sourceMappingURL=login.js.map
|
package/auth/login.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.js","sourceRoot":"","sources":["../src/auth/login.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../src/auth/login.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,EAAE;AACF,2EAA2E;AAC3E,wEAAwE;AACxE,+DAA+D;AAC/D,uEAAuE;AACvE,2EAA2E;AAC3E,mDAAmD;AACnD,4EAA4E;AAC5E,4EAA4E;AAC5E,8EAA8E;AAC9E,uEAAuE;AACvE,4EAA4E;AAC5E,+DAA+D;AAC/D,0EAA0E;AAC1E,8EAA8E;AAC9E,8EAA8E;AA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MAAM,CAAC,QAAQ;KAChC,CAAC;IACF,MAAM,CAAC,eAAe,GAAG,IAAI,CAAC;IAC9B,IAAI,CAAC,MAAM,CAAC,CAAC;AACf,CAAC;AAED,0EAA0E;AAC1E,KAAK,UAAU,gBAAgB,CAAC,MAAc;IAC5C,MAAM,MAAM,GAAG,mBAAmB,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;IACjF,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IACvB,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;IACvC,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC;IACjC,OAAO;QACL,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;QACnD,YAAY,EACV,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE;KACrH,CAAC;AACJ,CAAC"}
|
package/auth/oidc.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** What a server announces for an installed app's sign-in. */
|
|
2
|
+
export interface NativeSignIn {
|
|
3
|
+
readonly issuer: string;
|
|
4
|
+
readonly audience: string;
|
|
5
|
+
readonly clientId: string;
|
|
6
|
+
}
|
|
7
|
+
/** The endpoints an issuer's discovery document names. */
|
|
8
|
+
export interface Discovery {
|
|
9
|
+
readonly authorizationEndpoint: string;
|
|
10
|
+
readonly tokenEndpoint: string;
|
|
11
|
+
/** RFC 8628's endpoint, when the issuer offers the device grant. */
|
|
12
|
+
readonly deviceAuthorizationEndpoint?: string;
|
|
13
|
+
}
|
|
14
|
+
/** A provider's answer to a token request. */
|
|
15
|
+
export interface TokenSet {
|
|
16
|
+
readonly accessToken: string;
|
|
17
|
+
/** Present when `offline_access` was granted; may rotate on refresh. */
|
|
18
|
+
readonly refreshToken?: string;
|
|
19
|
+
/** Absolute expiry as an RFC 3339 string, derived from `expires_in`. */
|
|
20
|
+
readonly expiresAt?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const SCOPES = "openid profile email offline_access";
|
|
23
|
+
/** The device grant's type (RFC 8628, section 3.4). */
|
|
24
|
+
export declare const DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
25
|
+
/** Where an issuer publishes its discovery document. */
|
|
26
|
+
export declare function discoveryUrl(issuer: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* The endpoints a discovery document names, once it is the announced issuer's
|
|
29
|
+
* own and every endpoint is one the CLI may send a person or a credential to.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readDiscovery(expectedIssuer: string, body: unknown): Discovery;
|
|
32
|
+
/** The issuer's endpoints, read once per process. A failed read is not kept. */
|
|
33
|
+
export declare function discover(issuer: string): Promise<Discovery>;
|
|
34
|
+
/** Forget every issuer read so far (tests). */
|
|
35
|
+
export declare function forgetDiscovery(): void;
|
|
36
|
+
/** Whether `raw` is `https`, or `http` on this machine. */
|
|
37
|
+
export declare function isTrustedEndpoint(raw: string): boolean;
|
|
38
|
+
/** The host of a gRPC address (`host:port`) or a URL. */
|
|
39
|
+
export declare function hostOf(address: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Whether `issuer` sits on the server's own site: both on this computer, the
|
|
42
|
+
* same host, or the same registrable domain (`api.acme.co.uk` and
|
|
43
|
+
* `id.acme.co.uk`, never two names under a public suffix).
|
|
44
|
+
*/
|
|
45
|
+
export declare function providerOnServersSite(serverAddress: string, issuer: string): boolean;
|
|
46
|
+
/** The authorize address for the PKCE Authorization Code flow. */
|
|
47
|
+
export declare function authorizeUrl(params: {
|
|
48
|
+
readonly discovery: Discovery;
|
|
49
|
+
readonly signIn: NativeSignIn;
|
|
50
|
+
readonly redirectUri: string;
|
|
51
|
+
readonly state: string;
|
|
52
|
+
readonly codeChallenge: string;
|
|
53
|
+
}): string;
|
|
54
|
+
/** A provider's refusal: its error code and, when it gave them, its words. */
|
|
55
|
+
export declare class ProviderError extends Error {
|
|
56
|
+
readonly code: string;
|
|
57
|
+
readonly description: string | undefined;
|
|
58
|
+
readonly status: number;
|
|
59
|
+
constructor(code: string, description: string | undefined, status: number);
|
|
60
|
+
}
|
|
61
|
+
/** POST a form and answer the JSON body; a refusal throws {@link ProviderError}. */
|
|
62
|
+
export declare function postForm(endpoint: string, form: Record<string, string>): Promise<Record<string, unknown>>;
|
|
63
|
+
/** POST a token request and answer the token set; any refusal is an auth failure in the provider's words. */
|
|
64
|
+
export declare function postTokenForm(tokenEndpoint: string, form: Record<string, string>): Promise<TokenSet>;
|
|
65
|
+
/** Normalize a successful token response. */
|
|
66
|
+
export declare function tokenSetOf(body: Record<string, unknown>): TokenSet;
|
|
67
|
+
//# sourceMappingURL=oidc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc.d.ts","sourceRoot":"","sources":["../src/auth/oidc.ts"],"names":[],"mappings":"AA0BA,8DAA8D;AAC9D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,0DAA0D;AAC1D,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,oEAAoE;IACpE,QAAQ,CAAC,2BAA2B,CAAC,EAAE,MAAM,CAAC;CAC/C;AAED,8CAA8C;AAC9C,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,wEAAwE;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,MAAM,EACZ,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,MAAM,EAAE,MAAM;CAI1B;AAED,oFAAoF;AACpF,wBAAsB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAqB/G;AAED,6GAA6G;AAC7G,wBAAsB,aAAa,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAW1G;AAED,6CAA6C;AAC7C,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,QAAQ,CAYlE"}
|
package/auth/oidc.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// The identity provider a server names, read the way the desktop app reads it.
|
|
2
|
+
//
|
|
3
|
+
// A server that signs its callers in announces how an installed app signs a
|
|
4
|
+
// person in (`getServerInfo().native_sign_in`): the issuer, the audience its
|
|
5
|
+
// access tokens must carry and the public native client registered for
|
|
6
|
+
// installed apps. Nothing about any provider is built into the CLI. This module
|
|
7
|
+
// holds the parts every flow shares:
|
|
8
|
+
// - `discover`: the issuer's `/.well-known/openid-configuration`, whose
|
|
9
|
+
// `issuer` must equal the announced one exactly (the server's own reader
|
|
10
|
+
// holds the same rule) and whose endpoints must be `https`, or `http` on
|
|
11
|
+
// this machine; read once per process per issuer;
|
|
12
|
+
// - `providerOnServersSite`: whether the provider sits on the server's own
|
|
13
|
+
// site (the same registrable domain, by the Public Suffix List with its
|
|
14
|
+
// private section, so `evil.github.io` and `victim.github.io` are two
|
|
15
|
+
// sites; the same host; or both on this computer). A server the person was talked into
|
|
16
|
+
// adding could announce another server's provider to collect tokens that
|
|
17
|
+
// server accepts; a provider elsewhere is shown and needs the person's yes;
|
|
18
|
+
// - `authorizeUrl`: S256 PKCE, `state`, `openid profile email
|
|
19
|
+
// offline_access`, `audience` (Auth0 needs it to mint an access token for
|
|
20
|
+
// the API; other providers ignore it) and `prompt=login`;
|
|
21
|
+
// - `postTokenForm`: one form POST to a token or device endpoint, answered as
|
|
22
|
+
// a token set or as the provider's own error code and words.
|
|
23
|
+
import { getDomain } from "tldts";
|
|
24
|
+
import { CliExitError, ExitCode } from "../errors/index.js";
|
|
25
|
+
export const SCOPES = "openid profile email offline_access";
|
|
26
|
+
/** The device grant's type (RFC 8628, section 3.4). */
|
|
27
|
+
export const DEVICE_CODE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
28
|
+
const discovered = new Map();
|
|
29
|
+
/** Where an issuer publishes its discovery document. */
|
|
30
|
+
export function discoveryUrl(issuer) {
|
|
31
|
+
return `${issuer.replace(/\/+$/, "")}/.well-known/openid-configuration`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The endpoints a discovery document names, once it is the announced issuer's
|
|
35
|
+
* own and every endpoint is one the CLI may send a person or a credential to.
|
|
36
|
+
*/
|
|
37
|
+
export function readDiscovery(expectedIssuer, body) {
|
|
38
|
+
const document = (body ?? {});
|
|
39
|
+
const authorization = document.authorization_endpoint;
|
|
40
|
+
const token = document.token_endpoint;
|
|
41
|
+
if (typeof document.issuer !== "string" || typeof authorization !== "string" || typeof token !== "string") {
|
|
42
|
+
throw new CliExitError(`${expectedIssuer} published no OpenID Connect discovery document the CLI can read`, ExitCode.Auth);
|
|
43
|
+
}
|
|
44
|
+
if (document.issuer !== expectedIssuer) {
|
|
45
|
+
throw new CliExitError(`the sign-in provider says it is ${document.issuer}, but this server named ${expectedIssuer}`, ExitCode.Auth, ["Ask the server's operator to set the issuer exactly as the provider spells it."]);
|
|
46
|
+
}
|
|
47
|
+
const device = typeof document.device_authorization_endpoint === "string" ? document.device_authorization_endpoint : undefined;
|
|
48
|
+
for (const endpoint of [authorization, token, device]) {
|
|
49
|
+
if (endpoint !== undefined && !isTrustedEndpoint(endpoint)) {
|
|
50
|
+
throw new CliExitError(`the sign-in provider names ${endpoint}, which is not https`, ExitCode.Auth, ["The CLI signs in only over https, or http on this computer."]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
authorizationEndpoint: authorization,
|
|
55
|
+
tokenEndpoint: token,
|
|
56
|
+
...(device === undefined ? {} : { deviceAuthorizationEndpoint: device }),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** The issuer's endpoints, read once per process. A failed read is not kept. */
|
|
60
|
+
export function discover(issuer) {
|
|
61
|
+
let pending = discovered.get(issuer);
|
|
62
|
+
if (pending === undefined) {
|
|
63
|
+
pending = fetchDiscovery(issuer);
|
|
64
|
+
discovered.set(issuer, pending);
|
|
65
|
+
pending.catch(() => discovered.delete(issuer));
|
|
66
|
+
}
|
|
67
|
+
return pending;
|
|
68
|
+
}
|
|
69
|
+
/** Forget every issuer read so far (tests). */
|
|
70
|
+
export function forgetDiscovery() {
|
|
71
|
+
discovered.clear();
|
|
72
|
+
}
|
|
73
|
+
async function fetchDiscovery(issuer) {
|
|
74
|
+
if (!isTrustedEndpoint(issuer)) {
|
|
75
|
+
throw new CliExitError(`the server names the sign-in provider ${issuer}, which is not https`, ExitCode.Auth, [
|
|
76
|
+
"The CLI signs in only over https, or http on this computer.",
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
let response;
|
|
80
|
+
try {
|
|
81
|
+
response = await fetch(discoveryUrl(issuer));
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
throw new CliExitError(`failed to reach the sign-in provider ${issuer}: ${err.message}`, ExitCode.Connection);
|
|
85
|
+
}
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
throw new CliExitError(`the sign-in provider ${issuer} answered ${response.status} for its discovery document`, ExitCode.Auth);
|
|
88
|
+
}
|
|
89
|
+
return readDiscovery(issuer, await response.json().catch(() => undefined));
|
|
90
|
+
}
|
|
91
|
+
/** Whether `raw` is `https`, or `http` on this machine. */
|
|
92
|
+
export function isTrustedEndpoint(raw) {
|
|
93
|
+
let url;
|
|
94
|
+
try {
|
|
95
|
+
url = new URL(raw);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
if (url.protocol === "https:")
|
|
101
|
+
return url.hostname !== "";
|
|
102
|
+
return url.protocol === "http:" && isLoopbackHost(url.hostname);
|
|
103
|
+
}
|
|
104
|
+
function isLoopbackHost(hostname) {
|
|
105
|
+
const host = hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
106
|
+
return host === "localhost" || host === "::1" || /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(host);
|
|
107
|
+
}
|
|
108
|
+
/** The host of a gRPC address (`host:port`) or a URL. */
|
|
109
|
+
export function hostOf(address) {
|
|
110
|
+
const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(address) ? address : `http://${address}`;
|
|
111
|
+
try {
|
|
112
|
+
return new URL(withScheme).hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return "";
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Whether `issuer` sits on the server's own site: both on this computer, the
|
|
120
|
+
* same host, or the same registrable domain (`api.acme.co.uk` and
|
|
121
|
+
* `id.acme.co.uk`, never two names under a public suffix).
|
|
122
|
+
*/
|
|
123
|
+
export function providerOnServersSite(serverAddress, issuer) {
|
|
124
|
+
const server = hostOf(serverAddress);
|
|
125
|
+
const provider = hostOf(issuer);
|
|
126
|
+
if (server === "" || provider === "")
|
|
127
|
+
return false;
|
|
128
|
+
if (isLoopbackHost(server) && isLoopbackHost(provider))
|
|
129
|
+
return true;
|
|
130
|
+
if (server === provider)
|
|
131
|
+
return true;
|
|
132
|
+
// The private section too: hosting suffixes (github.io, fly.dev) give each
|
|
133
|
+
// tenant its own site, as the desktop app's check does.
|
|
134
|
+
const a = getDomain(server, { allowPrivateDomains: true });
|
|
135
|
+
const b = getDomain(provider, { allowPrivateDomains: true });
|
|
136
|
+
return a !== null && b !== null && a === b;
|
|
137
|
+
}
|
|
138
|
+
/** The authorize address for the PKCE Authorization Code flow. */
|
|
139
|
+
export function authorizeUrl(params) {
|
|
140
|
+
const url = new URL(params.discovery.authorizationEndpoint);
|
|
141
|
+
url.searchParams.set("response_type", "code");
|
|
142
|
+
url.searchParams.set("client_id", params.signIn.clientId);
|
|
143
|
+
url.searchParams.set("redirect_uri", params.redirectUri);
|
|
144
|
+
url.searchParams.set("scope", SCOPES);
|
|
145
|
+
url.searchParams.set("audience", params.signIn.audience);
|
|
146
|
+
url.searchParams.set("state", params.state);
|
|
147
|
+
url.searchParams.set("code_challenge", params.codeChallenge);
|
|
148
|
+
url.searchParams.set("code_challenge_method", "S256");
|
|
149
|
+
url.searchParams.set("prompt", "login");
|
|
150
|
+
return url.toString();
|
|
151
|
+
}
|
|
152
|
+
/** A provider's refusal: its error code and, when it gave them, its words. */
|
|
153
|
+
export class ProviderError extends Error {
|
|
154
|
+
code;
|
|
155
|
+
description;
|
|
156
|
+
status;
|
|
157
|
+
constructor(code, description, status) {
|
|
158
|
+
super(description === undefined || description === "" ? code : `${code}: ${description}`);
|
|
159
|
+
this.code = code;
|
|
160
|
+
this.description = description;
|
|
161
|
+
this.status = status;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/** POST a form and answer the JSON body; a refusal throws {@link ProviderError}. */
|
|
165
|
+
export async function postForm(endpoint, form) {
|
|
166
|
+
let response;
|
|
167
|
+
try {
|
|
168
|
+
response = await fetch(endpoint, {
|
|
169
|
+
method: "POST",
|
|
170
|
+
headers: { "content-type": "application/x-www-form-urlencoded", accept: "application/json" },
|
|
171
|
+
body: new URLSearchParams(form).toString(),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
throw new CliExitError(`failed to reach the sign-in provider: ${err.message}`, ExitCode.Connection);
|
|
176
|
+
}
|
|
177
|
+
const body = (await response.json().catch(() => ({})));
|
|
178
|
+
if (!response.ok) {
|
|
179
|
+
const code = typeof body.error === "string" ? body.error : `HTTP ${response.status}`;
|
|
180
|
+
const description = typeof body.error_description === "string" ? body.error_description : undefined;
|
|
181
|
+
throw new ProviderError(code, description, response.status);
|
|
182
|
+
}
|
|
183
|
+
return body;
|
|
184
|
+
}
|
|
185
|
+
/** POST a token request and answer the token set; any refusal is an auth failure in the provider's words. */
|
|
186
|
+
export async function postTokenForm(tokenEndpoint, form) {
|
|
187
|
+
let body;
|
|
188
|
+
try {
|
|
189
|
+
body = await postForm(tokenEndpoint, form);
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
if (err instanceof ProviderError) {
|
|
193
|
+
throw new CliExitError(`authentication failed: ${err.message}`, ExitCode.Auth);
|
|
194
|
+
}
|
|
195
|
+
throw err;
|
|
196
|
+
}
|
|
197
|
+
return tokenSetOf(body);
|
|
198
|
+
}
|
|
199
|
+
/** Normalize a successful token response. */
|
|
200
|
+
export function tokenSetOf(body) {
|
|
201
|
+
if (typeof body.access_token !== "string" || body.access_token === "") {
|
|
202
|
+
throw new CliExitError("authentication failed: the provider answered no access token", ExitCode.Auth);
|
|
203
|
+
}
|
|
204
|
+
const expiresIn = typeof body.expires_in === "number" ? body.expires_in : undefined;
|
|
205
|
+
return {
|
|
206
|
+
accessToken: body.access_token,
|
|
207
|
+
...(typeof body.refresh_token === "string" && body.refresh_token !== ""
|
|
208
|
+
? { refreshToken: body.refresh_token }
|
|
209
|
+
: {}),
|
|
210
|
+
...(expiresIn === undefined ? {} : { expiresAt: new Date(Date.now() + expiresIn * 1000).toISOString() }),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=oidc.js.map
|
package/auth/oidc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oidc.js","source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