@owlmeans/client-auth 0.1.18-rc.5 → 0.1.18-rc.50
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.md +282 -37
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/client-auth/SKILL.md +144 -21
- package/build/components/dispatcher/component.d.ts.map +1 -1
- package/build/components/dispatcher/component.js +23 -5
- package/build/components/dispatcher/component.js.map +1 -1
- package/build/entrypoints.d.ts +5 -0
- package/build/entrypoints.d.ts.map +1 -0
- package/build/entrypoints.js +7 -0
- package/build/entrypoints.js.map +1 -0
- package/build/helper.d.ts +2 -1
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +24 -3
- package/build/helper.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/login/adopt.d.ts +24 -0
- package/build/login/adopt.d.ts.map +1 -0
- package/build/login/adopt.js +28 -0
- package/build/login/adopt.js.map +1 -0
- package/build/login/consts.d.ts +49 -0
- package/build/login/consts.d.ts.map +1 -0
- package/build/login/consts.js +49 -0
- package/build/login/consts.js.map +1 -0
- package/build/login/credit.d.ts +24 -0
- package/build/login/credit.d.ts.map +1 -0
- package/build/login/credit.js +58 -0
- package/build/login/credit.js.map +1 -0
- package/build/login/env.d.ts +32 -0
- package/build/login/env.d.ts.map +1 -0
- package/build/login/env.js +84 -0
- package/build/login/env.js.map +1 -0
- package/build/login/flow.d.ts +20 -0
- package/build/login/flow.d.ts.map +1 -0
- package/build/login/flow.js +39 -0
- package/build/login/flow.js.map +1 -0
- package/build/login/hook.d.ts +37 -0
- package/build/login/hook.d.ts.map +1 -0
- package/build/login/hook.js +72 -0
- package/build/login/hook.js.map +1 -0
- package/build/login/i18n/be.json +41 -0
- package/build/login/i18n/de.json +41 -0
- package/build/login/i18n/en.json +41 -0
- package/build/login/i18n/es.json +41 -0
- package/build/login/i18n/fr.json +41 -0
- package/build/login/i18n/pl.json +41 -0
- package/build/login/i18n/ru.json +41 -0
- package/build/login/i18n/uk.json +41 -0
- package/build/login/i18n.d.ts +2 -0
- package/build/login/i18n.d.ts.map +1 -0
- package/build/login/i18n.js +27 -0
- package/build/login/i18n.js.map +1 -0
- package/build/login/index.d.ts +17 -0
- package/build/login/index.d.ts.map +1 -0
- package/build/login/index.js +17 -0
- package/build/login/index.js.map +1 -0
- package/build/login/land.d.ts +46 -0
- package/build/login/land.d.ts.map +1 -0
- package/build/login/land.js +166 -0
- package/build/login/land.js.map +1 -0
- package/build/login/methods.d.ts +25 -0
- package/build/login/methods.d.ts.map +1 -0
- package/build/login/methods.js +97 -0
- package/build/login/methods.js.map +1 -0
- package/build/login/resume.d.ts +30 -0
- package/build/login/resume.d.ts.map +1 -0
- package/build/login/resume.js +57 -0
- package/build/login/resume.js.map +1 -0
- package/build/login/screen.d.ts +17 -0
- package/build/login/screen.d.ts.map +1 -0
- package/build/login/screen.js +81 -0
- package/build/login/screen.js.map +1 -0
- package/build/login/service.d.ts +31 -0
- package/build/login/service.d.ts.map +1 -0
- package/build/login/service.js +168 -0
- package/build/login/service.js.map +1 -0
- package/build/login/surrogate.d.ts +20 -0
- package/build/login/surrogate.d.ts.map +1 -0
- package/build/login/surrogate.js +33 -0
- package/build/login/surrogate.js.map +1 -0
- package/build/login/terms-config.d.ts +59 -0
- package/build/login/terms-config.d.ts.map +1 -0
- package/build/login/terms-config.js +2 -0
- package/build/login/terms-config.js.map +1 -0
- package/build/login/terms.d.ts +102 -0
- package/build/login/terms.d.ts.map +1 -0
- package/build/login/terms.js +253 -0
- package/build/login/terms.js.map +1 -0
- package/build/login/types.d.ts +349 -0
- package/build/login/types.d.ts.map +1 -0
- package/build/login/types.js +31 -0
- package/build/login/types.js.map +1 -0
- package/build/manager/components/authentication/control.js +3 -3
- package/build/manager/components/authentication/control.js.map +1 -1
- package/build/manager/components/authentication/types.d.ts +2 -2
- package/build/manager/components/authentication/types.d.ts.map +1 -1
- package/build/manager/components/tunnel-consumer.js +2 -2
- package/build/manager/components/tunnel-consumer.js.map +1 -1
- package/build/manager/entrypoints.d.ts +3 -0
- package/build/manager/entrypoints.d.ts.map +1 -0
- package/build/manager/entrypoints.js +17 -0
- package/build/manager/entrypoints.js.map +1 -0
- package/build/manager/plugins/basic-ed25519.d.ts.map +1 -1
- package/build/manager/plugins/basic-ed25519.js +5 -0
- package/build/manager/plugins/basic-ed25519.js.map +1 -1
- package/build/manager/plugins/exports.d.ts +2 -0
- package/build/manager/plugins/exports.d.ts.map +1 -1
- package/build/manager/plugins/exports.js +2 -0
- package/build/manager/plugins/exports.js.map +1 -1
- package/build/manager/plugins/index.d.ts +1 -5
- package/build/manager/plugins/index.d.ts.map +1 -1
- package/build/manager/plugins/index.js +9 -1
- package/build/manager/plugins/index.js.map +1 -1
- package/build/manager/plugins/methods.d.ts +6 -0
- package/build/manager/plugins/methods.d.ts.map +1 -0
- package/build/manager/plugins/methods.js +65 -0
- package/build/manager/plugins/methods.js.map +1 -0
- package/build/manager/plugins/re-captcha.d.ts.map +1 -1
- package/build/manager/plugins/re-captcha.js +5 -0
- package/build/manager/plugins/re-captcha.js.map +1 -1
- package/build/manager/plugins/registry.d.ts +20 -0
- package/build/manager/plugins/registry.d.ts.map +1 -0
- package/build/manager/plugins/registry.js +19 -0
- package/build/manager/plugins/registry.js.map +1 -0
- package/build/manager/plugins/tunnel-consumer.d.ts.map +1 -1
- package/build/manager/plugins/tunnel-consumer.js +8 -1
- package/build/manager/plugins/tunnel-consumer.js.map +1 -1
- package/build/manager/plugins/types.d.ts +53 -0
- package/build/manager/plugins/types.d.ts.map +1 -1
- package/build/service.js +1 -1
- package/build/service.js.map +1 -1
- package/package.json +36 -27
- package/src/components/dispatcher/component.tsx +31 -5
- package/src/entrypoints.ts +10 -0
- package/src/helper.ts +26 -3
- package/src/index.ts +1 -1
- package/src/login/adopt.ts +31 -0
- package/src/login/consts.ts +64 -0
- package/src/login/credit.ts +75 -0
- package/src/login/env.ts +86 -0
- package/src/login/flow.ts +44 -0
- package/src/login/hook.ts +80 -0
- package/src/login/i18n/be.json +41 -0
- package/src/login/i18n/de.json +41 -0
- package/src/login/i18n/en.json +41 -0
- package/src/login/i18n/es.json +41 -0
- package/src/login/i18n/fr.json +41 -0
- package/src/login/i18n/pl.json +41 -0
- package/src/login/i18n/ru.json +41 -0
- package/src/login/i18n/uk.json +41 -0
- package/src/login/i18n.ts +28 -0
- package/src/login/index.ts +17 -0
- package/src/login/land.ts +196 -0
- package/src/login/methods.ts +113 -0
- package/src/login/resume.ts +58 -0
- package/src/login/screen.tsx +160 -0
- package/src/login/service.ts +219 -0
- package/src/login/surrogate.ts +45 -0
- package/src/login/terms-config.ts +49 -0
- package/src/login/terms.ts +354 -0
- package/src/login/types.ts +377 -0
- package/src/manager/README.md +37 -80
- package/src/manager/components/authentication/control.ts +3 -3
- package/src/manager/components/authentication/types.ts +2 -2
- package/src/manager/components/tunnel-consumer.tsx +2 -2
- package/src/manager/entrypoints.ts +18 -0
- package/src/manager/plugins/basic-ed25519.tsx +7 -0
- package/src/manager/plugins/exports.ts +2 -0
- package/src/manager/plugins/index.ts +10 -4
- package/src/manager/plugins/methods.ts +74 -0
- package/src/manager/plugins/re-captcha.tsx +7 -0
- package/src/manager/plugins/registry.ts +26 -0
- package/src/manager/plugins/tunnel-consumer.tsx +10 -1
- package/src/manager/plugins/types.ts +54 -0
- package/src/service.ts +1 -1
- package/tests/context.ts +1 -2
- package/tests/i18n.spec.ts +68 -0
- package/tests/land.spec.ts +294 -0
- package/tests/login.spec.ts +332 -0
- package/tests/terms-deferred.spec.ts +65 -0
- package/tests/terms.spec.ts +256 -0
- package/build/.gitkeep +0 -0
- package/build/manager/modules.d.ts +0 -2
- package/build/manager/modules.d.ts.map +0 -1
- package/build/manager/modules.js +0 -16
- package/build/manager/modules.js.map +0 -1
- package/build/modules.d.ts +0 -4
- package/build/modules.d.ts.map +0 -1
- package/build/modules.js +0 -9
- package/build/modules.js.map +0 -1
- package/src/manager/modules.ts +0 -18
- package/src/modules.ts +0 -13
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { DISPATCHER } from '@owlmeans/auth';
|
|
3
|
+
import { HOME } from '@owlmeans/context';
|
|
4
|
+
import { useContext, useNavigate } from '@owlmeans/client';
|
|
5
|
+
import { resumeSuspendedFlow } from '@owlmeans/client-flow';
|
|
6
|
+
import { DEFAULT_ALIAS as AUTH_ALIAS } from '../consts.js';
|
|
7
|
+
import { ensureLoginService } from './service.js';
|
|
8
|
+
/**
|
|
9
|
+
* Bound on a single step's `pending` check, or a landing hook's `landed` call.
|
|
10
|
+
*
|
|
11
|
+
* A step/hook that hangs must never HANG sign-in itself — both `continueLogin` and
|
|
12
|
+
* `landAfterLogin` treat a timeout exactly like a rejection, resolving within this budget either
|
|
13
|
+
* way. What that resolves TO is fail-open ("not pending") for an ordinary step, and fail-closed
|
|
14
|
+
* ("pending") for one that declared itself `required` — see `continueLogin`'s `onBroken`.
|
|
15
|
+
*/
|
|
16
|
+
export const LOGIN_STEP_TIMEOUT = 5_000;
|
|
17
|
+
/** Where a browser records the last token a landing hook has already run for. */
|
|
18
|
+
export const LOGIN_LANDED_STORAGE = '_owlmeans-login-landed';
|
|
19
|
+
/**
|
|
20
|
+
* Race a promise against a bound, resolving to `onTimeout` (never rejecting) if the bound wins.
|
|
21
|
+
*
|
|
22
|
+
* A synchronous throw from the wrapped call is turned into a rejection by the caller before this
|
|
23
|
+
* ever sees it, so the only two outcomes here are "settled in time" and "timed out". `onTimeout`
|
|
24
|
+
* defaults to `undefined` — every existing caller that omits it keeps its old fail-open meaning;
|
|
25
|
+
* `continueLogin` passes a step's own `required` flag through it so a step that hangs is read the
|
|
26
|
+
* same way as one that throws.
|
|
27
|
+
*/
|
|
28
|
+
const withTimeout = async (promise, ms, onTimeout) => {
|
|
29
|
+
let timer;
|
|
30
|
+
try {
|
|
31
|
+
return await Promise.race([
|
|
32
|
+
promise,
|
|
33
|
+
new Promise(resolve => { timer = setTimeout(() => resolve(onTimeout), ms); }),
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
if (timer != null) {
|
|
38
|
+
clearTimeout(timer);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Run every registered landing hook, once per distinct token.
|
|
44
|
+
*
|
|
45
|
+
* The stored token is overwritten BEFORE the hooks run, not after: a hook that throws or hangs
|
|
46
|
+
* must never make the same token re-run the whole set on the next call, since surviving exactly
|
|
47
|
+
* that is what the bound-and-swallow contract is for. The raw token string is the marker rather
|
|
48
|
+
* than a digest of it — it never leaves the browser, and this package already keeps the terms
|
|
49
|
+
* acceptance marker the same way (`LOGIN_TERMS_STORAGE`).
|
|
50
|
+
*/
|
|
51
|
+
const runLandingHooks = async (ctx, login, timeout) => {
|
|
52
|
+
const auth = ctx.service(AUTH_ALIAS);
|
|
53
|
+
const token = await auth.authenticated();
|
|
54
|
+
if (token == null) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
let last = null;
|
|
58
|
+
try {
|
|
59
|
+
last = window.localStorage.getItem(LOGIN_LANDED_STORAGE);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Storage can be unavailable (private modes, blocked cookies). Treated as "never landed",
|
|
63
|
+
// which just re-runs the hooks — the safe direction, same as the terms-acceptance marker.
|
|
64
|
+
}
|
|
65
|
+
if (last === token) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
window.localStorage.setItem(LOGIN_LANDED_STORAGE, token);
|
|
70
|
+
}
|
|
71
|
+
catch { /* nothing to remember if storage was never available */ }
|
|
72
|
+
for (const hook of login.landingHooks()) {
|
|
73
|
+
await withTimeout(Promise.resolve().then(() => hook.landed(ctx)), timeout).catch(() => undefined);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Where a finished sign-in should go: the first pending step, else a suspended flow, else the
|
|
78
|
+
* fallback (ordinarily `HOME`).
|
|
79
|
+
*
|
|
80
|
+
* Re-checks `env().surrogate` even though {@link landAfterLogin} already did — this function is
|
|
81
|
+
* also called directly (e.g. from {@link useContinueLogin}, after the surrogate window has
|
|
82
|
+
* already closed), and the check is cheap insurance either way: **no step and no landing hook
|
|
83
|
+
* ever runs inside the surrogate popup.** It has nothing of its own to collect and nowhere to
|
|
84
|
+
* navigate — the popup's own `DispatcherHOC` has no `navigate() → HOME` at all.
|
|
85
|
+
*/
|
|
86
|
+
export const continueLogin = async (ctx, opts) => {
|
|
87
|
+
const login = ensureLoginService(ctx);
|
|
88
|
+
if (login.env().surrogate) {
|
|
89
|
+
return { alias: DISPATCHER };
|
|
90
|
+
}
|
|
91
|
+
const timeout = opts?.stepTimeout ?? LOGIN_STEP_TIMEOUT;
|
|
92
|
+
const auth = ctx.service(AUTH_ALIAS);
|
|
93
|
+
const token = await auth.authenticated();
|
|
94
|
+
if (token != null) {
|
|
95
|
+
const steps = login.steps();
|
|
96
|
+
let start = 0;
|
|
97
|
+
if (opts?.after != null) {
|
|
98
|
+
const index = steps.findIndex(step => step.alias === opts.after);
|
|
99
|
+
if (index >= 0) {
|
|
100
|
+
start = index + 1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
for (let i = start; i < steps.length; i++) {
|
|
104
|
+
const step = steps[i];
|
|
105
|
+
// Registration proves only that some module reached the bundle — the step's own screen may
|
|
106
|
+
// not be bound in this tree (an older target, a partial import). Skipped, never thrown.
|
|
107
|
+
if (!ctx.hasEntrypoint(step.entrypoint)) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
// A step that throws or hangs fails OPEN ("not pending") by default — UNLESS it declared
|
|
111
|
+
// itself `required`, in which case a broken read must show the step rather than let the
|
|
112
|
+
// person through it unconfirmed (a Terms box moved here from the sign-in screen).
|
|
113
|
+
const onBroken = step.required === true;
|
|
114
|
+
const pending = await withTimeout(Promise.resolve().then(() => step.pending(ctx)), timeout, onBroken).catch(() => onBroken);
|
|
115
|
+
if (pending === true) {
|
|
116
|
+
return { alias: step.entrypoint, query: await step.query?.(ctx), step: step.alias };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (opts?.resume !== false) {
|
|
121
|
+
const landing = await resumeSuspendedFlow(ctx);
|
|
122
|
+
if (landing != null) {
|
|
123
|
+
return { alias: landing.entrypoint, query: landing.query };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return opts?.fallback ?? { alias: HOME };
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* The whole post-sign-in landing decision: run any due landing hooks for a freshly seen token,
|
|
130
|
+
* then delegate to {@link continueLogin} for where the flow actually goes.
|
|
131
|
+
*
|
|
132
|
+
* This is what a plugin that just adopted a token calls in place of the old inline
|
|
133
|
+
* "`resumeSuspendedFlow` else `HOME`" — `DispatcherHOC`, the supervisor plugin and both Google
|
|
134
|
+
* plugins all replace their own copy of that logic with this one.
|
|
135
|
+
*/
|
|
136
|
+
export const landAfterLogin = async (ctx, opts) => {
|
|
137
|
+
const login = ensureLoginService(ctx);
|
|
138
|
+
// Never run a step or a landing hook while THIS document is the surrogate popup — see the note
|
|
139
|
+
// on `continueLogin`.
|
|
140
|
+
if (login.env().surrogate) {
|
|
141
|
+
return { alias: DISPATCHER };
|
|
142
|
+
}
|
|
143
|
+
await runLandingHooks(ctx, login, opts?.stepTimeout ?? LOGIN_STEP_TIMEOUT);
|
|
144
|
+
return continueLogin(ctx, opts);
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* The absolute URL a landing resolves to — the same shape the supervisor and Google plugins
|
|
148
|
+
* already build their own `window.location.href` from.
|
|
149
|
+
*/
|
|
150
|
+
export const landingUrl = async (ctx, landing) => await ctx.entrypoint(landing.alias).url({ params: landing.params, query: landing.query }, { absolute: true });
|
|
151
|
+
/**
|
|
152
|
+
* For a component that runs its own post-login step (the marketing-consent screen, for one) to
|
|
153
|
+
* call once it is satisfied — moves the flow on to the next step, or the ordinary landing.
|
|
154
|
+
*
|
|
155
|
+
* Not async at the call site by accident of its own — it is a callback a component holds and
|
|
156
|
+
* fires later, so nothing here needs the synchronous-gesture discipline `useLogin`/`useLogout` do.
|
|
157
|
+
*/
|
|
158
|
+
export const useContinueLogin = () => {
|
|
159
|
+
const context = useContext();
|
|
160
|
+
const nav = useNavigate();
|
|
161
|
+
return useCallback(async (opts) => {
|
|
162
|
+
const landing = await continueLogin(context, opts);
|
|
163
|
+
await nav.go(landing.alias, { params: landing.params, query: landing.query });
|
|
164
|
+
}, [context, nav]);
|
|
165
|
+
};
|
|
166
|
+
//# sourceMappingURL=land.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"land.js","sourceRoot":"","sources":["../../src/login/land.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAG1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,aAAa,IAAI,UAAU,EAAE,MAAM,cAAc,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAGjD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAA;AAEvC,iFAAiF;AACjF,MAAM,CAAC,MAAM,oBAAoB,GAAG,wBAAwB,CAAA;AAE5D;;;;;;;;GAQG;AACH,MAAM,WAAW,GAAG,KAAK,EACvB,OAAmB,EAAE,EAAU,EAAE,SAAa,EACtB,EAAE;IAC1B,IAAI,KAAgD,CAAA;IACpD,IAAI,CAA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export declare const registerMethodSource: (source: LoginMethodSource) => void;
|
|
4
|
+
export declare const listMethodSources: () => LoginMethodSource[];
|
|
5
|
+
/**
|
|
6
|
+
* Everything the current environment may be offered, in the order it should be offered in.
|
|
7
|
+
*
|
|
8
|
+
* Resolution order matters and is not arbitrary:
|
|
9
|
+
*
|
|
10
|
+
* 1. Sources produce candidates. A source that throws is skipped rather than taking the screen
|
|
11
|
+
* down — a misconfigured provider list must not remove the sign-in method that does work.
|
|
12
|
+
* 2. `restricted` candidates are dropped unless the configuration named them, which is what makes
|
|
13
|
+
* an operator login opt-in rather than merely unadvertised.
|
|
14
|
+
* 3. An explicit `methods` list is both a filter AND the order, because an app that bothered to
|
|
15
|
+
* list them means that list.
|
|
16
|
+
*/
|
|
17
|
+
export declare const resolveLoginMethods: (ctx: LoginMethodContext, cfg?: LoginScreenConfig, extra?: LoginMethodSource[]) => LoginMethod[];
|
|
18
|
+
/**
|
|
19
|
+
* The method a screen highlights and focuses.
|
|
20
|
+
*
|
|
21
|
+
* The first `primary` one, else the first offered. It is highlighted, never started: requirement
|
|
22
|
+
* one of this whole feature is that nothing leaves the document without a click.
|
|
23
|
+
*/
|
|
24
|
+
export declare const primaryLoginMethod: (methods: LoginMethod[]) => LoginMethod | null;
|
|
25
|
+
//# sourceMappingURL=methods.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"methods.d.ts","sourceRoot":"","sources":["../../src/login/methods.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAE5E,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAgBpF,eAAO,MAAM,oBAAoB,WAAY,iBAAiB,KAAG,IAMhE,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAO,iBAAiB,EAAkB,CAAA;AAiBxE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,QACzB,kBAAkB,QAAQ,iBAAiB,UAAS,iBAAiB,EAAE,KAC3E,WAAW,EA8Cb,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,YAAa,WAAW,EAAE,KAAG,WAAW,GAAG,IACG,CAAA"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { DEFAULT_METHOD_ORDER } from './consts.js';
|
|
2
|
+
/**
|
|
3
|
+
* The module-global registry of method SOURCES.
|
|
4
|
+
*
|
|
5
|
+
* A source, rather than a method, because the two things that offer sign-in methods answer
|
|
6
|
+
* different questions at different times: the plugin registry knows what code is loaded, and the
|
|
7
|
+
* OIDC configuration knows what an entity is federated with. Both are answered per render — a
|
|
8
|
+
* provider list can arrive from the api-config middleware after the first paint.
|
|
9
|
+
*
|
|
10
|
+
* Global, like the `AuthenticationPlugin` map it mirrors, because a package registers its source
|
|
11
|
+
* from a side-effect import that has no context to hang it on. A context-scoped registry exists
|
|
12
|
+
* alongside it on the login service, and both are merged by {@link resolveLoginMethods}.
|
|
13
|
+
*/
|
|
14
|
+
const sources = [];
|
|
15
|
+
export const registerMethodSource = (source) => {
|
|
16
|
+
const existing = sources.findIndex(candidate => candidate.alias === source.alias);
|
|
17
|
+
if (existing >= 0) {
|
|
18
|
+
sources.splice(existing, 1);
|
|
19
|
+
}
|
|
20
|
+
sources.push(source);
|
|
21
|
+
};
|
|
22
|
+
export const listMethodSources = () => [...sources];
|
|
23
|
+
/** Normalize a config entry, which may be a bare id or a full override object. */
|
|
24
|
+
const asConfig = (entry) => typeof entry === 'string' ? { id: entry } : entry;
|
|
25
|
+
const merge = (method, override) => override == null ? method : {
|
|
26
|
+
...method,
|
|
27
|
+
...(override.label != null ? { label: override.label } : {}),
|
|
28
|
+
...(override.i18nKey != null ? { i18nKey: override.i18nKey } : {}),
|
|
29
|
+
...(override.icon != null ? { icon: override.icon } : {}),
|
|
30
|
+
...(override.order != null ? { order: override.order } : {}),
|
|
31
|
+
...(override.emphasis != null ? { emphasis: override.emphasis } : {}),
|
|
32
|
+
...(override.params != null ? { params: { ...method.params, ...override.params } } : {}),
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Everything the current environment may be offered, in the order it should be offered in.
|
|
36
|
+
*
|
|
37
|
+
* Resolution order matters and is not arbitrary:
|
|
38
|
+
*
|
|
39
|
+
* 1. Sources produce candidates. A source that throws is skipped rather than taking the screen
|
|
40
|
+
* down — a misconfigured provider list must not remove the sign-in method that does work.
|
|
41
|
+
* 2. `restricted` candidates are dropped unless the configuration named them, which is what makes
|
|
42
|
+
* an operator login opt-in rather than merely unadvertised.
|
|
43
|
+
* 3. An explicit `methods` list is both a filter AND the order, because an app that bothered to
|
|
44
|
+
* list them means that list.
|
|
45
|
+
*/
|
|
46
|
+
export const resolveLoginMethods = (ctx, cfg, extra = []) => {
|
|
47
|
+
const candidates = [];
|
|
48
|
+
for (const source of [...sources, ...extra]) {
|
|
49
|
+
try {
|
|
50
|
+
candidates.push(...source.list(ctx));
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
console.error(`login: method source "${source.alias}" failed`, e);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const overrides = cfg?.overrides ?? {};
|
|
57
|
+
const listed = cfg?.methods?.map(asConfig);
|
|
58
|
+
const listedIds = listed?.map(entry => entry.id).filter((id) => id != null);
|
|
59
|
+
const offered = candidates
|
|
60
|
+
.filter(method => {
|
|
61
|
+
const override = overrides[method.id] ?? listed?.find(entry => entry.id === method.id);
|
|
62
|
+
if (override?.enabled === false || override?.hidden === true) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
// A restricted method is offered only where the configuration asked for it — by naming it in
|
|
66
|
+
// `methods`, or by enabling it in `overrides`. Registering the plugin is deliberately not
|
|
67
|
+
// enough: an operator login that appears wherever its code happens to be bundled is an
|
|
68
|
+
// operator login in production.
|
|
69
|
+
if (method.restricted === true
|
|
70
|
+
&& listedIds?.includes(method.id) !== true
|
|
71
|
+
&& override?.enabled !== true) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
})
|
|
76
|
+
.map(method => merge(method, overrides[method.id]));
|
|
77
|
+
if (listedIds != null) {
|
|
78
|
+
return listedIds
|
|
79
|
+
.map(id => {
|
|
80
|
+
const method = offered.find(candidate => candidate.id === id);
|
|
81
|
+
return method != null ? merge(method, listed?.find(entry => entry.id === id)) : null;
|
|
82
|
+
})
|
|
83
|
+
.filter((method) => method != null);
|
|
84
|
+
}
|
|
85
|
+
return offered.sort((a, b) => {
|
|
86
|
+
const order = (a.order ?? DEFAULT_METHOD_ORDER) - (b.order ?? DEFAULT_METHOD_ORDER);
|
|
87
|
+
return order !== 0 ? order : a.id.localeCompare(b.id);
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* The method a screen highlights and focuses.
|
|
92
|
+
*
|
|
93
|
+
* The first `primary` one, else the first offered. It is highlighted, never started: requirement
|
|
94
|
+
* one of this whole feature is that nothing leaves the document without a click.
|
|
95
|
+
*/
|
|
96
|
+
export const primaryLoginMethod = (methods) => methods.find(method => method.emphasis === 'primary') ?? methods[0] ?? null;
|
|
97
|
+
//# sourceMappingURL=methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"methods.js","sourceRoot":"","sources":["../../src/login/methods.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAGlD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,GAAwB,EAAE,CAAA;AAEvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,MAAyB,EAAQ,EAAE;IACtE,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,CAAC,CAAA;IACjF,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;QAClB,OAAO,C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G,CAAC,CAAC,CAAC,KAAK,IAAI,oBAAoB,CAAC,CAAA;QACnF,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IACvD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAsB,EAAsB,EAAE,CAC/E,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { LoginOutcome } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The message key a FINISHED sign-in attempt should show, or null when it actually went somewhere.
|
|
4
|
+
*
|
|
5
|
+
* A dispatcher may treat `Passed` as "carry on with the ordinary continuation", because it has one.
|
|
6
|
+
* A screen does not: the user clicked, the document did not move, and nothing rendered — which is
|
|
7
|
+
* indistinguishable from a broken button, and is exactly how a null authorization URL used to
|
|
8
|
+
* present itself. Every outcome that leaves the user looking at the same screen therefore has to
|
|
9
|
+
* say something.
|
|
10
|
+
*/
|
|
11
|
+
export declare const loginAttemptError: (outcome: LoginOutcome | null) => string | null;
|
|
12
|
+
/** What a dispatcher does once `login().resume(...)` has answered. */
|
|
13
|
+
export declare enum ResumeAction {
|
|
14
|
+
/** The plugin took it over — the browser is leaving, or the window is closing. */
|
|
15
|
+
Stop = "stop",
|
|
16
|
+
/** Render the outcome to the user; there is nothing further to do automatically. */
|
|
17
|
+
Render = "render",
|
|
18
|
+
/** Ordinary tab: keep the session and carry on to the application. */
|
|
19
|
+
Navigate = "navigate"
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The one reading of a `resume` outcome, shared by every dispatcher.
|
|
23
|
+
*
|
|
24
|
+
* Exported as a pure function because three dispatchers — `web-client`, `web-oidc-rp` and
|
|
25
|
+
* `mui-oidc-rp` — have to agree on it, and the last time they each held their own copy of a
|
|
26
|
+
* decision they drifted, which is how a popup came to render the application inside itself in two
|
|
27
|
+
* packages at once. It is also the whole rule, so it is testable without a DOM.
|
|
28
|
+
*/
|
|
29
|
+
export declare const resumeAction: (outcome: LoginOutcome) => ResumeAction;
|
|
30
|
+
//# sourceMappingURL=resume.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resume.d.ts","sourceRoot":"","sources":["../../src/login/resume.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,YAAa,YAAY,GAAG,IAAI,KAAG,MAAM,GAAG,IAazE,CAAA;AAED,sEAAsE;AACtE,oBAAY,YAAY;IACtB,kFAAkF;IAClF,IAAI,SAAS;IACb,oFAAoF;IACpF,MAAM,WAAW;IACjB,sEAAsE;IACtE,QAAQ,aAAa;CACtB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,YAAa,YAAY,KAAG,YAapD,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { LoginOutcome } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The message key a FINISHED sign-in attempt should show, or null when it actually went somewhere.
|
|
4
|
+
*
|
|
5
|
+
* A dispatcher may treat `Passed` as "carry on with the ordinary continuation", because it has one.
|
|
6
|
+
* A screen does not: the user clicked, the document did not move, and nothing rendered — which is
|
|
7
|
+
* indistinguishable from a broken button, and is exactly how a null authorization URL used to
|
|
8
|
+
* present itself. Every outcome that leaves the user looking at the same screen therefore has to
|
|
9
|
+
* say something.
|
|
10
|
+
*/
|
|
11
|
+
export const loginAttemptError = (outcome) => {
|
|
12
|
+
switch (outcome) {
|
|
13
|
+
case LoginOutcome.Gesture:
|
|
14
|
+
case LoginOutcome.Blocked:
|
|
15
|
+
// The window never opened. That is the popup blocker, and it has its own copy.
|
|
16
|
+
return 'login.error.blocked';
|
|
17
|
+
case LoginOutcome.Failed:
|
|
18
|
+
case LoginOutcome.Passed:
|
|
19
|
+
return 'login.error.failed';
|
|
20
|
+
default:
|
|
21
|
+
// Handled, Redirected and Orphaned all did something; Orphaned reports itself elsewhere.
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/** What a dispatcher does once `login().resume(...)` has answered. */
|
|
26
|
+
export var ResumeAction;
|
|
27
|
+
(function (ResumeAction) {
|
|
28
|
+
/** The plugin took it over — the browser is leaving, or the window is closing. */
|
|
29
|
+
ResumeAction["Stop"] = "stop";
|
|
30
|
+
/** Render the outcome to the user; there is nothing further to do automatically. */
|
|
31
|
+
ResumeAction["Render"] = "render";
|
|
32
|
+
/** Ordinary tab: keep the session and carry on to the application. */
|
|
33
|
+
ResumeAction["Navigate"] = "navigate";
|
|
34
|
+
})(ResumeAction || (ResumeAction = {}));
|
|
35
|
+
/**
|
|
36
|
+
* The one reading of a `resume` outcome, shared by every dispatcher.
|
|
37
|
+
*
|
|
38
|
+
* Exported as a pure function because three dispatchers — `web-client`, `web-oidc-rp` and
|
|
39
|
+
* `mui-oidc-rp` — have to agree on it, and the last time they each held their own copy of a
|
|
40
|
+
* decision they drifted, which is how a popup came to render the application inside itself in two
|
|
41
|
+
* packages at once. It is also the whole rule, so it is testable without a DOM.
|
|
42
|
+
*/
|
|
43
|
+
export const resumeAction = (outcome) => {
|
|
44
|
+
switch (outcome) {
|
|
45
|
+
case LoginOutcome.Handled:
|
|
46
|
+
case LoginOutcome.Redirected:
|
|
47
|
+
return ResumeAction.Stop;
|
|
48
|
+
case LoginOutcome.Orphaned:
|
|
49
|
+
case LoginOutcome.Failed:
|
|
50
|
+
case LoginOutcome.Gesture:
|
|
51
|
+
case LoginOutcome.Blocked:
|
|
52
|
+
return ResumeAction.Render;
|
|
53
|
+
default:
|
|
54
|
+
return ResumeAction.Navigate;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=resume.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resume.js","sourceRoot":"","sources":["../../src/login/resume.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,OAA4B,EAAiB,EAAE;IAC/E,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,YAAY,CAAC,OAAO,CAAC;QAC1B,KAAK,YAAY,CAAC,OAAO;YACvB,+EAA+E;YAC/E,OAAO,qBAAqB,CAAA;QAC9B,KAAK,YAAY,CAAC,MAAM,CAAC;QACzB,KAAK,YAAY,CAAC,MAAM;YACtB,OAAO,oBAAoB,CAAA;QAC7B;YACE,yFAAyF;YACzF,OAAO,IAAI,CAAA;IACf,CAAC;AACH,CAAC,CAAA;AAED,sEAAsE;AACtE,MAAM,CAAN,IAAY,YAOX;AAPD,WAAY,YAAY;IACtB,kFAAkF;IAClF,6BAAa,CAAA;IACb,oFAAoF;IACpF,iCAAiB,CAAA;IACjB,sEAAsE;IACtE,qCAAqB,CAAA;AACvB,CAAC,EAPW,YAAY,KAAZ,YAAY,QAOvB;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAqB,EAAgB,EAAE;IAClE,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,YAAY,CAAC,OAAO,CAAC;QAC1B,KAAK,YAAY,CAAC,UAAU;YAC1B,OAAO,YAAY,CAAC,IAAI,CAAA;QAC1B,KAAK,YAAY,CAAC,QAAQ,CAAC;QAC3B,KAAK,YAAY,CAAC,MAAM,CAAC;QACzB,KAAK,YAAY,CAAC,OAAO,CAAC;QAC1B,KAAK,YAAY,CAAC,OAAO;YACvB,OAAO,YAAY,CAAC,MAAM,CAAA;QAC5B;YACE,OAAO,YAAY,CAAC,QAAQ,CAAA;IAChC,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import type { LoginScreenProps } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The sign-in screen every application gets, whether or not it registered a styled one.
|
|
5
|
+
*
|
|
6
|
+
* It exists because a relying party must render SOMETHING rather than start a flow on its own, and
|
|
7
|
+
* a relying party may not depend on a UI family. So this is deliberately plain: raw elements and
|
|
8
|
+
* inline styles, no Tailwind class that a consumer's stylesheet would have to scan for, no shadcn
|
|
9
|
+
* primitive a consumer would have to vendor. An application that registers a real screen through
|
|
10
|
+
* `login().registerScreen(...)` never sees it.
|
|
11
|
+
*
|
|
12
|
+
* Because it is the floor rather than the design, it still has to be correct: it offers the same
|
|
13
|
+
* methods, enforces the same terms confirmation, centres the same way, and renders the same
|
|
14
|
+
* credit line.
|
|
15
|
+
*/
|
|
16
|
+
export declare const FallbackLoginScreen: FC<LoginScreenProps>;
|
|
17
|
+
//# sourceMappingURL=screen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screen.d.ts","sourceRoot":"","sources":["../../src/login/screen.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,EAAE,EAAa,MAAM,OAAO,CAAA;AAGzD,OAAO,KAAK,EAA6B,gBAAgB,EAAgB,MAAM,YAAY,CAAA;AAuC3F;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,mBAAmB,EAAE,EAAE,CAAC,gBAAgB,CAuGpD,CAAA"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
|
+
import { useContext } from '@owlmeans/client';
|
|
4
|
+
import { LOGIN_SERVICE } from './consts.js';
|
|
5
|
+
import { primaryLoginMethod } from './methods.js';
|
|
6
|
+
import { acceptTerms, resolveTerms, termsAccepted, termsDeferred, termsLabelResolver, termsSentence, } from './terms.js';
|
|
7
|
+
import { resolveCredit } from './credit.js';
|
|
8
|
+
const renderParts = (parts) => parts.map((part, index) => part.href != null
|
|
9
|
+
? _jsx("a", { href: part.href, target: "_blank", rel: "noreferrer noopener", children: part.text }, index)
|
|
10
|
+
: _jsx("span", { children: part.text }, index));
|
|
11
|
+
/**
|
|
12
|
+
* The page the card sits in.
|
|
13
|
+
*
|
|
14
|
+
* It carries its own viewport height because this screen is rendered straight out of the
|
|
15
|
+
* dispatcher, into whatever the application happens to have around it — which is usually nothing
|
|
16
|
+
* with a height, so a percentage minimum would resolve to zero and leave the card at the top.
|
|
17
|
+
*/
|
|
18
|
+
const page = {
|
|
19
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
20
|
+
minHeight: '100dvh', padding: '1rem',
|
|
21
|
+
fontFamily: 'system-ui, sans-serif', lineHeight: 1.5,
|
|
22
|
+
};
|
|
23
|
+
// Centred throughout, so the plain screen and the styled one read the same way.
|
|
24
|
+
const box = {
|
|
25
|
+
width: '100%', maxWidth: '24rem', padding: '1.5rem', textAlign: 'center',
|
|
26
|
+
};
|
|
27
|
+
const button = (emphasis) => ({
|
|
28
|
+
display: 'block', width: '100%', marginTop: '.5rem', padding: '.625rem 1rem',
|
|
29
|
+
fontSize: '1rem', cursor: 'pointer', borderRadius: '.375rem',
|
|
30
|
+
border: '1px solid currentColor',
|
|
31
|
+
...(emphasis === 'primary' ? { fontWeight: 600 } : {}),
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* The sign-in screen every application gets, whether or not it registered a styled one.
|
|
35
|
+
*
|
|
36
|
+
* It exists because a relying party must render SOMETHING rather than start a flow on its own, and
|
|
37
|
+
* a relying party may not depend on a UI family. So this is deliberately plain: raw elements and
|
|
38
|
+
* inline styles, no Tailwind class that a consumer's stylesheet would have to scan for, no shadcn
|
|
39
|
+
* primitive a consumer would have to vendor. An application that registers a real screen through
|
|
40
|
+
* `login().registerScreen(...)` never sees it.
|
|
41
|
+
*
|
|
42
|
+
* Because it is the floor rather than the design, it still has to be correct: it offers the same
|
|
43
|
+
* methods, enforces the same terms confirmation, centres the same way, and renders the same
|
|
44
|
+
* credit line.
|
|
45
|
+
*/
|
|
46
|
+
export const FallbackLoginScreen = props => {
|
|
47
|
+
const context = useContext();
|
|
48
|
+
const t = props.translate ?? ((_key, defaultValue) => defaultValue);
|
|
49
|
+
const cfg = props.config ?? context.cfg.security?.auth?.login;
|
|
50
|
+
const brand = context.cfg.brand;
|
|
51
|
+
const login = context.service(LOGIN_SERVICE);
|
|
52
|
+
const env = login.env();
|
|
53
|
+
const resolved = resolveTerms(props.terms ?? cfg?.terms);
|
|
54
|
+
const credit = resolveCredit(cfg?.credit, brand, context.cfg.service);
|
|
55
|
+
const resolveLabel = termsLabelResolver(t, props.locale);
|
|
56
|
+
const deferred = termsDeferred(context);
|
|
57
|
+
const [accepted, setAccepted] = useState(() => termsAccepted(resolved));
|
|
58
|
+
const [attempted, setAttempted] = useState(false);
|
|
59
|
+
const all = login.methods({ context, env });
|
|
60
|
+
const methods = typeof props.methods === 'function'
|
|
61
|
+
? props.methods(all)
|
|
62
|
+
: props.methods ?? all;
|
|
63
|
+
const primary = primaryLoginMethod(methods);
|
|
64
|
+
const blocked = resolved != null && resolved.required && !deferred && !accepted;
|
|
65
|
+
const select = useCallback((method) => {
|
|
66
|
+
if (blocked) {
|
|
67
|
+
setAttempted(true);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
void method.start({ context, env });
|
|
71
|
+
}, [blocked, context, env]);
|
|
72
|
+
const onAccept = useCallback((value) => {
|
|
73
|
+
setAccepted(value);
|
|
74
|
+
setAttempted(false);
|
|
75
|
+
acceptTerms(resolved, value);
|
|
76
|
+
}, [resolved]);
|
|
77
|
+
return _jsx("div", { "data-login-screen": true, style: page, children: _jsxs("div", { style: box, children: [_jsx("h1", { style: { fontSize: '1.25rem', marginBottom: '.25rem' }, children: props.title ?? t('login.title', 'Sign in') }), _jsx("p", { style: { opacity: .75, marginTop: 0 }, children: props.subtitle ?? t('login.subtitle', 'Choose how you would like to continue.') }), methods.length < 1
|
|
78
|
+
? _jsx("p", { role: "status", children: t('login.empty', 'No sign-in method is configured for this application.') })
|
|
79
|
+
: methods.map(method => _jsx("button", { type: "button", "data-login-method": method.id, "aria-disabled": blocked, "data-blocked": blocked ? 'true' : undefined, style: { ...button(method.emphasis), opacity: blocked ? .6 : 1 }, autoFocus: method.id === primary?.id, onClick: () => select(method), children: method.label ?? t(`login.method.${method.i18nKey ?? method.id}`, method.id) }, method.id)), resolved != null && !deferred && _jsx("p", { style: { marginTop: '1rem', fontSize: '.875rem' }, children: _jsxs("label", { children: [_jsx("input", { type: "checkbox", checked: accepted, "data-login-terms": true, onChange: event => onAccept(event.target.checked) }), ' ', renderParts(termsSentence(t('login.terms.accept', 'I have read and agree to the {{documents}}.'), resolved, props.locale, resolveLabel))] }) }), resolved?.revisedAt != null && !deferred && _jsx("p", { "data-login-revised": true, style: { fontSize: '.75rem', opacity: .7 }, children: t('login.terms.revised', 'Last updated: {{date}}').split('{{date}}').join(resolved.revisedAt) }), resolved != null && _jsx("p", { "data-login-privacy": true, style: { fontSize: '.875rem' }, children: renderParts(termsSentence(t('login.terms.notice', 'How we handle your personal data: {{notices}}.'), resolved, props.locale, resolveLabel)) }), attempted && blocked && resolved != null && _jsx("p", { role: "alert", style: { color: '#b00', fontSize: '.875rem' }, children: renderParts(termsSentence(t('login.terms.required', 'Please confirm the {{documents}} to continue.'), resolved, props.locale, resolveLabel)) }), props.footer ?? _jsxs("p", { style: { marginTop: '2rem', fontSize: '.75rem', opacity: .7 }, children: [credit.poweredBy && _jsx("span", { children: t('login.credit.powered', 'Powered by OwlMeans') }), credit.poweredBy && credit.line != null && ' · ', credit.line] })] }) });
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=screen.js.map
|
|
@@ -0,0 +1 @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AAC,SAAS,IAAI,yBAAO,CAAC,CAAC,sBAAsB,EAAE,qBAAqB,CAAC,GAAQ,EACnF,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,IAAI,IAAI,IAAI,KAAK,EAChD,MAAM,CAAC,IAAI,IACV,IACA,GAAM,CAAA;AACd,CAAC,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BasicConfig, BasicContext } from '@owlmeans/context';
|
|
2
|
+
import { LoginOutcome } from './types.js';
|
|
3
|
+
import type { LoginService, LoginServiceAppend } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Login service = plugin host. It holds a registry of login plugins and, on every facade call,
|
|
6
|
+
* resolves the active plugin by cascade (priority desc, first whose `match(env)` is truthy) and
|
|
7
|
+
* delegates to it.
|
|
8
|
+
*
|
|
9
|
+
* The facade methods stay ordinary writable properties (never getters) so that non-plugin
|
|
10
|
+
* implementations — e.g. a native login service — can keep overriding them directly.
|
|
11
|
+
*
|
|
12
|
+
* It is a LAZY service on purpose. The host carries no async setup, and plugin packages must be
|
|
13
|
+
* able to reach it from an app's `makeContext` — i.e. while the context is still in the Loading
|
|
14
|
+
* stage. `context.service()` throws for an uninitialized non-lazy service, which would make
|
|
15
|
+
* `ensureLoginService` fail exactly where apps are told to call it.
|
|
16
|
+
*
|
|
17
|
+
* `begin` and `logout` are deliberately NOT `async`. An async facade method defers the plugin's
|
|
18
|
+
* body past a microtask boundary, and a `window.open` that lands after the user gesture has
|
|
19
|
+
* finished being handled is eaten by the popup blocker. The same rule binds every plugin's own
|
|
20
|
+
* `begin` and `logout`, and it is why a precondition must be synchronous too.
|
|
21
|
+
*/
|
|
22
|
+
export declare const makeLoginService: (alias?: string) => LoginService;
|
|
23
|
+
/**
|
|
24
|
+
* Idempotently obtain the login service on a context, registering an empty host if none exists
|
|
25
|
+
* yet. Plugin packages call this before `registerPlugin`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const ensureLoginService: (ctx: BasicContext<any>) => LoginService;
|
|
28
|
+
/** Register the host and expose it as `context.login()`. */
|
|
29
|
+
export declare const appendLogin: <C extends BasicConfig, T extends BasicContext<C>>(ctx: T) => T & LoginServiceAppend;
|
|
30
|
+
export { LoginOutcome };
|
|
31
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/login/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAMlE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,KAAK,EAEY,YAAY,EAAE,kBAAkB,EACvD,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,WAAW,MAAM,KAAmB,YAgKhE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAS,YAAY,CAAC,GAAG,CAAC,KAAG,YAQ3D,CAAA;AAED,4DAA4D;AAC5D,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,OACrE,CAAC,KACL,CAAC,GAAG,kBAMN,CAAA;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|