@sparkvault/sdk-js 16.0.1 → 16.1.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.md +2 -0
- package/dist/index.cjs +1735 -636
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +126 -41
- package/dist/index.mjs +1735 -636
- package/dist/index.mjs.map +1 -1
- package/dist/products/identity/api.d.ts +34 -3
- package/dist/products/identity/dialog-launcher.d.ts +44 -4
- package/dist/products/identity/federation-flow.d.ts +31 -0
- package/dist/products/identity/index.d.ts +56 -36
- package/dist/products/identity/methods.d.ts +4 -2
- package/dist/products/identity/pending-signin.d.ts +87 -0
- package/dist/products/identity/popup-launcher.d.ts +12 -0
- package/dist/products/identity/renderer.d.ts +142 -3
- package/dist/products/identity/state.d.ts +4 -0
- package/dist/products/identity/types.d.ts +87 -6
- package/dist/products/identity/utils.d.ts +21 -2
- package/dist/products/identity/views/base.d.ts +6 -0
- package/dist/products/identity/views/error.d.ts +12 -0
- package/dist/products/identity/views/identity-input.d.ts +24 -0
- package/dist/products/identity/views/loading.d.ts +8 -0
- package/dist/products/identity/views/method-button.d.ts +14 -0
- package/dist/products/identity/views/method-select.d.ts +7 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2171,8 +2171,11 @@ async function s256Challenge(verifier) {
|
|
|
2171
2171
|
* already reaches the Identity origin, so its CSP needs no other origin for
|
|
2172
2172
|
* the draw.
|
|
2173
2173
|
*
|
|
2174
|
-
* Request: `{ num_bytes }`, 1 to IDENTITY_DRAW_MAX_BYTES
|
|
2175
|
-
*
|
|
2174
|
+
* Request: `{ num_bytes }`, 1 to IDENTITY_DRAW_MAX_BYTES; a sign-in's
|
|
2175
|
+
* reference is drawn as `{ num_bytes, purpose }`, its size and purpose as
|
|
2176
|
+
* ./identity-signin-contract.js SIGNIN_REFERENCE names them, against a budget
|
|
2177
|
+
* of its own. Answer (in the `data` envelope): `{ value, num_bytes }`, the
|
|
2178
|
+
* bytes as unpadded base64url.
|
|
2176
2179
|
*
|
|
2177
2180
|
* BROWSER-SAFE.
|
|
2178
2181
|
*/
|
|
@@ -2199,6 +2202,157 @@ function identityDrawBytes(answer, numBytes) {
|
|
|
2199
2202
|
return bytes;
|
|
2200
2203
|
}
|
|
2201
2204
|
|
|
2205
|
+
/**
|
|
2206
|
+
* The wire between the browser SDK's sign-in (packages/sdk-js
|
|
2207
|
+
* src/products/identity) and Identity's sign-in endpoints and pages: the
|
|
2208
|
+
* names and values both sides read, defined once so a start, a returned
|
|
2209
|
+
* fragment or a recovery bounce can never be written one way and read
|
|
2210
|
+
* another.
|
|
2211
|
+
*
|
|
2212
|
+
* - A start that leaves for a provider (`/{account}/social/{provider}`,
|
|
2213
|
+
* `/{account}/federation`) names its return by START_PARAMS; a silent
|
|
2214
|
+
* attempt through the account's own identity provider sends
|
|
2215
|
+
* `prompt=none` (FEDERATION_SILENT_PROMPT).
|
|
2216
|
+
* - The return comes back to the page that started it as a fragment: a
|
|
2217
|
+
* sign-in as `#token=…&state=…` (SIGNIN_RESULT_FRAGMENT), and a refusal of
|
|
2218
|
+
* the account's own identity provider as federationRefusalFragment builds
|
|
2219
|
+
* it and federationRefusalIn reads it.
|
|
2220
|
+
* - The sign-in page (`/{account}/signin`) takes `method=federation`
|
|
2221
|
+
* (SIGNIN_METHOD_PARAM, FEDERATION_METHOD) to start with the account's own
|
|
2222
|
+
* identity provider, whose button says federationButtonLabel's words.
|
|
2223
|
+
* - Every sign-in the SDK opens carries a reference (SIGNIN_REFERENCE) that
|
|
2224
|
+
* Identity records on the hub session the sign-in creates or chooses. A
|
|
2225
|
+
* sign-in whose popup result was lost recovers through `/{account}/sso`
|
|
2226
|
+
* naming that reference, and the recovery may only veto: it mints what the
|
|
2227
|
+
* same call without a reference would, and only when that hub session
|
|
2228
|
+
* carries this sign-in's reference.
|
|
2229
|
+
*
|
|
2230
|
+
* Browser-safe and dependency-free: the JS SDK bundles this module, and the
|
|
2231
|
+
* sign-in shells inline federationRefusalIn's own source into their pages.
|
|
2232
|
+
*/
|
|
2233
|
+
|
|
2234
|
+
/** The query parameters a start that leaves for a provider names its return with. */
|
|
2235
|
+
const START_PARAMS = Object.freeze({
|
|
2236
|
+
redirectUri: 'redirect_uri',
|
|
2237
|
+
state: 'state',
|
|
2238
|
+
authRequestId: 'auth_request_id',
|
|
2239
|
+
prompt: 'prompt'
|
|
2240
|
+
});
|
|
2241
|
+
|
|
2242
|
+
/** The `prompt` a silent attempt through the account's own identity provider sends. */
|
|
2243
|
+
const FEDERATION_SILENT_PROMPT = 'none';
|
|
2244
|
+
|
|
2245
|
+
/** The fragment a provider round trip returns a sign-in in: `#token=…&state=…`. */
|
|
2246
|
+
const SIGNIN_RESULT_FRAGMENT = Object.freeze({ token: 'token', state: 'state' });
|
|
2247
|
+
|
|
2248
|
+
/** The sign-in page's parameter naming the method to start with, and the account's own identity provider as its value. */
|
|
2249
|
+
const SIGNIN_METHOD_PARAM = 'method';
|
|
2250
|
+
const FEDERATION_METHOD = 'federation';
|
|
2251
|
+
|
|
2252
|
+
/**
|
|
2253
|
+
* The words on the sign-in page's button for the account's own identity
|
|
2254
|
+
* provider, by the name the account gave it (`display_name`): the SDK's
|
|
2255
|
+
* sign-in draws the button with them, and the console's settings quote them
|
|
2256
|
+
* beside the name.
|
|
2257
|
+
*
|
|
2258
|
+
* @param {string} displayName
|
|
2259
|
+
* @returns {string}
|
|
2260
|
+
*/
|
|
2261
|
+
function federationButtonLabel(displayName) {
|
|
2262
|
+
return `Continue with ${displayName}`;
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
/**
|
|
2266
|
+
* The refusal a returned fragment carries (federationRefusalFragment), or
|
|
2267
|
+
* null for any other fragment. Whether it answers a sign-in this browser
|
|
2268
|
+
* started is the reader's check, against the `state` it stored before it
|
|
2269
|
+
* left.
|
|
2270
|
+
*
|
|
2271
|
+
* Self-contained: it reads nothing outside its own body, because the sign-in
|
|
2272
|
+
* shells inline its source (`String(federationRefusalIn)`) into their pages.
|
|
2273
|
+
*
|
|
2274
|
+
* @param {URLSearchParams} fragment - The returned fragment's parameters
|
|
2275
|
+
* @returns {'interaction_required'|'failed'|null}
|
|
2276
|
+
*/
|
|
2277
|
+
function federationRefusalIn(fragment) {
|
|
2278
|
+
const error = fragment.get('error');
|
|
2279
|
+
if (error === 'interaction_required' && fragment.get('method') === 'federation') return 'interaction_required';
|
|
2280
|
+
if (error === 'federation_failed') return 'failed';
|
|
2281
|
+
return null;
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2284
|
+
/**
|
|
2285
|
+
* How long a sign-in stays recoverable: the SDK's pending marker lives this
|
|
2286
|
+
* long, and Identity honours a sign-in reference recorded on a hub session at
|
|
2287
|
+
* most this long ago.
|
|
2288
|
+
*/
|
|
2289
|
+
const SIGNIN_RECOVERY = Object.freeze({
|
|
2290
|
+
pendingTtlMs: 10 * 60 * 1000
|
|
2291
|
+
});
|
|
2292
|
+
|
|
2293
|
+
/**
|
|
2294
|
+
* A sign-in's reference: `bytes` drawn by the SDK that opens the sign-in page
|
|
2295
|
+
* (from the Entropy service, like its other values), unpadded base64url. It is
|
|
2296
|
+
* no secret and grants nothing by itself; it names one sign-in, and each
|
|
2297
|
+
* popup the SDK opens for it (the first, and each "Try again") draws its own.
|
|
2298
|
+
*
|
|
2299
|
+
* - `param`: the name it travels under, in a query (the sign-in page's URL,
|
|
2300
|
+
* a provider start, the recovery bounce to `/sso`) and in a JSON body (each
|
|
2301
|
+
* call that completes a sign-in, `/sso/continue`).
|
|
2302
|
+
* - `drawPurpose`: the `purpose` a draw of a reference names at the Identity
|
|
2303
|
+
* origin's draw (identity-entropy.js), which counts it against a budget of
|
|
2304
|
+
* its own, apart from the draws a sign-in needs to complete.
|
|
2305
|
+
* - `fromOpenerParam` = `fromOpenerValue`: the sign-in popup's URL says its
|
|
2306
|
+
* opener posts the reference (the popup opens inside the click, before any
|
|
2307
|
+
* draw can finish). The opener posts `{ type: message, [param] }` once its
|
|
2308
|
+
* pending marker holds the reference, or `[param]: null` once it knows the
|
|
2309
|
+
* popup has none right now; the popup asks again with
|
|
2310
|
+
* `{ type: retryMessage }`, and the opener then draws afresh.
|
|
2311
|
+
* - `fromOpenerParam` = `noRecoveryValue`: the SDK sent this page by redirect
|
|
2312
|
+
* with no reference and holds no pending marker for it (it removes any
|
|
2313
|
+
* first), so no recovery can ever stand in for the page's result, which the
|
|
2314
|
+
* page completes in its own window.
|
|
2315
|
+
* - `drawDeadlineMs`: the longest the opener waits for its draw. A draw that
|
|
2316
|
+
* fails or misses it leaves the popup without a reference for now, and one
|
|
2317
|
+
* that lands later is discarded.
|
|
2318
|
+
* - `openerWaitMs`: the longest the popup waits for its opener's message
|
|
2319
|
+
* before it treats the reference as unavailable for now. The popup renders
|
|
2320
|
+
* at once and never waits on it to show its first step. It exceeds
|
|
2321
|
+
* `drawDeadlineMs`: the popup starts waiting only once its page loads,
|
|
2322
|
+
* after the click that started the draw, so the opener always decides
|
|
2323
|
+
* first.
|
|
2324
|
+
* - `redirectWaitMs`: the longest a redirect waits for the reference its
|
|
2325
|
+
* popup's draw is still deciding (a popup whose handle the page's opener
|
|
2326
|
+
* policy severed), before it goes without one.
|
|
2327
|
+
*/
|
|
2328
|
+
const SIGNIN_REFERENCE = Object.freeze({
|
|
2329
|
+
param: 'signin_ref',
|
|
2330
|
+
bytes: 32,
|
|
2331
|
+
drawPurpose: 'signin_reference',
|
|
2332
|
+
fromOpenerParam: 'signin_ref_from',
|
|
2333
|
+
fromOpenerValue: 'opener',
|
|
2334
|
+
noRecoveryValue: 'none',
|
|
2335
|
+
message: 'sparkvault-signin-ref',
|
|
2336
|
+
retryMessage: 'sparkvault-signin-ref-retry',
|
|
2337
|
+
drawDeadlineMs: 2500,
|
|
2338
|
+
openerWaitMs: 4000,
|
|
2339
|
+
redirectWaitMs: 500
|
|
2340
|
+
});
|
|
2341
|
+
|
|
2342
|
+
/**
|
|
2343
|
+
* Whether a value is a sign-in reference in its one spelling: 32 bytes as
|
|
2344
|
+
* 43 unpadded base64url characters.
|
|
2345
|
+
*
|
|
2346
|
+
* Self-contained, like federationRefusalIn: the sign-in shells inline its
|
|
2347
|
+
* source.
|
|
2348
|
+
*
|
|
2349
|
+
* @param {unknown} value
|
|
2350
|
+
* @returns {boolean}
|
|
2351
|
+
*/
|
|
2352
|
+
function isSigninReference(value) {
|
|
2353
|
+
return typeof value === 'string' && /^[A-Za-z0-9_-]{43}$/.test(value);
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2202
2356
|
/**
|
|
2203
2357
|
* Request paths: the one way a module names a SparkVault route.
|
|
2204
2358
|
*
|
|
@@ -2392,7 +2546,7 @@ function currentPageReturnUrl() {
|
|
|
2392
2546
|
* delivery modes: the popup (opener + postMessage) and the same-tab redirect
|
|
2393
2547
|
* (redirect_uri + state + code_challenge → one-time code in the fragment).
|
|
2394
2548
|
*/
|
|
2395
|
-
function buildSigninUrl(config, options,
|
|
2549
|
+
function buildSigninUrl(config, options, delivery) {
|
|
2396
2550
|
const params = new URLSearchParams({ origin: window.location.origin });
|
|
2397
2551
|
// Identifier prefill - the sign-in page collects it itself when absent.
|
|
2398
2552
|
if (options.email) {
|
|
@@ -2418,10 +2572,26 @@ function buildSigninUrl(config, options, extras) {
|
|
|
2418
2572
|
if (options.prompt === 'select_account') {
|
|
2419
2573
|
params.set('prompt', 'select_account');
|
|
2420
2574
|
}
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
params.set(
|
|
2575
|
+
// `method` likewise: only the account's own identity provider can be asked
|
|
2576
|
+
// for by name, and only that literal reaches the sign-in page.
|
|
2577
|
+
if (options.method === FEDERATION_METHOD) {
|
|
2578
|
+
params.set(SIGNIN_METHOD_PARAM, FEDERATION_METHOD);
|
|
2579
|
+
}
|
|
2580
|
+
if (delivery.kind === 'popup') {
|
|
2581
|
+
params.set(SIGNIN_REFERENCE.fromOpenerParam, SIGNIN_REFERENCE.fromOpenerValue);
|
|
2582
|
+
}
|
|
2583
|
+
else {
|
|
2584
|
+
if (delivery.signinRef) {
|
|
2585
|
+
params.set(SIGNIN_REFERENCE.param, delivery.signinRef);
|
|
2586
|
+
}
|
|
2587
|
+
else {
|
|
2588
|
+
params.set(SIGNIN_REFERENCE.fromOpenerParam, SIGNIN_REFERENCE.noRecoveryValue);
|
|
2589
|
+
}
|
|
2590
|
+
if (delivery.handoff) {
|
|
2591
|
+
params.set('redirect_uri', delivery.handoff.redirectUri);
|
|
2592
|
+
params.set('state', delivery.handoff.state);
|
|
2593
|
+
params.set('code_challenge', delivery.handoff.codeChallenge);
|
|
2594
|
+
}
|
|
2425
2595
|
}
|
|
2426
2596
|
return `${config.identityBaseUrl}/${config.accountId}/signin?${params}`;
|
|
2427
2597
|
}
|
|
@@ -2475,6 +2645,10 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2475
2645
|
this.configCache = null;
|
|
2476
2646
|
this.config = config;
|
|
2477
2647
|
}
|
|
2648
|
+
/** The account this API signs people in to. */
|
|
2649
|
+
get accountId() {
|
|
2650
|
+
return this.config.accountId;
|
|
2651
|
+
}
|
|
2478
2652
|
get baseUrl() {
|
|
2479
2653
|
return `${this.config.identityBaseUrl}${apiPath `/${this.config.accountId}`}`;
|
|
2480
2654
|
}
|
|
@@ -2548,6 +2722,25 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2548
2722
|
const answer = await this.request('POST', apiPath `/entropy`, { num_bytes: AUTHORIZATION_DRAW.bytes });
|
|
2549
2723
|
return authorizationValues(identityDrawBytes(answer, AUTHORIZATION_DRAW.bytes));
|
|
2550
2724
|
}
|
|
2725
|
+
/**
|
|
2726
|
+
* A sign-in's reference (app-sdk SIGNIN_REFERENCE): its own draw through
|
|
2727
|
+
* the Identity origin, like drawAuthorizationValues, spelled unpadded
|
|
2728
|
+
* base64url. The draw names its purpose, so the origin counts it against a
|
|
2729
|
+
* budget of its own and a network's reference draws never spend the draws
|
|
2730
|
+
* its sign-ins need to complete. Rejects on a draw that fails (a spent
|
|
2731
|
+
* budget among them) or answers malformed.
|
|
2732
|
+
*/
|
|
2733
|
+
async drawSigninReference() {
|
|
2734
|
+
const answer = await this.request('POST', apiPath `/entropy`, {
|
|
2735
|
+
num_bytes: SIGNIN_REFERENCE.bytes,
|
|
2736
|
+
purpose: SIGNIN_REFERENCE.drawPurpose,
|
|
2737
|
+
});
|
|
2738
|
+
const reference = bytesToBase64url(identityDrawBytes(answer, SIGNIN_REFERENCE.bytes));
|
|
2739
|
+
if (!isSigninReference(reference)) {
|
|
2740
|
+
throw new SparkVaultError('The Identity origin answered a malformed sign-in reference', 'invalid_response');
|
|
2741
|
+
}
|
|
2742
|
+
return reference;
|
|
2743
|
+
}
|
|
2551
2744
|
/**
|
|
2552
2745
|
* Check whether the SVID resolved from an email or phone has registered
|
|
2553
2746
|
* passkeys (`has_passkey`; cross-tenant — single global RP), for a
|
|
@@ -2600,6 +2793,7 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2600
2793
|
pin: params.pin,
|
|
2601
2794
|
recipient: params.recipient,
|
|
2602
2795
|
...this.buildAuthContextParams(params.authContext),
|
|
2796
|
+
...signinRefParam(params.signinRef),
|
|
2603
2797
|
});
|
|
2604
2798
|
}
|
|
2605
2799
|
/**
|
|
@@ -2642,6 +2836,7 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2642
2836
|
return this.request('POST', apiPath `/passkey/verify/complete`, {
|
|
2643
2837
|
session: params.session,
|
|
2644
2838
|
...this.buildAuthContextParams(params.authContext),
|
|
2839
|
+
...signinRefParam(params.signinRef),
|
|
2645
2840
|
credential: {
|
|
2646
2841
|
id: params.credential.id,
|
|
2647
2842
|
rawId: arrayBufferToBase64url(params.credential.rawId),
|
|
@@ -2694,15 +2889,18 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2694
2889
|
});
|
|
2695
2890
|
}
|
|
2696
2891
|
/**
|
|
2697
|
-
* Get OAuth redirect URL for social provider
|
|
2892
|
+
* Get OAuth redirect URL for social provider. The start carries the
|
|
2893
|
+
* sign-in's reference, when it has one, so the hub session the provider's
|
|
2894
|
+
* answer creates or chooses records it.
|
|
2698
2895
|
*/
|
|
2699
|
-
getSocialAuthUrl(provider, redirectUri, state, authContext) {
|
|
2896
|
+
getSocialAuthUrl(provider, redirectUri, state, authContext, signinRef) {
|
|
2700
2897
|
const params = new URLSearchParams({
|
|
2701
|
-
|
|
2702
|
-
state,
|
|
2898
|
+
[START_PARAMS.redirectUri]: redirectUri,
|
|
2899
|
+
[START_PARAMS.state]: state,
|
|
2900
|
+
...signinRefParam(signinRef),
|
|
2703
2901
|
});
|
|
2704
2902
|
if (authContext?.authRequestId) {
|
|
2705
|
-
params.set(
|
|
2903
|
+
params.set(START_PARAMS.authRequestId, authContext.authRequestId);
|
|
2706
2904
|
}
|
|
2707
2905
|
const { simple_mode: simpleMode } = verifySessionParam(authContext);
|
|
2708
2906
|
if (simpleMode) {
|
|
@@ -2710,15 +2908,42 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2710
2908
|
}
|
|
2711
2909
|
return `${this.baseUrl}/social/${provider}?${params}`;
|
|
2712
2910
|
}
|
|
2911
|
+
/**
|
|
2912
|
+
* The start of a sign-in with the account's own identity provider: the same
|
|
2913
|
+
* return as a social start (the page `redirectUri` names, answered with
|
|
2914
|
+
* `#token` and the `state` sent, or the OIDC auth request it continues), and
|
|
2915
|
+
* `prompt=none` for a silent attempt, which the provider answers without
|
|
2916
|
+
* showing anything. The start carries the sign-in's reference, when it has
|
|
2917
|
+
* one: such a sign-in opens no hub session, so Identity releases that
|
|
2918
|
+
* reference from the browser's hub sessions on its completion, and a
|
|
2919
|
+
* recovery naming it mints none of them. A verify session is never named:
|
|
2920
|
+
* such a sign-in cannot complete one, so its start refuses it, and a verify
|
|
2921
|
+
* session never admits the method.
|
|
2922
|
+
*/
|
|
2923
|
+
getFederationAuthUrl(redirectUri, state, authContext, options = {}) {
|
|
2924
|
+
const params = new URLSearchParams({
|
|
2925
|
+
[START_PARAMS.redirectUri]: redirectUri,
|
|
2926
|
+
[START_PARAMS.state]: state,
|
|
2927
|
+
...signinRefParam(options.signinRef),
|
|
2928
|
+
});
|
|
2929
|
+
if (authContext?.authRequestId) {
|
|
2930
|
+
params.set(START_PARAMS.authRequestId, authContext.authRequestId);
|
|
2931
|
+
}
|
|
2932
|
+
if (options.silent) {
|
|
2933
|
+
params.set(START_PARAMS.prompt, FEDERATION_SILENT_PROMPT);
|
|
2934
|
+
}
|
|
2935
|
+
return `${this.baseUrl}/federation?${params}`;
|
|
2936
|
+
}
|
|
2713
2937
|
/**
|
|
2714
2938
|
* Send SparkLink email for identity verification.
|
|
2715
2939
|
* Includes connectionId for WebSocket push notification of verification result.
|
|
2716
2940
|
*/
|
|
2717
|
-
async sendSparkLink(email, connectionId, authContext) {
|
|
2941
|
+
async sendSparkLink(email, connectionId, authContext, signinRef) {
|
|
2718
2942
|
return this.request('POST', apiPath `/sparklink/send`, {
|
|
2719
2943
|
email,
|
|
2720
2944
|
connection_id: connectionId,
|
|
2721
2945
|
...this.buildAuthContextParams(authContext),
|
|
2946
|
+
...signinRefParam(signinRef),
|
|
2722
2947
|
});
|
|
2723
2948
|
}
|
|
2724
2949
|
/**
|
|
@@ -2745,6 +2970,15 @@ class IdentityApi extends SparkVaultApi {
|
|
|
2745
2970
|
function verifySessionParam(authContext) {
|
|
2746
2971
|
return authContext?.simpleMode ? { simple_mode: { session_id: authContext.simpleMode.sessionId } } : {};
|
|
2747
2972
|
}
|
|
2973
|
+
/**
|
|
2974
|
+
* The sign-in's reference (app-sdk SIGNIN_REFERENCE) a call that completes a
|
|
2975
|
+
* sign-in carries, in a body or a provider start's query, so Identity records
|
|
2976
|
+
* it on the hub session the sign-in creates or chooses. None when the sign-in
|
|
2977
|
+
* has none.
|
|
2978
|
+
*/
|
|
2979
|
+
function signinRefParam(signinRef) {
|
|
2980
|
+
return signinRef ? { [SIGNIN_REFERENCE.param]: signinRef } : {};
|
|
2981
|
+
}
|
|
2748
2982
|
/**
|
|
2749
2983
|
* Read a SparkLink result event. The WebSocket push and the kindling reclaim
|
|
2750
2984
|
* carry the same server-built event, so this is the one reader for both.
|
|
@@ -3082,18 +3316,108 @@ const METHOD_REGISTRY = {
|
|
|
3082
3316
|
icon: 'linkedin',
|
|
3083
3317
|
provider: 'linkedin',
|
|
3084
3318
|
},
|
|
3319
|
+
// The account's own identity provider. Its button names the provider the
|
|
3320
|
+
// way the account named it in `/config` (`federation.display_name`), so its
|
|
3321
|
+
// `name` here is only the registry's placeholder (enrichMethods replaces it).
|
|
3322
|
+
federation: {
|
|
3323
|
+
id: 'federation',
|
|
3324
|
+
type: 'federation',
|
|
3325
|
+
name: 'Your organization',
|
|
3326
|
+
description: '',
|
|
3327
|
+
icon: 'building',
|
|
3328
|
+
},
|
|
3085
3329
|
};
|
|
3086
3330
|
/**
|
|
3087
3331
|
* Enrich method IDs with full metadata
|
|
3088
3332
|
* @param ids - Array of method IDs from config
|
|
3333
|
+
* @param federation - The account's own identity provider as `/config` describes it;
|
|
3334
|
+
* without it no `federation` method is offered, for its button has no name to show
|
|
3089
3335
|
* @returns Array of method metadata objects
|
|
3090
3336
|
*/
|
|
3091
|
-
function enrichMethods(ids) {
|
|
3337
|
+
function enrichMethods(ids, federation) {
|
|
3092
3338
|
return ids
|
|
3093
|
-
.map(id =>
|
|
3339
|
+
.map((id) => {
|
|
3340
|
+
if (id !== 'federation')
|
|
3341
|
+
return METHOD_REGISTRY[id];
|
|
3342
|
+
return federation ? { ...METHOD_REGISTRY.federation, name: federationButtonLabel(federation.display_name) } : undefined;
|
|
3343
|
+
})
|
|
3094
3344
|
.filter((m) => m !== undefined);
|
|
3095
3345
|
}
|
|
3096
3346
|
|
|
3347
|
+
/**
|
|
3348
|
+
* The browser side of a sign-in with the account's own identity provider, on
|
|
3349
|
+
* the Identity origin's sign-in pages: what the provider's round trip returned
|
|
3350
|
+
* in the fragment, and whether this tab already left for the provider without
|
|
3351
|
+
* the person's click.
|
|
3352
|
+
*
|
|
3353
|
+
* The Identity callback returns a sign-in the way it returns a social one
|
|
3354
|
+
* (`#token=…&state=…`, completed by `IdentityModule.render`), and its two
|
|
3355
|
+
* refusals as fragments of their own (app-sdk identity-signin-contract:
|
|
3356
|
+
* federationRefusalFragment writes them, federationRefusalIn reads them),
|
|
3357
|
+
* each with the `state` the start sent, read by `IdentityModule.render`
|
|
3358
|
+
* before the flow starts:
|
|
3359
|
+
* - `interaction_required`: a silent attempt the provider could not answer
|
|
3360
|
+
* without the person. The page offers the account's methods, this one
|
|
3361
|
+
* first, and never tries silently again.
|
|
3362
|
+
* - `failed`: the attempt failed. The page says so in fixed words, never
|
|
3363
|
+
* the provider's.
|
|
3364
|
+
*/
|
|
3365
|
+
/** The error view's code for a failed sign-in through the account's own identity provider. */
|
|
3366
|
+
const FEDERATION_FAILED = 'federation_failed';
|
|
3367
|
+
/**
|
|
3368
|
+
* Marks a tab that left for the provider without the person's click: the
|
|
3369
|
+
* silent first attempt, a start the caller asked for (`method: 'federation'`),
|
|
3370
|
+
* or the provider as the only method. A person who comes Back from the
|
|
3371
|
+
* provider's page reloads this page with no fragment, and the marker stops it
|
|
3372
|
+
* leaving on its own again, so Back is never forwarded to the provider. Read
|
|
3373
|
+
* and removed by the next sign-in on the page (takeFederationAutoStart). It
|
|
3374
|
+
* names its account, so a sign-in page for another account in the same tab is
|
|
3375
|
+
* never held back by it.
|
|
3376
|
+
*/
|
|
3377
|
+
const AUTO_START_KEY = 'sv_federation_auto_start';
|
|
3378
|
+
/** Identity's OAuth state lifetime: a round trip older than this cannot complete anyway. */
|
|
3379
|
+
const AUTO_START_TTL_MS = 15 * 60 * 1000;
|
|
3380
|
+
/** Record that this tab is leaving for the account's provider without the person's click. */
|
|
3381
|
+
function markFederationAutoStart(accountId) {
|
|
3382
|
+
try {
|
|
3383
|
+
sessionStorage.setItem(AUTO_START_KEY, JSON.stringify({ at: Date.now(), accountId }));
|
|
3384
|
+
}
|
|
3385
|
+
catch {
|
|
3386
|
+
// Storage disabled: the start's own state cannot be stored either, so the
|
|
3387
|
+
// sign-in fails before it leaves.
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3390
|
+
/**
|
|
3391
|
+
* Whether this tab left for this account's provider on its own within the
|
|
3392
|
+
* state's lifetime. The record is removed either way: whatever it said, the
|
|
3393
|
+
* page's next sign-in has read it.
|
|
3394
|
+
*/
|
|
3395
|
+
function takeFederationAutoStart(accountId) {
|
|
3396
|
+
let raw;
|
|
3397
|
+
try {
|
|
3398
|
+
raw = sessionStorage.getItem(AUTO_START_KEY);
|
|
3399
|
+
sessionStorage.removeItem(AUTO_START_KEY);
|
|
3400
|
+
}
|
|
3401
|
+
catch {
|
|
3402
|
+
return false;
|
|
3403
|
+
}
|
|
3404
|
+
if (raw === null)
|
|
3405
|
+
return false;
|
|
3406
|
+
try {
|
|
3407
|
+
const marker = JSON.parse(raw);
|
|
3408
|
+
if (typeof marker !== 'object' || marker === null)
|
|
3409
|
+
return false;
|
|
3410
|
+
const { at, accountId: markedAccount } = marker;
|
|
3411
|
+
return markedAccount === accountId
|
|
3412
|
+
&& typeof at === 'number'
|
|
3413
|
+
&& Number.isFinite(at)
|
|
3414
|
+
&& Date.now() - at < AUTO_START_TTL_MS;
|
|
3415
|
+
}
|
|
3416
|
+
catch {
|
|
3417
|
+
return false;
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
|
|
3097
3421
|
/**
|
|
3098
3422
|
* Verification State Manager
|
|
3099
3423
|
*
|
|
@@ -3116,6 +3440,8 @@ class VerificationState {
|
|
|
3116
3440
|
this._identityType = 'email';
|
|
3117
3441
|
// Auth context for OIDC/simple mode flows
|
|
3118
3442
|
this._authContext = undefined;
|
|
3443
|
+
// The sign-in's reference (app-sdk SIGNIN_REFERENCE), when the sign-in page has one
|
|
3444
|
+
this._signinRef = null;
|
|
3119
3445
|
// Passkey state
|
|
3120
3446
|
this._passkey = {
|
|
3121
3447
|
hasPasskey: null,
|
|
@@ -3191,6 +3517,14 @@ class VerificationState {
|
|
|
3191
3517
|
setAuthContext(context) {
|
|
3192
3518
|
this._authContext = context;
|
|
3193
3519
|
}
|
|
3520
|
+
// --- Sign-in reference ---
|
|
3521
|
+
/** The reference every call that completes this sign-in carries, else null. */
|
|
3522
|
+
get signinRef() {
|
|
3523
|
+
return this._signinRef;
|
|
3524
|
+
}
|
|
3525
|
+
setSigninRef(signinRef) {
|
|
3526
|
+
this._signinRef = signinRef;
|
|
3527
|
+
}
|
|
3194
3528
|
// --- Passkey State ---
|
|
3195
3529
|
get passkey() {
|
|
3196
3530
|
return this._passkey;
|
|
@@ -3304,6 +3638,11 @@ class PopupLauncher {
|
|
|
3304
3638
|
options.onReady?.();
|
|
3305
3639
|
return;
|
|
3306
3640
|
}
|
|
3641
|
+
if (options.requestType && data?.type === options.requestType) {
|
|
3642
|
+
if (event.source === popup)
|
|
3643
|
+
options.onRequest?.();
|
|
3644
|
+
return;
|
|
3645
|
+
}
|
|
3307
3646
|
if (data?.type !== options.resultType) {
|
|
3308
3647
|
return;
|
|
3309
3648
|
}
|
|
@@ -3495,6 +3834,7 @@ class PasskeyHandler {
|
|
|
3495
3834
|
session: challenge.session,
|
|
3496
3835
|
credential,
|
|
3497
3836
|
authContext: this.state.authContext,
|
|
3837
|
+
signinRef: this.state.signinRef,
|
|
3498
3838
|
});
|
|
3499
3839
|
return {
|
|
3500
3840
|
success: true,
|
|
@@ -3586,6 +3926,14 @@ class PasskeyHandler {
|
|
|
3586
3926
|
if (simpleMode) {
|
|
3587
3927
|
params.set('simple_mode', JSON.stringify(simpleMode));
|
|
3588
3928
|
}
|
|
3929
|
+
// The sign-in this ceremony completes, when the sign-in page has its
|
|
3930
|
+
// reference: the popup names it on the call that completes the sign-in, so
|
|
3931
|
+
// the hub session that call opens is bound to it and a lost result of this
|
|
3932
|
+
// sign-in still recovers.
|
|
3933
|
+
const { signinRef } = this.state;
|
|
3934
|
+
if (signinRef) {
|
|
3935
|
+
params.set(SIGNIN_REFERENCE.param, signinRef);
|
|
3936
|
+
}
|
|
3589
3937
|
const hash = mode === 'register' && registrationToken
|
|
3590
3938
|
? `#${new URLSearchParams({ registration_token: registrationToken }).toString()}`
|
|
3591
3939
|
: '';
|
|
@@ -3768,6 +4116,7 @@ class OtpHandler {
|
|
|
3768
4116
|
pin: code,
|
|
3769
4117
|
recipient: this.state.recipient,
|
|
3770
4118
|
authContext: this.state.authContext,
|
|
4119
|
+
signinRef: this.state.signinRef,
|
|
3771
4120
|
});
|
|
3772
4121
|
// Primary factor accepted, but the account requires a second factor.
|
|
3773
4122
|
// Not a success and not a retry — hand the ticket up to drive the 2FA step.
|
|
@@ -3836,7 +4185,7 @@ class SparkLinkHandler {
|
|
|
3836
4185
|
*/
|
|
3837
4186
|
async send(connectionId) {
|
|
3838
4187
|
try {
|
|
3839
|
-
const result = await this.api.sendSparkLink(this.state.recipient, connectionId, this.state.authContext);
|
|
4188
|
+
const result = await this.api.sendSparkLink(this.state.recipient, connectionId, this.state.authContext, this.state.signinRef);
|
|
3840
4189
|
return {
|
|
3841
4190
|
success: true,
|
|
3842
4191
|
expiresAt: result.expiresAt,
|
|
@@ -4015,16 +4364,25 @@ function validateOtpCode(code) {
|
|
|
4015
4364
|
class LoadingView {
|
|
4016
4365
|
constructor(props = {}) {
|
|
4017
4366
|
this.message = props.message ?? 'Loading...';
|
|
4367
|
+
if (props.announce === true) {
|
|
4368
|
+
this.announcement = this.message;
|
|
4369
|
+
}
|
|
4018
4370
|
}
|
|
4019
4371
|
render() {
|
|
4020
4372
|
const container = div('sv-loading');
|
|
4021
4373
|
const spinner = document.createElement('div');
|
|
4022
4374
|
spinner.className = 'sv-spinner';
|
|
4023
|
-
spinner.setAttribute('role', 'status');
|
|
4024
|
-
spinner.setAttribute('aria-label', 'Loading');
|
|
4025
4375
|
const text = document.createElement('p');
|
|
4026
4376
|
text.className = 'sv-loading-text';
|
|
4027
4377
|
text.textContent = this.message;
|
|
4378
|
+
if (this.announcement !== undefined) {
|
|
4379
|
+
spinner.setAttribute('aria-hidden', 'true');
|
|
4380
|
+
text.setAttribute('aria-hidden', 'true');
|
|
4381
|
+
}
|
|
4382
|
+
else {
|
|
4383
|
+
spinner.setAttribute('role', 'status');
|
|
4384
|
+
spinner.setAttribute('aria-label', 'Loading');
|
|
4385
|
+
}
|
|
4028
4386
|
container.appendChild(spinner);
|
|
4029
4387
|
container.appendChild(text);
|
|
4030
4388
|
return container;
|
|
@@ -4035,429 +4393,122 @@ class LoadingView {
|
|
|
4035
4393
|
}
|
|
4036
4394
|
|
|
4037
4395
|
/**
|
|
4038
|
-
*
|
|
4039
|
-
* SMS and voice consent beside a phone number, and the terms a signup
|
|
4040
|
-
* accepts. Each line is split around the documents it links, and each document
|
|
4041
|
-
* has its one address here: a surface draws the words between the links and
|
|
4042
|
-
* links each document at TERMS_URL or PRIVACY_URL.
|
|
4396
|
+
* SVG Icon Factory
|
|
4043
4397
|
*
|
|
4044
|
-
*
|
|
4398
|
+
* Bare outline glyphs per the SparkVault design system: stroke `currentColor`
|
|
4399
|
+
* so the stylesheet drives color, no tinted container backgrounds, round
|
|
4400
|
+
* caps/joins. Uses proper DOM element creation for security.
|
|
4045
4401
|
*/
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4402
|
+
function createSvgElement(viewBox, width = 16, height = 16) {
|
|
4403
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
4404
|
+
svg.setAttribute('viewBox', viewBox);
|
|
4405
|
+
svg.setAttribute('width', String(width));
|
|
4406
|
+
svg.setAttribute('height', String(height));
|
|
4407
|
+
svg.setAttribute('fill', 'none');
|
|
4408
|
+
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
4409
|
+
return svg;
|
|
4410
|
+
}
|
|
4411
|
+
function createPath(d, attrs = {}) {
|
|
4412
|
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
4413
|
+
path.setAttribute('d', d);
|
|
4414
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
4415
|
+
path.setAttribute(key, value);
|
|
4416
|
+
}
|
|
4417
|
+
return path;
|
|
4418
|
+
}
|
|
4419
|
+
function createCircle(cx, cy, r, attrs = {}) {
|
|
4420
|
+
const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
4421
|
+
circle.setAttribute('cx', String(cx));
|
|
4422
|
+
circle.setAttribute('cy', String(cy));
|
|
4423
|
+
circle.setAttribute('r', String(r));
|
|
4424
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
4425
|
+
circle.setAttribute(key, value);
|
|
4426
|
+
}
|
|
4427
|
+
return circle;
|
|
4428
|
+
}
|
|
4053
4429
|
/**
|
|
4054
|
-
*
|
|
4055
|
-
* calls (the sign-in field and the backup phone of Identity's sign-in, in
|
|
4056
|
-
* sdk-js and sdk-mobile, the mobile app's backup phone, and auth.sv's new
|
|
4057
|
-
* phone number), and under the sign-in's method picker wherever it offers a
|
|
4058
|
-
* text or a call: a phone number the sign-in was handed reaches the picker
|
|
4059
|
-
* without passing the field. The terms take the consent from whoever provides
|
|
4060
|
-
* the number, so the words fit a number typed and a number handed over alike.
|
|
4061
|
-
* A carrier approves the number SparkVault texts from only when this line, its
|
|
4062
|
-
* call to action, names the service, the consent, how often messages come,
|
|
4063
|
-
* that rates may apply, how to opt out and get help, and links the terms and
|
|
4064
|
-
* the privacy policy, so it says each of them. It agrees with the terms' SMS
|
|
4065
|
-
* and voice disclosures and the privacy policy (apps/www/terms.md 15,
|
|
4066
|
-
* apps/www/privacy.md 1.1, held to them by
|
|
4067
|
-
* apps/www/tests/consent-lines.test.mjs): texts carry the codes, alerts and
|
|
4068
|
-
* notifications they name and calls only the codes, STOP opts the number out,
|
|
4069
|
-
* HELP answers, frequency varies, rates may apply, and where texts and calls
|
|
4070
|
-
* go and how to opt back in (START or UNSTOP) are the terms' to say.
|
|
4430
|
+
* Checkmark icon for benefit lists
|
|
4071
4431
|
*/
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4432
|
+
function createCheckmarkIcon() {
|
|
4433
|
+
const svg = createSvgElement('0 0 16 16');
|
|
4434
|
+
svg.appendChild(createPath('M13.25 4.75L6 12 2.75 8.75', {
|
|
4435
|
+
stroke: 'currentColor',
|
|
4436
|
+
'stroke-width': '2',
|
|
4437
|
+
'stroke-linecap': 'round',
|
|
4438
|
+
'stroke-linejoin': 'round',
|
|
4439
|
+
}));
|
|
4440
|
+
return svg;
|
|
4441
|
+
}
|
|
4081
4442
|
/**
|
|
4082
|
-
*
|
|
4083
|
-
*
|
|
4084
|
-
* The line the sign-in shows wherever a person gives SparkVault a phone number
|
|
4085
|
-
* to text or call, in the platform's one wording
|
|
4086
|
-
* (`@sparkvault/app-sdk/consent-lines`): under every field that takes one, and
|
|
4087
|
-
* under the method picker wherever it offers a text or a call. It describes
|
|
4088
|
-
* the field or the methods above it, so a screen reader reads it with them.
|
|
4443
|
+
* Back arrow (chevron left)
|
|
4089
4444
|
*/
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
return
|
|
4445
|
+
function createBackArrowIcon() {
|
|
4446
|
+
const svg = createSvgElement('0 0 16 16');
|
|
4447
|
+
svg.appendChild(createPath('M10 12L6 8L10 4', {
|
|
4448
|
+
stroke: 'currentColor',
|
|
4449
|
+
'stroke-width': '2',
|
|
4450
|
+
'stroke-linecap': 'round',
|
|
4451
|
+
'stroke-linejoin': 'round',
|
|
4452
|
+
}));
|
|
4453
|
+
return svg;
|
|
4099
4454
|
}
|
|
4100
4455
|
/**
|
|
4101
|
-
*
|
|
4102
|
-
* in a new tab.
|
|
4103
|
-
*
|
|
4104
|
-
* @param id - The line's id, which the field or each method names in its `aria-describedby`
|
|
4456
|
+
* Close (X) icon
|
|
4105
4457
|
*/
|
|
4106
|
-
function
|
|
4107
|
-
const
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4458
|
+
function createCloseIcon() {
|
|
4459
|
+
const svg = createSvgElement('0 0 20 20', 20, 20);
|
|
4460
|
+
svg.appendChild(createPath('M15 5L5 15M5 5L15 15', {
|
|
4461
|
+
stroke: 'currentColor',
|
|
4462
|
+
'stroke-width': '1.5',
|
|
4463
|
+
'stroke-linecap': 'round',
|
|
4464
|
+
}));
|
|
4465
|
+
return svg;
|
|
4112
4466
|
}
|
|
4113
|
-
|
|
4114
4467
|
/**
|
|
4115
|
-
*
|
|
4116
|
-
*
|
|
4117
|
-
* Collects and validates the user's email or phone number: reads the input as
|
|
4118
|
-
* one or the other by the platform's rules (`@sparkvault/app-sdk/phone` and
|
|
4119
|
-
* `@sparkvault/app-sdk/email-address`), and formats a phone-only field as the
|
|
4120
|
-
* number is typed. A field that takes a phone number carries the SMS and voice
|
|
4121
|
-
* consent beneath it.
|
|
4468
|
+
* Passkey icon - bare outline key design
|
|
4122
4469
|
*/
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
}
|
|
4146
|
-
get allowsEmail() {
|
|
4147
|
-
return this.props.allowedTypes.includes('email');
|
|
4148
|
-
}
|
|
4149
|
-
get allowsPhone() {
|
|
4150
|
-
return this.props.allowedTypes.includes('phone');
|
|
4151
|
-
}
|
|
4152
|
-
render() {
|
|
4153
|
-
const container = div('sv-email-view');
|
|
4154
|
-
// Compact header - just the subtitle instruction
|
|
4155
|
-
const headerSection = div('sv-email-header');
|
|
4156
|
-
const subtitle = document.createElement('p');
|
|
4157
|
-
subtitle.className = 'sv-email-subtitle';
|
|
4158
|
-
subtitle.textContent = this.getSubtitleText();
|
|
4159
|
-
headerSection.appendChild(subtitle);
|
|
4160
|
-
container.appendChild(headerSection);
|
|
4161
|
-
// Error container
|
|
4162
|
-
this.errorContainer = div('sv-email-error-container');
|
|
4163
|
-
if (this.props.error) {
|
|
4164
|
-
this.errorContainer.appendChild(errorMessage(this.props.error));
|
|
4165
|
-
}
|
|
4166
|
-
container.appendChild(this.errorContainer);
|
|
4167
|
-
// Form section
|
|
4168
|
-
const formSection = div('sv-email-form');
|
|
4169
|
-
const inputWrapper = div('sv-email-input-wrapper');
|
|
4170
|
-
this.labelElement = document.createElement('label');
|
|
4171
|
-
this.labelElement.className = 'sv-email-label';
|
|
4172
|
-
this.labelElement.htmlFor = 'sv-identity-input';
|
|
4173
|
-
this.labelElement.textContent = this.getLabelText();
|
|
4174
|
-
this.inputElement = document.createElement('input');
|
|
4175
|
-
this.inputElement.type = this.allowsPhone && !this.allowsEmail ? 'tel' : 'text';
|
|
4176
|
-
this.inputElement.id = 'sv-identity-input';
|
|
4177
|
-
this.inputElement.className = 'sv-email-input';
|
|
4178
|
-
this.inputElement.placeholder = this.getPlaceholderText();
|
|
4179
|
-
this.inputElement.autocomplete = this.allowsBoth ? 'on' : (this.allowsEmail ? 'email' : 'tel');
|
|
4180
|
-
this.inputElement.required = true;
|
|
4181
|
-
this.inputElement.maxLength = EMAIL_ADDRESS_LIMITS.ADDRESS;
|
|
4182
|
-
if (this.props.initialValue) {
|
|
4183
|
-
this.inputElement.value = this.props.initialValue;
|
|
4184
|
-
this.detectAndUpdateType(this.props.initialValue);
|
|
4185
|
-
}
|
|
4186
|
-
this.inputElement.addEventListener('input', this.boundHandleInput);
|
|
4187
|
-
this.inputElement.addEventListener('keydown', this.boundHandleKeyDown);
|
|
4188
|
-
inputWrapper.appendChild(this.labelElement);
|
|
4189
|
-
inputWrapper.appendChild(this.inputElement);
|
|
4190
|
-
if (this.allowsPhone) {
|
|
4191
|
-
const consent = smsConsent('sv-identity-sms-consent');
|
|
4192
|
-
this.inputElement.setAttribute('aria-describedby', consent.id);
|
|
4193
|
-
inputWrapper.appendChild(consent);
|
|
4194
|
-
}
|
|
4195
|
-
formSection.appendChild(inputWrapper);
|
|
4196
|
-
this.submitButton = document.createElement('button');
|
|
4197
|
-
this.submitButton.className = 'sv-btn sv-btn-email-primary';
|
|
4198
|
-
this.submitButton.textContent = 'Continue';
|
|
4199
|
-
this.submitButton.addEventListener('click', this.boundHandleSubmit);
|
|
4200
|
-
formSection.appendChild(this.submitButton);
|
|
4201
|
-
container.appendChild(formSection);
|
|
4202
|
-
if (this.boundHandlePasskey) {
|
|
4203
|
-
this.passkeyLink = document.createElement('button');
|
|
4204
|
-
this.passkeyLink.className = 'sv-fallback-link';
|
|
4205
|
-
this.passkeyLink.textContent = 'Sign in with a passkey';
|
|
4206
|
-
this.passkeyLink.addEventListener('click', this.boundHandlePasskey);
|
|
4207
|
-
container.appendChild(this.passkeyLink);
|
|
4208
|
-
}
|
|
4209
|
-
this.focusTimeoutId = setTimeout(() => this.inputElement?.focus(), 50);
|
|
4210
|
-
return container;
|
|
4211
|
-
}
|
|
4212
|
-
getSubtitleText() {
|
|
4213
|
-
if (this.allowsBoth)
|
|
4214
|
-
return 'Enter your email or phone to continue';
|
|
4215
|
-
if (this.allowsPhone)
|
|
4216
|
-
return 'Enter your phone number to continue';
|
|
4217
|
-
return 'Enter your email to continue';
|
|
4218
|
-
}
|
|
4219
|
-
getLabelText() {
|
|
4220
|
-
if (this.allowsBoth) {
|
|
4221
|
-
return this.detectedType === 'phone' ? 'Phone number' : 'Email address';
|
|
4222
|
-
}
|
|
4223
|
-
if (this.allowsPhone)
|
|
4224
|
-
return 'Phone number';
|
|
4225
|
-
return 'Email address';
|
|
4226
|
-
}
|
|
4227
|
-
getPlaceholderText() {
|
|
4228
|
-
if (this.allowsBoth)
|
|
4229
|
-
return 'you@example.com or (555) 123-4567';
|
|
4230
|
-
if (this.allowsPhone)
|
|
4231
|
-
return '(555) 123-4567';
|
|
4232
|
-
return 'you@example.com';
|
|
4233
|
-
}
|
|
4234
|
-
handleInput() {
|
|
4235
|
-
this.clearError();
|
|
4236
|
-
if (!this.inputElement)
|
|
4237
|
-
return;
|
|
4238
|
-
const value = this.inputElement.value;
|
|
4239
|
-
if (this.allowsBoth) {
|
|
4240
|
-
// The label follows what the input reads as, but the text is never
|
|
4241
|
-
// rewritten: digits typed so far can still begin an email address
|
|
4242
|
-
// ("2024user@gmail.com", "12345678@qq.com"), and phone formatting would
|
|
4243
|
-
// corrupt it. Submit normalizes a phone number whatever its separators.
|
|
4244
|
-
const wasPhone = this.detectedType === 'phone';
|
|
4245
|
-
this.detectAndUpdateType(value);
|
|
4246
|
-
if (wasPhone !== (this.detectedType === 'phone') && this.labelElement) {
|
|
4247
|
-
this.labelElement.textContent = this.getLabelText();
|
|
4248
|
-
}
|
|
4249
|
-
}
|
|
4250
|
-
else if (this.allowsPhone) {
|
|
4251
|
-
// Phone-only mode: always format
|
|
4252
|
-
const cursorPos = this.inputElement.selectionStart ?? value.length;
|
|
4253
|
-
const formatted = formatPhoneDisplay(value);
|
|
4254
|
-
if (formatted !== value) {
|
|
4255
|
-
this.inputElement.value = formatted;
|
|
4256
|
-
const newPos = Math.min(cursorPos + (formatted.length - value.length), formatted.length);
|
|
4257
|
-
this.inputElement.setSelectionRange(newPos, newPos);
|
|
4258
|
-
}
|
|
4259
|
-
}
|
|
4260
|
-
}
|
|
4261
|
-
detectAndUpdateType(value) {
|
|
4262
|
-
this.detectedType = inferIdentityType(value);
|
|
4263
|
-
}
|
|
4264
|
-
clearError() {
|
|
4265
|
-
if (this.errorContainer) {
|
|
4266
|
-
clearChildren(this.errorContainer);
|
|
4267
|
-
}
|
|
4268
|
-
this.inputElement?.classList.remove('sv-email-input-error');
|
|
4269
|
-
}
|
|
4270
|
-
showError(message) {
|
|
4271
|
-
if (this.errorContainer) {
|
|
4272
|
-
clearChildren(this.errorContainer);
|
|
4273
|
-
this.errorContainer.appendChild(errorMessage(message));
|
|
4274
|
-
}
|
|
4275
|
-
this.inputElement?.classList.add('sv-email-input-error');
|
|
4276
|
-
this.inputElement?.focus();
|
|
4277
|
-
}
|
|
4278
|
-
handleSubmit() {
|
|
4279
|
-
if (!this.inputElement || !this.submitButton)
|
|
4280
|
-
return;
|
|
4281
|
-
const rawValue = this.inputElement.value;
|
|
4282
|
-
// Validate based on detected type
|
|
4283
|
-
if (this.allowsBoth) {
|
|
4284
|
-
if (this.detectedType === 'phone') {
|
|
4285
|
-
const validPhone = parsePhone(rawValue);
|
|
4286
|
-
if (!validPhone) {
|
|
4287
|
-
this.showError('Please enter a valid phone number');
|
|
4288
|
-
return;
|
|
4289
|
-
}
|
|
4290
|
-
this.submitButton.disabled = true;
|
|
4291
|
-
this.submitButton.textContent = 'Please wait...';
|
|
4292
|
-
this.props.onSubmit({ value: validPhone, type: 'phone' });
|
|
4293
|
-
}
|
|
4294
|
-
else {
|
|
4295
|
-
const validEmail = validateEmail(rawValue);
|
|
4296
|
-
if (!validEmail) {
|
|
4297
|
-
this.showError('Please enter a valid email address');
|
|
4298
|
-
return;
|
|
4299
|
-
}
|
|
4300
|
-
this.submitButton.disabled = true;
|
|
4301
|
-
this.submitButton.textContent = 'Please wait...';
|
|
4302
|
-
this.props.onSubmit({ value: validEmail, type: 'email' });
|
|
4303
|
-
}
|
|
4304
|
-
}
|
|
4305
|
-
else if (this.allowsPhone) {
|
|
4306
|
-
const validPhone = parsePhone(rawValue);
|
|
4307
|
-
if (!validPhone) {
|
|
4308
|
-
this.showError('Please enter a valid phone number');
|
|
4309
|
-
return;
|
|
4310
|
-
}
|
|
4311
|
-
this.submitButton.disabled = true;
|
|
4312
|
-
this.submitButton.textContent = 'Please wait...';
|
|
4313
|
-
this.props.onSubmit({ value: validPhone, type: 'phone' });
|
|
4314
|
-
}
|
|
4315
|
-
else {
|
|
4316
|
-
const validEmail = validateEmail(rawValue);
|
|
4317
|
-
if (!validEmail) {
|
|
4318
|
-
this.showError('Please enter a valid email address');
|
|
4319
|
-
return;
|
|
4320
|
-
}
|
|
4321
|
-
this.submitButton.disabled = true;
|
|
4322
|
-
this.submitButton.textContent = 'Please wait...';
|
|
4323
|
-
this.props.onSubmit({ value: validEmail, type: 'email' });
|
|
4324
|
-
}
|
|
4325
|
-
}
|
|
4326
|
-
destroy() {
|
|
4327
|
-
if (this.focusTimeoutId !== null) {
|
|
4328
|
-
clearTimeout(this.focusTimeoutId);
|
|
4329
|
-
this.focusTimeoutId = null;
|
|
4330
|
-
}
|
|
4331
|
-
if (this.inputElement) {
|
|
4332
|
-
this.inputElement.removeEventListener('input', this.boundHandleInput);
|
|
4333
|
-
this.inputElement.removeEventListener('keydown', this.boundHandleKeyDown);
|
|
4334
|
-
}
|
|
4335
|
-
if (this.submitButton) {
|
|
4336
|
-
this.submitButton.removeEventListener('click', this.boundHandleSubmit);
|
|
4337
|
-
}
|
|
4338
|
-
if (this.passkeyLink && this.boundHandlePasskey) {
|
|
4339
|
-
this.passkeyLink.removeEventListener('click', this.boundHandlePasskey);
|
|
4340
|
-
}
|
|
4341
|
-
}
|
|
4470
|
+
function createPasskeyIcon() {
|
|
4471
|
+
const svg = createSvgElement('0 0 56 56', 56, 56);
|
|
4472
|
+
svg.classList.add('sv-passkey-icon');
|
|
4473
|
+
// Key glyph optically centered in the 56px box (footprint unchanged)
|
|
4474
|
+
const group = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
4475
|
+
group.setAttribute('transform', 'translate(29.5, 26.5)');
|
|
4476
|
+
const strokeAttrs = {
|
|
4477
|
+
stroke: 'currentColor',
|
|
4478
|
+
'stroke-width': '3',
|
|
4479
|
+
'stroke-linecap': 'round',
|
|
4480
|
+
'stroke-linejoin': 'round',
|
|
4481
|
+
fill: 'none',
|
|
4482
|
+
};
|
|
4483
|
+
// Key head (circle)
|
|
4484
|
+
group.appendChild(createCircle(-9.5, -9.5, 9.5, strokeAttrs));
|
|
4485
|
+
// Key shaft
|
|
4486
|
+
group.appendChild(createPath('M-2.8 -2.8L16 16', strokeAttrs));
|
|
4487
|
+
// Key teeth
|
|
4488
|
+
group.appendChild(createPath('M9.5 9.5L9.5 15.5', strokeAttrs));
|
|
4489
|
+
group.appendChild(createPath('M16 16L16 22', strokeAttrs));
|
|
4490
|
+
svg.appendChild(group);
|
|
4491
|
+
return svg;
|
|
4342
4492
|
}
|
|
4343
|
-
|
|
4344
4493
|
/**
|
|
4345
|
-
*
|
|
4346
|
-
*
|
|
4347
|
-
* Bare outline glyphs per the SparkVault design system: stroke `currentColor`
|
|
4348
|
-
* so the stylesheet drives color, no tinted container backgrounds, round
|
|
4349
|
-
* caps/joins. Uses proper DOM element creation for security.
|
|
4494
|
+
* Bare outline alert triangle shared by the error and expired icons.
|
|
4495
|
+
* Color comes from `currentColor` via the class-specific stylesheet rules.
|
|
4350
4496
|
*/
|
|
4351
|
-
function
|
|
4352
|
-
const svg =
|
|
4353
|
-
svg.
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
}
|
|
4366
|
-
return path;
|
|
4367
|
-
}
|
|
4368
|
-
function createCircle(cx, cy, r, attrs = {}) {
|
|
4369
|
-
const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
4370
|
-
circle.setAttribute('cx', String(cx));
|
|
4371
|
-
circle.setAttribute('cy', String(cy));
|
|
4372
|
-
circle.setAttribute('r', String(r));
|
|
4373
|
-
for (const [key, value] of Object.entries(attrs)) {
|
|
4374
|
-
circle.setAttribute(key, value);
|
|
4375
|
-
}
|
|
4376
|
-
return circle;
|
|
4377
|
-
}
|
|
4378
|
-
/**
|
|
4379
|
-
* Checkmark icon for benefit lists
|
|
4380
|
-
*/
|
|
4381
|
-
function createCheckmarkIcon() {
|
|
4382
|
-
const svg = createSvgElement('0 0 16 16');
|
|
4383
|
-
svg.appendChild(createPath('M13.25 4.75L6 12 2.75 8.75', {
|
|
4384
|
-
stroke: 'currentColor',
|
|
4385
|
-
'stroke-width': '2',
|
|
4386
|
-
'stroke-linecap': 'round',
|
|
4387
|
-
'stroke-linejoin': 'round',
|
|
4388
|
-
}));
|
|
4389
|
-
return svg;
|
|
4390
|
-
}
|
|
4391
|
-
/**
|
|
4392
|
-
* Back arrow (chevron left)
|
|
4393
|
-
*/
|
|
4394
|
-
function createBackArrowIcon() {
|
|
4395
|
-
const svg = createSvgElement('0 0 16 16');
|
|
4396
|
-
svg.appendChild(createPath('M10 12L6 8L10 4', {
|
|
4397
|
-
stroke: 'currentColor',
|
|
4398
|
-
'stroke-width': '2',
|
|
4399
|
-
'stroke-linecap': 'round',
|
|
4400
|
-
'stroke-linejoin': 'round',
|
|
4401
|
-
}));
|
|
4402
|
-
return svg;
|
|
4403
|
-
}
|
|
4404
|
-
/**
|
|
4405
|
-
* Close (X) icon
|
|
4406
|
-
*/
|
|
4407
|
-
function createCloseIcon() {
|
|
4408
|
-
const svg = createSvgElement('0 0 20 20', 20, 20);
|
|
4409
|
-
svg.appendChild(createPath('M15 5L5 15M5 5L15 15', {
|
|
4410
|
-
stroke: 'currentColor',
|
|
4411
|
-
'stroke-width': '1.5',
|
|
4412
|
-
'stroke-linecap': 'round',
|
|
4413
|
-
}));
|
|
4414
|
-
return svg;
|
|
4415
|
-
}
|
|
4416
|
-
/**
|
|
4417
|
-
* Passkey icon - bare outline key design
|
|
4418
|
-
*/
|
|
4419
|
-
function createPasskeyIcon() {
|
|
4420
|
-
const svg = createSvgElement('0 0 56 56', 56, 56);
|
|
4421
|
-
svg.classList.add('sv-passkey-icon');
|
|
4422
|
-
// Key glyph optically centered in the 56px box (footprint unchanged)
|
|
4423
|
-
const group = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
4424
|
-
group.setAttribute('transform', 'translate(29.5, 26.5)');
|
|
4425
|
-
const strokeAttrs = {
|
|
4426
|
-
stroke: 'currentColor',
|
|
4427
|
-
'stroke-width': '3',
|
|
4428
|
-
'stroke-linecap': 'round',
|
|
4429
|
-
'stroke-linejoin': 'round',
|
|
4430
|
-
fill: 'none',
|
|
4431
|
-
};
|
|
4432
|
-
// Key head (circle)
|
|
4433
|
-
group.appendChild(createCircle(-9.5, -9.5, 9.5, strokeAttrs));
|
|
4434
|
-
// Key shaft
|
|
4435
|
-
group.appendChild(createPath('M-2.8 -2.8L16 16', strokeAttrs));
|
|
4436
|
-
// Key teeth
|
|
4437
|
-
group.appendChild(createPath('M9.5 9.5L9.5 15.5', strokeAttrs));
|
|
4438
|
-
group.appendChild(createPath('M16 16L16 22', strokeAttrs));
|
|
4439
|
-
svg.appendChild(group);
|
|
4440
|
-
return svg;
|
|
4441
|
-
}
|
|
4442
|
-
/**
|
|
4443
|
-
* Bare outline alert triangle shared by the error and expired icons.
|
|
4444
|
-
* Color comes from `currentColor` via the class-specific stylesheet rules.
|
|
4445
|
-
*/
|
|
4446
|
-
function createAlertTriangleIcon(className) {
|
|
4447
|
-
const svg = createSvgElement('0 0 48 48', 48, 48);
|
|
4448
|
-
svg.classList.add(className);
|
|
4449
|
-
const strokeAttrs = {
|
|
4450
|
-
stroke: 'currentColor',
|
|
4451
|
-
'stroke-width': '2.5',
|
|
4452
|
-
'stroke-linecap': 'round',
|
|
4453
|
-
'stroke-linejoin': 'round',
|
|
4454
|
-
fill: 'none',
|
|
4455
|
-
};
|
|
4456
|
-
// Triangle outline
|
|
4457
|
-
svg.appendChild(createPath('M24 9L5.5 39h37L24 9z', strokeAttrs));
|
|
4458
|
-
// Exclamation
|
|
4459
|
-
svg.appendChild(createPath('M24 20v8', strokeAttrs));
|
|
4460
|
-
svg.appendChild(createCircle(24, 33.5, 1.5, { fill: 'currentColor' }));
|
|
4497
|
+
function createAlertTriangleIcon(className) {
|
|
4498
|
+
const svg = createSvgElement('0 0 48 48', 48, 48);
|
|
4499
|
+
svg.classList.add(className);
|
|
4500
|
+
const strokeAttrs = {
|
|
4501
|
+
stroke: 'currentColor',
|
|
4502
|
+
'stroke-width': '2.5',
|
|
4503
|
+
'stroke-linecap': 'round',
|
|
4504
|
+
'stroke-linejoin': 'round',
|
|
4505
|
+
fill: 'none',
|
|
4506
|
+
};
|
|
4507
|
+
// Triangle outline
|
|
4508
|
+
svg.appendChild(createPath('M24 9L5.5 39h37L24 9z', strokeAttrs));
|
|
4509
|
+
// Exclamation
|
|
4510
|
+
svg.appendChild(createPath('M24 20v8', strokeAttrs));
|
|
4511
|
+
svg.appendChild(createCircle(24, 33.5, 1.5, { fill: 'currentColor' }));
|
|
4461
4512
|
return svg;
|
|
4462
4513
|
}
|
|
4463
4514
|
/**
|
|
@@ -4654,6 +4705,380 @@ function createUsersIcon() {
|
|
|
4654
4705
|
return svg;
|
|
4655
4706
|
}
|
|
4656
4707
|
|
|
4708
|
+
/**
|
|
4709
|
+
* Method Button
|
|
4710
|
+
*
|
|
4711
|
+
* A sign-in method's button, drawn one way wherever a method is offered: the
|
|
4712
|
+
* method list, and the identifier step that leads with the account's own
|
|
4713
|
+
* identity provider. The caller attaches its click handler, and removes it.
|
|
4714
|
+
*/
|
|
4715
|
+
/**
|
|
4716
|
+
* The button: its glyph, hidden from assistive technology so the button is
|
|
4717
|
+
* named by its words alone; the method's name; and its description, when it
|
|
4718
|
+
* has one.
|
|
4719
|
+
*/
|
|
4720
|
+
function methodButton(method) {
|
|
4721
|
+
const btn = document.createElement('button');
|
|
4722
|
+
btn.className = 'sv-btn sv-btn-method';
|
|
4723
|
+
const content = div('sv-method-content');
|
|
4724
|
+
const icon = div('sv-method-icon');
|
|
4725
|
+
icon.setAttribute('aria-hidden', 'true');
|
|
4726
|
+
icon.appendChild(createMethodIcon(method.icon));
|
|
4727
|
+
content.appendChild(icon);
|
|
4728
|
+
const text = div('sv-method-text');
|
|
4729
|
+
const name = document.createElement('div');
|
|
4730
|
+
name.className = 'sv-method-name';
|
|
4731
|
+
name.textContent = method.name;
|
|
4732
|
+
text.appendChild(name);
|
|
4733
|
+
if (method.description) {
|
|
4734
|
+
const description = document.createElement('div');
|
|
4735
|
+
description.className = 'sv-method-description';
|
|
4736
|
+
description.textContent = method.description;
|
|
4737
|
+
text.appendChild(description);
|
|
4738
|
+
}
|
|
4739
|
+
content.appendChild(text);
|
|
4740
|
+
btn.appendChild(content);
|
|
4741
|
+
return btn;
|
|
4742
|
+
}
|
|
4743
|
+
|
|
4744
|
+
/**
|
|
4745
|
+
* Two consent lines, each in one wording for every surface that shows it: the
|
|
4746
|
+
* SMS and voice consent beside a phone number, and the terms a signup
|
|
4747
|
+
* accepts. Each line is split around the documents it links, and each document
|
|
4748
|
+
* has its one address here: a surface draws the words between the links and
|
|
4749
|
+
* links each document at TERMS_URL or PRIVACY_URL.
|
|
4750
|
+
*
|
|
4751
|
+
* BROWSER-SAFE: data only, no imports. sdk-mobile mirrors it.
|
|
4752
|
+
*/
|
|
4753
|
+
|
|
4754
|
+
/** The terms of service, published once, on the marketing site. */
|
|
4755
|
+
const TERMS_URL = 'https://sparkvault.com/terms/';
|
|
4756
|
+
|
|
4757
|
+
/** The privacy policy, published once, on the marketing site. */
|
|
4758
|
+
const PRIVACY_URL = 'https://sparkvault.com/privacy/';
|
|
4759
|
+
|
|
4760
|
+
/**
|
|
4761
|
+
* Beside every field where a person enters a phone number SparkVault texts or
|
|
4762
|
+
* calls (the sign-in field and the backup phone of Identity's sign-in, in
|
|
4763
|
+
* sdk-js and sdk-mobile, the mobile app's backup phone, and auth.sv's new
|
|
4764
|
+
* phone number), and under the sign-in's method picker wherever it offers a
|
|
4765
|
+
* text or a call: a phone number the sign-in was handed reaches the picker
|
|
4766
|
+
* without passing the field. The terms take the consent from whoever provides
|
|
4767
|
+
* the number, so the words fit a number typed and a number handed over alike.
|
|
4768
|
+
* A carrier approves the number SparkVault texts from only when this line, its
|
|
4769
|
+
* call to action, names the service, the consent, how often messages come,
|
|
4770
|
+
* that rates may apply, how to opt out and get help, and links the terms and
|
|
4771
|
+
* the privacy policy, so it says each of them. It agrees with the terms' SMS
|
|
4772
|
+
* and voice disclosures and the privacy policy (apps/www/terms.md 15,
|
|
4773
|
+
* apps/www/privacy.md 1.1, held to them by
|
|
4774
|
+
* apps/www/tests/consent-lines.test.mjs): texts carry the codes, alerts and
|
|
4775
|
+
* notifications they name and calls only the codes, STOP opts the number out,
|
|
4776
|
+
* HELP answers, frequency varies, rates may apply, and where texts and calls
|
|
4777
|
+
* go and how to opt back in (START or UNSTOP) are the terms' to say.
|
|
4778
|
+
*/
|
|
4779
|
+
const SMS_CONSENT = Object.freeze({
|
|
4780
|
+
beforeTerms: 'By providing a phone number, you agree to receive texts from SparkVault with verification codes, security alerts and account notifications, and automated calls with verification codes, as its ',
|
|
4781
|
+
terms: 'Terms',
|
|
4782
|
+
beforePrivacy: ' and ',
|
|
4783
|
+
privacy: 'Privacy Policy',
|
|
4784
|
+
afterPrivacy: ' describe. Message frequency varies. Message and data rates may apply. Reply STOP to opt out or HELP for help.'
|
|
4785
|
+
});
|
|
4786
|
+
|
|
4787
|
+
/* global HTMLAnchorElement */
|
|
4788
|
+
/**
|
|
4789
|
+
* SMS and Voice Consent
|
|
4790
|
+
*
|
|
4791
|
+
* The line the sign-in shows wherever a person gives SparkVault a phone number
|
|
4792
|
+
* to text or call, in the platform's one wording
|
|
4793
|
+
* (`@sparkvault/app-sdk/consent-lines`): under every field that takes one, and
|
|
4794
|
+
* under the method picker wherever it offers a text or a call. It describes
|
|
4795
|
+
* the field or the methods above it, so a screen reader reads it with them.
|
|
4796
|
+
*/
|
|
4797
|
+
/** A document the line names, linked in place and opening in a new tab. */
|
|
4798
|
+
function documentLink(name, href) {
|
|
4799
|
+
const link = document.createElement('a');
|
|
4800
|
+
link.className = 'sv-sms-consent-link';
|
|
4801
|
+
link.href = href;
|
|
4802
|
+
link.target = '_blank';
|
|
4803
|
+
link.rel = 'noopener noreferrer';
|
|
4804
|
+
link.textContent = name;
|
|
4805
|
+
return link;
|
|
4806
|
+
}
|
|
4807
|
+
/**
|
|
4808
|
+
* The consent line, its "Terms" and "Privacy Policy" opening those documents
|
|
4809
|
+
* in a new tab.
|
|
4810
|
+
*
|
|
4811
|
+
* @param id - The line's id, which the field or each method names in its `aria-describedby`
|
|
4812
|
+
*/
|
|
4813
|
+
function smsConsent(id) {
|
|
4814
|
+
const line = document.createElement('p');
|
|
4815
|
+
line.className = 'sv-sms-consent';
|
|
4816
|
+
line.id = id;
|
|
4817
|
+
line.append(SMS_CONSENT.beforeTerms, documentLink(SMS_CONSENT.terms, TERMS_URL), SMS_CONSENT.beforePrivacy, documentLink(SMS_CONSENT.privacy, PRIVACY_URL), SMS_CONSENT.afterPrivacy);
|
|
4818
|
+
return line;
|
|
4819
|
+
}
|
|
4820
|
+
|
|
4821
|
+
/**
|
|
4822
|
+
* Identity Input View
|
|
4823
|
+
*
|
|
4824
|
+
* Collects and validates the user's email or phone number: reads the input as
|
|
4825
|
+
* one or the other by the platform's rules (`@sparkvault/app-sdk/phone` and
|
|
4826
|
+
* `@sparkvault/app-sdk/email-address`), and formats a phone-only field as the
|
|
4827
|
+
* number is typed. A field that takes a phone number carries the SMS and voice
|
|
4828
|
+
* consent beneath it.
|
|
4829
|
+
*/
|
|
4830
|
+
class IdentityInputView {
|
|
4831
|
+
constructor(props) {
|
|
4832
|
+
this.container = null;
|
|
4833
|
+
this.inputElement = null;
|
|
4834
|
+
this.labelElement = null;
|
|
4835
|
+
this.submitButton = null;
|
|
4836
|
+
this.passkeyLink = null;
|
|
4837
|
+
this.leadingButton = null;
|
|
4838
|
+
this.leadingHandler = null;
|
|
4839
|
+
this.errorContainer = null;
|
|
4840
|
+
this.focusTimeoutId = null;
|
|
4841
|
+
this.detectedType = 'email';
|
|
4842
|
+
this.props = props;
|
|
4843
|
+
this.boundHandleInput = () => {
|
|
4844
|
+
this.handleInput();
|
|
4845
|
+
this.props.onType?.();
|
|
4846
|
+
};
|
|
4847
|
+
this.boundHandleKeyDown = (e) => {
|
|
4848
|
+
if (e.key === 'Enter') {
|
|
4849
|
+
e.preventDefault();
|
|
4850
|
+
this.handleSubmit();
|
|
4851
|
+
}
|
|
4852
|
+
};
|
|
4853
|
+
this.boundHandleSubmit = () => this.handleSubmit();
|
|
4854
|
+
this.boundHandlePasskey = props.onPasskey ? () => props.onPasskey() : null;
|
|
4855
|
+
}
|
|
4856
|
+
get allowsBoth() {
|
|
4857
|
+
return this.props.allowedTypes.includes('email') && this.props.allowedTypes.includes('phone');
|
|
4858
|
+
}
|
|
4859
|
+
get allowsEmail() {
|
|
4860
|
+
return this.props.allowedTypes.includes('email');
|
|
4861
|
+
}
|
|
4862
|
+
get allowsPhone() {
|
|
4863
|
+
return this.props.allowedTypes.includes('phone');
|
|
4864
|
+
}
|
|
4865
|
+
render() {
|
|
4866
|
+
const container = div('sv-email-view');
|
|
4867
|
+
this.container = container;
|
|
4868
|
+
if (this.props.leadingMethod) {
|
|
4869
|
+
this.offerLeadingMethod(this.props.leadingMethod);
|
|
4870
|
+
}
|
|
4871
|
+
// Compact header - just the subtitle instruction
|
|
4872
|
+
const headerSection = div('sv-email-header');
|
|
4873
|
+
const subtitle = document.createElement('p');
|
|
4874
|
+
subtitle.className = 'sv-email-subtitle';
|
|
4875
|
+
subtitle.textContent = this.getSubtitleText();
|
|
4876
|
+
headerSection.appendChild(subtitle);
|
|
4877
|
+
container.appendChild(headerSection);
|
|
4878
|
+
// Error container
|
|
4879
|
+
this.errorContainer = div('sv-email-error-container');
|
|
4880
|
+
if (this.props.error) {
|
|
4881
|
+
this.errorContainer.appendChild(errorMessage(this.props.error));
|
|
4882
|
+
}
|
|
4883
|
+
container.appendChild(this.errorContainer);
|
|
4884
|
+
// Form section
|
|
4885
|
+
const formSection = div('sv-email-form');
|
|
4886
|
+
const inputWrapper = div('sv-email-input-wrapper');
|
|
4887
|
+
this.labelElement = document.createElement('label');
|
|
4888
|
+
this.labelElement.className = 'sv-email-label';
|
|
4889
|
+
this.labelElement.htmlFor = 'sv-identity-input';
|
|
4890
|
+
this.labelElement.textContent = this.getLabelText();
|
|
4891
|
+
this.inputElement = document.createElement('input');
|
|
4892
|
+
this.inputElement.type = this.allowsPhone && !this.allowsEmail ? 'tel' : 'text';
|
|
4893
|
+
this.inputElement.id = 'sv-identity-input';
|
|
4894
|
+
this.inputElement.className = 'sv-email-input';
|
|
4895
|
+
this.inputElement.placeholder = this.getPlaceholderText();
|
|
4896
|
+
this.inputElement.autocomplete = this.allowsBoth ? 'on' : (this.allowsEmail ? 'email' : 'tel');
|
|
4897
|
+
this.inputElement.required = true;
|
|
4898
|
+
this.inputElement.maxLength = EMAIL_ADDRESS_LIMITS.ADDRESS;
|
|
4899
|
+
if (this.props.initialValue) {
|
|
4900
|
+
this.inputElement.value = this.props.initialValue;
|
|
4901
|
+
this.detectAndUpdateType(this.props.initialValue);
|
|
4902
|
+
}
|
|
4903
|
+
this.inputElement.addEventListener('input', this.boundHandleInput);
|
|
4904
|
+
this.inputElement.addEventListener('keydown', this.boundHandleKeyDown);
|
|
4905
|
+
inputWrapper.appendChild(this.labelElement);
|
|
4906
|
+
inputWrapper.appendChild(this.inputElement);
|
|
4907
|
+
if (this.allowsPhone) {
|
|
4908
|
+
const consent = smsConsent('sv-identity-sms-consent');
|
|
4909
|
+
this.inputElement.setAttribute('aria-describedby', consent.id);
|
|
4910
|
+
inputWrapper.appendChild(consent);
|
|
4911
|
+
}
|
|
4912
|
+
formSection.appendChild(inputWrapper);
|
|
4913
|
+
this.submitButton = document.createElement('button');
|
|
4914
|
+
this.submitButton.className = 'sv-btn sv-btn-email-primary';
|
|
4915
|
+
this.submitButton.textContent = 'Continue';
|
|
4916
|
+
this.submitButton.addEventListener('click', this.boundHandleSubmit);
|
|
4917
|
+
formSection.appendChild(this.submitButton);
|
|
4918
|
+
container.appendChild(formSection);
|
|
4919
|
+
if (this.boundHandlePasskey) {
|
|
4920
|
+
this.passkeyLink = document.createElement('button');
|
|
4921
|
+
this.passkeyLink.className = 'sv-fallback-link';
|
|
4922
|
+
this.passkeyLink.textContent = 'Sign in with a passkey';
|
|
4923
|
+
this.passkeyLink.addEventListener('click', this.boundHandlePasskey);
|
|
4924
|
+
container.appendChild(this.passkeyLink);
|
|
4925
|
+
}
|
|
4926
|
+
this.focusTimeoutId = setTimeout(() => this.inputElement?.focus(), 50);
|
|
4927
|
+
return container;
|
|
4928
|
+
}
|
|
4929
|
+
/**
|
|
4930
|
+
* Offer `leading` above the field, set apart by "or". On a view already on
|
|
4931
|
+
* screen it joins in place, so what the person typed and where their focus
|
|
4932
|
+
* is stay as they were. A view that already leads with a method keeps it.
|
|
4933
|
+
*/
|
|
4934
|
+
offerLeadingMethod(leading) {
|
|
4935
|
+
if (!this.container || this.leadingButton)
|
|
4936
|
+
return;
|
|
4937
|
+
this.leadingHandler = leading.onSelect;
|
|
4938
|
+
this.leadingButton = methodButton(leading.method);
|
|
4939
|
+
this.leadingButton.addEventListener('click', this.leadingHandler);
|
|
4940
|
+
const divider = div('sv-divider');
|
|
4941
|
+
const or = document.createElement('span');
|
|
4942
|
+
or.className = 'sv-divider-text';
|
|
4943
|
+
or.textContent = 'or';
|
|
4944
|
+
divider.appendChild(or);
|
|
4945
|
+
this.container.prepend(this.leadingButton, divider);
|
|
4946
|
+
}
|
|
4947
|
+
getSubtitleText() {
|
|
4948
|
+
if (this.allowsBoth)
|
|
4949
|
+
return 'Enter your email or phone to continue';
|
|
4950
|
+
if (this.allowsPhone)
|
|
4951
|
+
return 'Enter your phone number to continue';
|
|
4952
|
+
return 'Enter your email to continue';
|
|
4953
|
+
}
|
|
4954
|
+
getLabelText() {
|
|
4955
|
+
if (this.allowsBoth) {
|
|
4956
|
+
return this.detectedType === 'phone' ? 'Phone number' : 'Email address';
|
|
4957
|
+
}
|
|
4958
|
+
if (this.allowsPhone)
|
|
4959
|
+
return 'Phone number';
|
|
4960
|
+
return 'Email address';
|
|
4961
|
+
}
|
|
4962
|
+
getPlaceholderText() {
|
|
4963
|
+
if (this.allowsBoth)
|
|
4964
|
+
return 'you@example.com or (555) 123-4567';
|
|
4965
|
+
if (this.allowsPhone)
|
|
4966
|
+
return '(555) 123-4567';
|
|
4967
|
+
return 'you@example.com';
|
|
4968
|
+
}
|
|
4969
|
+
handleInput() {
|
|
4970
|
+
this.clearError();
|
|
4971
|
+
if (!this.inputElement)
|
|
4972
|
+
return;
|
|
4973
|
+
const value = this.inputElement.value;
|
|
4974
|
+
if (this.allowsBoth) {
|
|
4975
|
+
// The label follows what the input reads as, but the text is never
|
|
4976
|
+
// rewritten: digits typed so far can still begin an email address
|
|
4977
|
+
// ("2024user@gmail.com", "12345678@qq.com"), and phone formatting would
|
|
4978
|
+
// corrupt it. Submit normalizes a phone number whatever its separators.
|
|
4979
|
+
const wasPhone = this.detectedType === 'phone';
|
|
4980
|
+
this.detectAndUpdateType(value);
|
|
4981
|
+
if (wasPhone !== (this.detectedType === 'phone') && this.labelElement) {
|
|
4982
|
+
this.labelElement.textContent = this.getLabelText();
|
|
4983
|
+
}
|
|
4984
|
+
}
|
|
4985
|
+
else if (this.allowsPhone) {
|
|
4986
|
+
// Phone-only mode: always format
|
|
4987
|
+
const cursorPos = this.inputElement.selectionStart ?? value.length;
|
|
4988
|
+
const formatted = formatPhoneDisplay(value);
|
|
4989
|
+
if (formatted !== value) {
|
|
4990
|
+
this.inputElement.value = formatted;
|
|
4991
|
+
const newPos = Math.min(cursorPos + (formatted.length - value.length), formatted.length);
|
|
4992
|
+
this.inputElement.setSelectionRange(newPos, newPos);
|
|
4993
|
+
}
|
|
4994
|
+
}
|
|
4995
|
+
}
|
|
4996
|
+
detectAndUpdateType(value) {
|
|
4997
|
+
this.detectedType = inferIdentityType(value);
|
|
4998
|
+
}
|
|
4999
|
+
clearError() {
|
|
5000
|
+
if (this.errorContainer) {
|
|
5001
|
+
clearChildren(this.errorContainer);
|
|
5002
|
+
}
|
|
5003
|
+
this.inputElement?.classList.remove('sv-email-input-error');
|
|
5004
|
+
}
|
|
5005
|
+
showError(message) {
|
|
5006
|
+
if (this.errorContainer) {
|
|
5007
|
+
clearChildren(this.errorContainer);
|
|
5008
|
+
this.errorContainer.appendChild(errorMessage(message));
|
|
5009
|
+
}
|
|
5010
|
+
this.inputElement?.classList.add('sv-email-input-error');
|
|
5011
|
+
this.inputElement?.focus();
|
|
5012
|
+
}
|
|
5013
|
+
handleSubmit() {
|
|
5014
|
+
if (!this.inputElement || !this.submitButton)
|
|
5015
|
+
return;
|
|
5016
|
+
const rawValue = this.inputElement.value;
|
|
5017
|
+
// Validate based on detected type
|
|
5018
|
+
if (this.allowsBoth) {
|
|
5019
|
+
if (this.detectedType === 'phone') {
|
|
5020
|
+
const validPhone = parsePhone(rawValue);
|
|
5021
|
+
if (!validPhone) {
|
|
5022
|
+
this.showError('Please enter a valid phone number');
|
|
5023
|
+
return;
|
|
5024
|
+
}
|
|
5025
|
+
this.submitButton.disabled = true;
|
|
5026
|
+
this.submitButton.textContent = 'Please wait...';
|
|
5027
|
+
this.props.onSubmit({ value: validPhone, type: 'phone' });
|
|
5028
|
+
}
|
|
5029
|
+
else {
|
|
5030
|
+
const validEmail = validateEmail(rawValue);
|
|
5031
|
+
if (!validEmail) {
|
|
5032
|
+
this.showError('Please enter a valid email address');
|
|
5033
|
+
return;
|
|
5034
|
+
}
|
|
5035
|
+
this.submitButton.disabled = true;
|
|
5036
|
+
this.submitButton.textContent = 'Please wait...';
|
|
5037
|
+
this.props.onSubmit({ value: validEmail, type: 'email' });
|
|
5038
|
+
}
|
|
5039
|
+
}
|
|
5040
|
+
else if (this.allowsPhone) {
|
|
5041
|
+
const validPhone = parsePhone(rawValue);
|
|
5042
|
+
if (!validPhone) {
|
|
5043
|
+
this.showError('Please enter a valid phone number');
|
|
5044
|
+
return;
|
|
5045
|
+
}
|
|
5046
|
+
this.submitButton.disabled = true;
|
|
5047
|
+
this.submitButton.textContent = 'Please wait...';
|
|
5048
|
+
this.props.onSubmit({ value: validPhone, type: 'phone' });
|
|
5049
|
+
}
|
|
5050
|
+
else {
|
|
5051
|
+
const validEmail = validateEmail(rawValue);
|
|
5052
|
+
if (!validEmail) {
|
|
5053
|
+
this.showError('Please enter a valid email address');
|
|
5054
|
+
return;
|
|
5055
|
+
}
|
|
5056
|
+
this.submitButton.disabled = true;
|
|
5057
|
+
this.submitButton.textContent = 'Please wait...';
|
|
5058
|
+
this.props.onSubmit({ value: validEmail, type: 'email' });
|
|
5059
|
+
}
|
|
5060
|
+
}
|
|
5061
|
+
destroy() {
|
|
5062
|
+
if (this.focusTimeoutId !== null) {
|
|
5063
|
+
clearTimeout(this.focusTimeoutId);
|
|
5064
|
+
this.focusTimeoutId = null;
|
|
5065
|
+
}
|
|
5066
|
+
if (this.inputElement) {
|
|
5067
|
+
this.inputElement.removeEventListener('input', this.boundHandleInput);
|
|
5068
|
+
this.inputElement.removeEventListener('keydown', this.boundHandleKeyDown);
|
|
5069
|
+
}
|
|
5070
|
+
if (this.submitButton) {
|
|
5071
|
+
this.submitButton.removeEventListener('click', this.boundHandleSubmit);
|
|
5072
|
+
}
|
|
5073
|
+
if (this.passkeyLink && this.boundHandlePasskey) {
|
|
5074
|
+
this.passkeyLink.removeEventListener('click', this.boundHandlePasskey);
|
|
5075
|
+
}
|
|
5076
|
+
if (this.leadingButton && this.leadingHandler) {
|
|
5077
|
+
this.leadingButton.removeEventListener('click', this.leadingHandler);
|
|
5078
|
+
}
|
|
5079
|
+
}
|
|
5080
|
+
}
|
|
5081
|
+
|
|
4657
5082
|
/**
|
|
4658
5083
|
* Method Select View
|
|
4659
5084
|
*
|
|
@@ -4668,6 +5093,7 @@ const textsOrCalls = (method) => method.identityType === 'phone';
|
|
|
4668
5093
|
class MethodSelectView {
|
|
4669
5094
|
constructor(props) {
|
|
4670
5095
|
this.backLink = null;
|
|
5096
|
+
this.methodsContainer = null;
|
|
4671
5097
|
this.methodButtons = [];
|
|
4672
5098
|
this.methodClickHandlers = new Map();
|
|
4673
5099
|
this.props = props;
|
|
@@ -4688,6 +5114,7 @@ class MethodSelectView {
|
|
|
4688
5114
|
}
|
|
4689
5115
|
const consent = this.props.methods.some(textsOrCalls) ? smsConsent('sv-method-sms-consent') : null;
|
|
4690
5116
|
const methodsContainer = div();
|
|
5117
|
+
this.methodsContainer = methodsContainer;
|
|
4691
5118
|
for (const method of this.props.methods) {
|
|
4692
5119
|
const methodButton = this.createMethodButton(method);
|
|
4693
5120
|
if (consent && textsOrCalls(method)) {
|
|
@@ -4709,6 +5136,18 @@ class MethodSelectView {
|
|
|
4709
5136
|
}
|
|
4710
5137
|
return container;
|
|
4711
5138
|
}
|
|
5139
|
+
/**
|
|
5140
|
+
* Put `method` at the head of a list already on screen, in place, so the
|
|
5141
|
+
* person's focus stays where it was. The method sends no text or call (the
|
|
5142
|
+
* account's own identity provider), so the list's consent stands as it is.
|
|
5143
|
+
*/
|
|
5144
|
+
offerLeadingMethod(method) {
|
|
5145
|
+
if (!this.methodsContainer)
|
|
5146
|
+
return;
|
|
5147
|
+
const button = this.createMethodButton(method);
|
|
5148
|
+
this.methodButtons.unshift(button);
|
|
5149
|
+
this.methodsContainer.prepend(button);
|
|
5150
|
+
}
|
|
4712
5151
|
createBackLink() {
|
|
4713
5152
|
const link = document.createElement('button');
|
|
4714
5153
|
link.className = 'sv-back-link';
|
|
@@ -4719,33 +5158,13 @@ class MethodSelectView {
|
|
|
4719
5158
|
return link;
|
|
4720
5159
|
}
|
|
4721
5160
|
createMethodButton(method) {
|
|
4722
|
-
const btn =
|
|
4723
|
-
btn.className = 'sv-btn sv-btn-method';
|
|
4724
|
-
const content = div('sv-method-content');
|
|
4725
|
-
const icon = this.getMethodIcon(method);
|
|
4726
|
-
content.appendChild(icon);
|
|
4727
|
-
const text = div('sv-method-text');
|
|
4728
|
-
const name = document.createElement('div');
|
|
4729
|
-
name.className = 'sv-method-name';
|
|
4730
|
-
name.textContent = method.name;
|
|
4731
|
-
const description = document.createElement('div');
|
|
4732
|
-
description.className = 'sv-method-description';
|
|
4733
|
-
description.textContent = method.description;
|
|
4734
|
-
text.appendChild(name);
|
|
4735
|
-
text.appendChild(description);
|
|
4736
|
-
content.appendChild(text);
|
|
4737
|
-
btn.appendChild(content);
|
|
5161
|
+
const btn = methodButton(method);
|
|
4738
5162
|
// Create and store handler reference for cleanup
|
|
4739
5163
|
const handler = () => this.props.onSelectMethod(method);
|
|
4740
5164
|
this.methodClickHandlers.set(btn, handler);
|
|
4741
5165
|
btn.addEventListener('click', handler);
|
|
4742
5166
|
return btn;
|
|
4743
5167
|
}
|
|
4744
|
-
getMethodIcon(method) {
|
|
4745
|
-
const iconContainer = div('sv-method-icon');
|
|
4746
|
-
iconContainer.appendChild(createMethodIcon(method.icon));
|
|
4747
|
-
return iconContainer;
|
|
4748
|
-
}
|
|
4749
5168
|
/**
|
|
4750
5169
|
* Clean up event listeners to prevent memory leaks.
|
|
4751
5170
|
*/
|
|
@@ -5853,6 +6272,18 @@ function isBlockedCode(code) {
|
|
|
5853
6272
|
* level they can clear (the message says so).
|
|
5854
6273
|
*/
|
|
5855
6274
|
const STRONGER_VERIFICATION_REQUIRED_CODE = 'stronger_verification_required';
|
|
6275
|
+
/**
|
|
6276
|
+
* The code of a sign-in whose only way in is the account's own identity
|
|
6277
|
+
* provider, on a page that may not offer it: the site's sign-in predates what
|
|
6278
|
+
* that provider needs, so only the site updating it clears this.
|
|
6279
|
+
*/
|
|
6280
|
+
const FEDERATION_UNAVAILABLE_CODE = 'federation_unavailable';
|
|
6281
|
+
/**
|
|
6282
|
+
* The code of a sign-in whose only way in is the account's own identity
|
|
6283
|
+
* provider, on a page that could not get its sign-in's reference just now:
|
|
6284
|
+
* a genuine error, which the person's Try Again asks for again.
|
|
6285
|
+
*/
|
|
6286
|
+
const SIGNIN_REFERENCE_UNAVAILABLE_CODE = 'signin_reference_unavailable';
|
|
5856
6287
|
/**
|
|
5857
6288
|
* The heading of a state the person can do nothing about from here, by its
|
|
5858
6289
|
* code, or null for a genuine error. Retrying cannot clear any of them, so the
|
|
@@ -5862,12 +6293,13 @@ const STRONGER_VERIFICATION_REQUIRED_CODE = 'stronger_verification_required';
|
|
|
5862
6293
|
* - a blocked Identity (trial exhausted or expired, or a paid capacity wall),
|
|
5863
6294
|
* which only the site owner subscribing clears, shown as a friendly,
|
|
5864
6295
|
* non-leaky interstitial;
|
|
5865
|
-
* - a request held to a passkey the person does not hold
|
|
6296
|
+
* - a request held to a passkey the person does not hold;
|
|
6297
|
+
* - an account whose only way in this page may not offer.
|
|
5866
6298
|
*/
|
|
5867
6299
|
function terminalTitle(code) {
|
|
5868
6300
|
if (code === 'identity_locked')
|
|
5869
6301
|
return 'This SparkVault Identity is locked';
|
|
5870
|
-
if (isBlockedCode(code))
|
|
6302
|
+
if (isBlockedCode(code) || code === FEDERATION_UNAVAILABLE_CODE)
|
|
5871
6303
|
return 'Sign-in unavailable';
|
|
5872
6304
|
if (code === STRONGER_VERIFICATION_REQUIRED_CODE)
|
|
5873
6305
|
return STRONGER_VERIFICATION_TITLE;
|
|
@@ -6468,6 +6900,12 @@ function blockedSignInMessage(companyName) {
|
|
|
6468
6900
|
: 'Sign-in is temporarily unavailable. Please contact the site owner for assistance.';
|
|
6469
6901
|
}
|
|
6470
6902
|
const BLOCKED_ERROR_CODES = new Set(IDENTITY_BLOCKED_ERROR_CODES);
|
|
6903
|
+
/**
|
|
6904
|
+
* How long the live region waits after a view is in place before it takes
|
|
6905
|
+
* the view's words: long enough that assistive technology has seen the
|
|
6906
|
+
* view's change and hears the region's as a change of its own.
|
|
6907
|
+
*/
|
|
6908
|
+
const STATUS_ANNOUNCE_DELAY_MS = 100;
|
|
6471
6909
|
const SPARKLINK_CSP_BLOCKED_ERROR = {
|
|
6472
6910
|
message: [
|
|
6473
6911
|
'Connection blocked by security policy.',
|
|
@@ -6477,7 +6915,7 @@ const SPARKLINK_CSP_BLOCKED_ERROR = {
|
|
|
6477
6915
|
code: 'sparklink_csp_blocked',
|
|
6478
6916
|
};
|
|
6479
6917
|
class IdentityRenderer {
|
|
6480
|
-
constructor(container, api, options, callbacks) {
|
|
6918
|
+
constructor(container, api, options, callbacks, federationReturn = null) {
|
|
6481
6919
|
// True while the identifier is the one the render options supplied (a host's
|
|
6482
6920
|
// prefill, a login hint, an invite's identity), false once the person types
|
|
6483
6921
|
// their own. Gates the "identity is fixed" behavior, so a no-hint
|
|
@@ -6505,10 +6943,29 @@ class IdentityRenderer {
|
|
|
6505
6943
|
this.sparkLinkVisibilityHandler = null;
|
|
6506
6944
|
this.sparkLinkClaiming = false;
|
|
6507
6945
|
this.sparkLinkRetryTimer = null;
|
|
6946
|
+
this.pageRestoreHandler = null;
|
|
6947
|
+
this.referenceAsk = null;
|
|
6948
|
+
this.referenceAsks = 0;
|
|
6949
|
+
// The sign-in step as it first showed, until the person types into it: a
|
|
6950
|
+
// reference that arrives while it is still on screen may start the
|
|
6951
|
+
// provider on its own, as one held from the start would have.
|
|
6952
|
+
this.untouchedStep = null;
|
|
6953
|
+
// The page's one live region: placed beside the flow content when the
|
|
6954
|
+
// container opens, empty, and kept across views, so the words a view
|
|
6955
|
+
// announces (View.announcement) land in a region already in the page, which
|
|
6956
|
+
// assistive technology hears change. A region created with its words already
|
|
6957
|
+
// in it is often never announced.
|
|
6958
|
+
this.statusRegion = null;
|
|
6959
|
+
this.statusTimer = null;
|
|
6508
6960
|
this.container = container;
|
|
6509
6961
|
this.api = api;
|
|
6510
6962
|
this.options = options;
|
|
6511
6963
|
this.callbacks = callbacks;
|
|
6964
|
+
this.federationReturn = federationReturn;
|
|
6965
|
+
// A start this tab made on its own, read (and removed) here: with no
|
|
6966
|
+
// fragment back, the person came Back from the provider's page.
|
|
6967
|
+
const leftOnItsOwn = takeFederationAutoStart(this.api.accountId);
|
|
6968
|
+
this.federationMayAutoStart = federationReturn === null && !leftOnItsOwn;
|
|
6512
6969
|
// Initialize centralized state
|
|
6513
6970
|
this.verificationState = new VerificationState();
|
|
6514
6971
|
// Initialize handlers with shared state
|
|
@@ -6521,6 +6978,20 @@ class IdentityRenderer {
|
|
|
6521
6978
|
if (options.authContext) {
|
|
6522
6979
|
this.verificationState.setAuthContext(options.authContext);
|
|
6523
6980
|
}
|
|
6981
|
+
// A sign-in through the account's own identity provider opens no hub
|
|
6982
|
+
// session, so a popup whose result is lost can recover it safely only by
|
|
6983
|
+
// its reference: /sso then refuses every hub session that does not carry
|
|
6984
|
+
// it. The page offers the provider only when told it may, never by what
|
|
6985
|
+
// it infers from its window: while it holds its reference (given at
|
|
6986
|
+
// once, or arriving through the function it was given), or, given none
|
|
6987
|
+
// at all, when it says it completes in its own window (it hands no opener
|
|
6988
|
+
// a result, so no recovery stands in for it). A page told it has none, a
|
|
6989
|
+
// value that is no reference, and a page told nothing (a sign-in page
|
|
6990
|
+
// that predates the reference, served from a cache) offer none.
|
|
6991
|
+
const { signinRef, completesInWindow } = options;
|
|
6992
|
+
this.askReference = typeof signinRef === 'function' ? signinRef : null;
|
|
6993
|
+
this.verificationState.setSigninRef(isSigninReference(signinRef) ? signinRef : null);
|
|
6994
|
+
this.offeredWithoutReference = signinRef === undefined && completesInWindow === true;
|
|
6524
6995
|
}
|
|
6525
6996
|
/**
|
|
6526
6997
|
* Seed the verification identity from the render options, deriving the
|
|
@@ -6585,6 +7056,9 @@ class IdentityRenderer {
|
|
|
6585
7056
|
* Otherwise shows loading state while fetching config.
|
|
6586
7057
|
*/
|
|
6587
7058
|
async start() {
|
|
7059
|
+
// Asked first, so a reference the page already holds or gets at once is
|
|
7060
|
+
// in place for the first step; the flow never waits on it.
|
|
7061
|
+
this.requestReference();
|
|
6588
7062
|
// Try to get config quickly if it was preloaded
|
|
6589
7063
|
// This races the config promise against a short timeout
|
|
6590
7064
|
let config = null;
|
|
@@ -6613,6 +7087,7 @@ class IdentityRenderer {
|
|
|
6613
7087
|
this.container.createLoading({
|
|
6614
7088
|
backdropBlur: this.options.backdropBlur,
|
|
6615
7089
|
}, () => this.handleClose());
|
|
7090
|
+
this.placeStatusRegion();
|
|
6616
7091
|
try {
|
|
6617
7092
|
if (!config) {
|
|
6618
7093
|
// Config not ready yet - show loading and await it
|
|
@@ -6646,6 +7121,7 @@ class IdentityRenderer {
|
|
|
6646
7121
|
showStartupError(error) {
|
|
6647
7122
|
if (!this.container.isOpen()) {
|
|
6648
7123
|
this.container.createLoading({ backdropBlur: this.options.backdropBlur }, () => this.handleClose());
|
|
7124
|
+
this.placeStatusRegion();
|
|
6649
7125
|
}
|
|
6650
7126
|
this.setState(this.viewStateForConfigError(error));
|
|
6651
7127
|
}
|
|
@@ -6719,6 +7195,8 @@ class IdentityRenderer {
|
|
|
6719
7195
|
close() {
|
|
6720
7196
|
// Cancel all pending API requests first
|
|
6721
7197
|
this.api.abort();
|
|
7198
|
+
// An answer to an open ask for the reference has no flow left to join.
|
|
7199
|
+
this.referenceAsks += 1;
|
|
6722
7200
|
// A pending discoverable ceremony would otherwise hold the browser sheet
|
|
6723
7201
|
// open against a dialog that no longer exists.
|
|
6724
7202
|
this.discoverableVerifyAbort?.abort();
|
|
@@ -6731,6 +7209,16 @@ class IdentityRenderer {
|
|
|
6731
7209
|
clearTimeout(this.morphTimer);
|
|
6732
7210
|
this.morphTimer = null;
|
|
6733
7211
|
}
|
|
7212
|
+
if (this.pageRestoreHandler) {
|
|
7213
|
+
window.removeEventListener('pageshow', this.pageRestoreHandler);
|
|
7214
|
+
this.pageRestoreHandler = null;
|
|
7215
|
+
}
|
|
7216
|
+
if (this.statusTimer !== null) {
|
|
7217
|
+
clearTimeout(this.statusTimer);
|
|
7218
|
+
this.statusTimer = null;
|
|
7219
|
+
}
|
|
7220
|
+
this.statusRegion?.remove();
|
|
7221
|
+
this.statusRegion = null;
|
|
6734
7222
|
this.cleanupSparkLink();
|
|
6735
7223
|
this.destroyCurrentView();
|
|
6736
7224
|
this.container.destroy();
|
|
@@ -6747,6 +7235,159 @@ class IdentityRenderer {
|
|
|
6747
7235
|
this.render();
|
|
6748
7236
|
}
|
|
6749
7237
|
async showInitialAuthStep() {
|
|
7238
|
+
const heldAtStart = this.verificationState.signinRef;
|
|
7239
|
+
if (this.startWithFederation())
|
|
7240
|
+
return;
|
|
7241
|
+
await this.showSignInStep();
|
|
7242
|
+
this.untouchedStep = this.currentView;
|
|
7243
|
+
// A reference that arrived while the step was being prepared joins it now.
|
|
7244
|
+
if (this.verificationState.signinRef !== heldAtStart)
|
|
7245
|
+
this.offerArrivedReference();
|
|
7246
|
+
}
|
|
7247
|
+
/**
|
|
7248
|
+
* The account's own identity provider as the flow's first step. A failed
|
|
7249
|
+
* round trip is said first. Otherwise the provider may start on its own
|
|
7250
|
+
* (startFederationAutomatically). Returns true when it took the step.
|
|
7251
|
+
*/
|
|
7252
|
+
startWithFederation() {
|
|
7253
|
+
if (this.federationReturn === 'failed') {
|
|
7254
|
+
this.federationReturn = null;
|
|
7255
|
+
this.setState(this.federationFailedState());
|
|
7256
|
+
return true;
|
|
7257
|
+
}
|
|
7258
|
+
return this.startFederationAutomatically();
|
|
7259
|
+
}
|
|
7260
|
+
/**
|
|
7261
|
+
* Leave for the account's own identity provider without the person's
|
|
7262
|
+
* click, while this page offers it and it starts on its own
|
|
7263
|
+
* (federationStartsOnItsOwn). Returns true when it left.
|
|
7264
|
+
*/
|
|
7265
|
+
startFederationAutomatically() {
|
|
7266
|
+
const federation = this.federation;
|
|
7267
|
+
if (!this.federationStartsOnItsOwn(federation))
|
|
7268
|
+
return false;
|
|
7269
|
+
this.leaveForFederation({ silent: federation.silent, automatic: true })
|
|
7270
|
+
.catch((error) => this.handleErrorWithRecovery(error, 'unknown'));
|
|
7271
|
+
return true;
|
|
7272
|
+
}
|
|
7273
|
+
/**
|
|
7274
|
+
* Whether the given account's own identity provider starts without the
|
|
7275
|
+
* person's click while this page may still leave on its own: when the
|
|
7276
|
+
* account asks for a silent attempt (`federation.silent`: the provider
|
|
7277
|
+
* answers without showing anything, and a refusal comes back as
|
|
7278
|
+
* `interaction_required`) or the caller asked for it (`method:
|
|
7279
|
+
* 'federation'`, interactive unless the account asks for the silent
|
|
7280
|
+
* attempt).
|
|
7281
|
+
*/
|
|
7282
|
+
federationStartsOnItsOwn(federation) {
|
|
7283
|
+
return federation !== null
|
|
7284
|
+
&& this.federationMayAutoStart
|
|
7285
|
+
&& (federation.silent || this.options.method === 'federation');
|
|
7286
|
+
}
|
|
7287
|
+
/**
|
|
7288
|
+
* The account's own identity provider while a step for this identifier
|
|
7289
|
+
* lacks it only because the page's ask for the sign-in's reference is still
|
|
7290
|
+
* out: with the reference held, the provider would be on that step, so the
|
|
7291
|
+
* step holds every automatic advance a held reference would not have made.
|
|
7292
|
+
* Once the reference lands the provider joins the step, or starts on its
|
|
7293
|
+
* own from the untouched first step (offerArrivedReference); an ask that
|
|
7294
|
+
* finds none leaves the held step up for the person's tap.
|
|
7295
|
+
*/
|
|
7296
|
+
federationAwaitingReference(recipient) {
|
|
7297
|
+
if (this.referenceAsk !== 'pending' || !this.offersFederationBeside(recipient))
|
|
7298
|
+
return null;
|
|
7299
|
+
return this.accountFederation;
|
|
7300
|
+
}
|
|
7301
|
+
/**
|
|
7302
|
+
* Ask the page for the sign-in's reference (VerifyOptions.signinRef as a
|
|
7303
|
+
* function) without waiting on the answer: the flow goes on, and the
|
|
7304
|
+
* answer joins it when it lands. A call that throws or rejects, and an
|
|
7305
|
+
* answer that is no reference, found none.
|
|
7306
|
+
*/
|
|
7307
|
+
requestReference() {
|
|
7308
|
+
const ask = this.askReference;
|
|
7309
|
+
if (!ask)
|
|
7310
|
+
return;
|
|
7311
|
+
const asked = ++this.referenceAsks;
|
|
7312
|
+
this.referenceAsk = 'pending';
|
|
7313
|
+
void new Promise((resolve) => { resolve(ask()); })
|
|
7314
|
+
.catch(() => null)
|
|
7315
|
+
.then((reference) => {
|
|
7316
|
+
if (asked !== this.referenceAsks)
|
|
7317
|
+
return;
|
|
7318
|
+
if (isSigninReference(reference)) {
|
|
7319
|
+
this.referenceArrived(reference);
|
|
7320
|
+
}
|
|
7321
|
+
else {
|
|
7322
|
+
this.referenceUnavailable();
|
|
7323
|
+
}
|
|
7324
|
+
});
|
|
7325
|
+
}
|
|
7326
|
+
/** The reference arrived: every completing call from now on carries it, and the step offers the provider. */
|
|
7327
|
+
referenceArrived(reference) {
|
|
7328
|
+
this.referenceAsk = null;
|
|
7329
|
+
this.verificationState.setSigninRef(reference);
|
|
7330
|
+
this.offerArrivedReference();
|
|
7331
|
+
}
|
|
7332
|
+
/**
|
|
7333
|
+
* The ask found no reference for now. An account with other ways in
|
|
7334
|
+
* simply keeps them; a person waiting on the provider as the only way in
|
|
7335
|
+
* is told to try again.
|
|
7336
|
+
*/
|
|
7337
|
+
referenceUnavailable() {
|
|
7338
|
+
this.referenceAsk = 'unavailable';
|
|
7339
|
+
if (this.viewState.view === 'awaiting-reference')
|
|
7340
|
+
void this.showMethodSelect();
|
|
7341
|
+
}
|
|
7342
|
+
/** The person's Try Again: ask again, and show the sign-in step meanwhile. */
|
|
7343
|
+
retryReference() {
|
|
7344
|
+
this.requestReference();
|
|
7345
|
+
void this.showSignInStep();
|
|
7346
|
+
}
|
|
7347
|
+
/**
|
|
7348
|
+
* Offer the account's own identity provider on the step that offers it,
|
|
7349
|
+
* now that the page holds its reference. On the sign-in step as it first
|
|
7350
|
+
* showed, still untouched, the provider starts on its own as it would have
|
|
7351
|
+
* with the reference held from the start; otherwise its button joins the
|
|
7352
|
+
* step in place, keeping what the person typed and their focus. A person
|
|
7353
|
+
* who has moved past that step sees nothing change, and the step offers
|
|
7354
|
+
* the provider whenever it shows again.
|
|
7355
|
+
*/
|
|
7356
|
+
offerArrivedReference() {
|
|
7357
|
+
const state = this.viewState;
|
|
7358
|
+
const onOfferingStep = state.view === 'awaiting-reference'
|
|
7359
|
+
|| state.view === 'identity-input'
|
|
7360
|
+
|| (state.view === 'method-select' && this.offersFederationBeside(state.email));
|
|
7361
|
+
if (!onOfferingStep)
|
|
7362
|
+
return;
|
|
7363
|
+
const untouched = this.untouchedStep !== null && this.currentView === this.untouchedStep;
|
|
7364
|
+
if (untouched && this.startFederationAutomatically())
|
|
7365
|
+
return;
|
|
7366
|
+
if (state.view === 'awaiting-reference') {
|
|
7367
|
+
void this.showMethodSelect();
|
|
7368
|
+
return;
|
|
7369
|
+
}
|
|
7370
|
+
const leading = this.leadingFederationMethod();
|
|
7371
|
+
if (!leading)
|
|
7372
|
+
return;
|
|
7373
|
+
const view = this.currentView;
|
|
7374
|
+
if (view instanceof IdentityInputView) {
|
|
7375
|
+
view.offerLeadingMethod(leading);
|
|
7376
|
+
}
|
|
7377
|
+
else if (view instanceof MethodSelectView
|
|
7378
|
+
&& state.view === 'method-select'
|
|
7379
|
+
&& !state.methods.some((method) => method.type === 'federation')) {
|
|
7380
|
+
view.offerLeadingMethod(leading.method);
|
|
7381
|
+
this.verificationState.setViewState({ ...state, methods: [leading.method, ...state.methods] });
|
|
7382
|
+
}
|
|
7383
|
+
}
|
|
7384
|
+
/**
|
|
7385
|
+
* The sign-in's own first step: the method list when no identifier is
|
|
7386
|
+
* asked for (or one is already known), the discoverable passkey ceremony for
|
|
7387
|
+
* a returning browser, else the identifier field (which leads with the
|
|
7388
|
+
* account's own identity provider when it offers one).
|
|
7389
|
+
*/
|
|
7390
|
+
async showSignInStep() {
|
|
6750
7391
|
if (this.recipient || this.getAllowedIdentityTypes().length === 0) {
|
|
6751
7392
|
await this.showMethodSelect();
|
|
6752
7393
|
return;
|
|
@@ -6754,8 +7395,12 @@ class IdentityRenderer {
|
|
|
6754
7395
|
// Returning browser on the Identity origin (passkey-hint cookie present):
|
|
6755
7396
|
// auto-start the discoverable ceremony instead of asking for an identifier
|
|
6756
7397
|
// — the Google-style one-touch return. A cancel lands on the identifier
|
|
6757
|
-
// form, which keeps a "Sign in with a passkey" way back in.
|
|
6758
|
-
|
|
7398
|
+
// form, which keeps a "Sign in with a passkey" way back in. A provider
|
|
7399
|
+
// that starts on its own once the pending reference lands goes first, as
|
|
7400
|
+
// with the reference held (startWithFederation), so the identifier form
|
|
7401
|
+
// waits for it instead.
|
|
7402
|
+
if (this.canDiscoverableVerify()
|
|
7403
|
+
&& !this.federationStartsOnItsOwn(this.federationAwaitingReference(this.recipient))) {
|
|
6759
7404
|
void this.launchDiscoverableVerify();
|
|
6760
7405
|
return;
|
|
6761
7406
|
}
|
|
@@ -6817,6 +7462,7 @@ class IdentityRenderer {
|
|
|
6817
7462
|
this.container.setMinimalChrome(minimalChromeViews.includes(this.viewState.view));
|
|
6818
7463
|
const view = this.createViewForState(this.viewState);
|
|
6819
7464
|
this.currentView = view;
|
|
7465
|
+
this.announce(view.announcement ?? '');
|
|
6820
7466
|
const rendered = view.render();
|
|
6821
7467
|
// Each step enters with a calm fade + rise (see .sv-step-enter). The brand
|
|
6822
7468
|
// lockup and footer live outside `body`, so only the flow content moves.
|
|
@@ -6825,11 +7471,12 @@ class IdentityRenderer {
|
|
|
6825
7471
|
// reshaping between steps (falls back to an instant swap in jsdom).
|
|
6826
7472
|
this.morphSwap(body, rendered);
|
|
6827
7473
|
// Drive the top progress bar (owned by login-popup.js as
|
|
6828
|
-
// `window.__sparkvaultProgress`) off the view: a transient `loading` view
|
|
6829
|
-
//
|
|
7474
|
+
// `window.__sparkvaultProgress`) off the view: a transient `loading` view,
|
|
7475
|
+
// or one awaiting the sign-in's reference, means a network step is in
|
|
7476
|
+
// flight, so keep the bar trickling; any real
|
|
6830
7477
|
// view completes it. The controller is idempotent, so overlapping calls are
|
|
6831
7478
|
// safe, and it is a no-op when the hook is absent (any non-popup host).
|
|
6832
|
-
if (this.viewState.view === 'loading') {
|
|
7479
|
+
if (this.viewState.view === 'loading' || this.viewState.view === 'awaiting-reference') {
|
|
6833
7480
|
progressStart();
|
|
6834
7481
|
}
|
|
6835
7482
|
else {
|
|
@@ -6848,6 +7495,41 @@ class IdentityRenderer {
|
|
|
6848
7495
|
this.focusTimeoutId = setTimeout(() => focusable.focus(), 50);
|
|
6849
7496
|
}
|
|
6850
7497
|
}
|
|
7498
|
+
/** Place the empty live region beside the flow content, once per container. */
|
|
7499
|
+
placeStatusRegion() {
|
|
7500
|
+
const body = this.container.getBody();
|
|
7501
|
+
if (!body || this.statusRegion?.isConnected)
|
|
7502
|
+
return;
|
|
7503
|
+
const region = document.createElement('div');
|
|
7504
|
+
region.className = 'sv-sr-only';
|
|
7505
|
+
region.setAttribute('role', 'status');
|
|
7506
|
+
region.setAttribute('aria-live', 'polite');
|
|
7507
|
+
region.setAttribute('aria-atomic', 'true');
|
|
7508
|
+
body.insertAdjacentElement('beforebegin', region);
|
|
7509
|
+
this.statusRegion = region;
|
|
7510
|
+
}
|
|
7511
|
+
/**
|
|
7512
|
+
* Put `words` in the live region, a moment after the view that says them
|
|
7513
|
+
* is in place, so they never land in the same change as the region or the
|
|
7514
|
+
* view that holds them; empty words clear it at once.
|
|
7515
|
+
*/
|
|
7516
|
+
announce(words) {
|
|
7517
|
+
if (this.statusTimer !== null) {
|
|
7518
|
+
clearTimeout(this.statusTimer);
|
|
7519
|
+
this.statusTimer = null;
|
|
7520
|
+
}
|
|
7521
|
+
const region = this.statusRegion;
|
|
7522
|
+
if (!region)
|
|
7523
|
+
return;
|
|
7524
|
+
if (!words) {
|
|
7525
|
+
region.textContent = '';
|
|
7526
|
+
return;
|
|
7527
|
+
}
|
|
7528
|
+
this.statusTimer = setTimeout(() => {
|
|
7529
|
+
this.statusTimer = null;
|
|
7530
|
+
region.textContent = words;
|
|
7531
|
+
}, STATUS_ANNOUNCE_DELAY_MS);
|
|
7532
|
+
}
|
|
6851
7533
|
destroyCurrentView() {
|
|
6852
7534
|
if (this.currentView?.destroy) {
|
|
6853
7535
|
this.currentView.destroy();
|
|
@@ -6906,6 +7588,7 @@ class IdentityRenderer {
|
|
|
6906
7588
|
createViewForState(state) {
|
|
6907
7589
|
switch (state.view) {
|
|
6908
7590
|
case 'loading':
|
|
7591
|
+
case 'awaiting-reference':
|
|
6909
7592
|
return new LoadingView({ message: 'Loading...' });
|
|
6910
7593
|
case 'identity-input':
|
|
6911
7594
|
return new IdentityInputView({
|
|
@@ -6918,6 +7601,10 @@ class IdentityRenderer {
|
|
|
6918
7601
|
onPasskey: this.canDiscoverableVerify()
|
|
6919
7602
|
? () => { void this.launchDiscoverableVerify(); }
|
|
6920
7603
|
: undefined,
|
|
7604
|
+
leadingMethod: this.leadingFederationMethod(),
|
|
7605
|
+
// A person who started typing keeps the step: a reference that
|
|
7606
|
+
// arrives later adds the provider's button, never leaves for it.
|
|
7607
|
+
onType: () => { this.untouchedStep = null; },
|
|
6921
7608
|
});
|
|
6922
7609
|
case 'method-select':
|
|
6923
7610
|
return new MethodSelectView({
|
|
@@ -7020,11 +7707,20 @@ class IdentityRenderer {
|
|
|
7020
7707
|
});
|
|
7021
7708
|
case 'oauth-pending':
|
|
7022
7709
|
return new LoadingView({ message: `Connecting to ${state.provider}...` });
|
|
7710
|
+
case 'federation-checking':
|
|
7711
|
+
return new LoadingView({ message: `Checking your ${state.displayName} sign-in…`, announce: true });
|
|
7023
7712
|
case 'error':
|
|
7024
7713
|
return new ErrorView({
|
|
7025
7714
|
message: state.message,
|
|
7026
7715
|
code: state.code,
|
|
7027
|
-
|
|
7716
|
+
// A failed provider sign-in tries again from the sign-in's first
|
|
7717
|
+
// step, where the provider leads; nothing leaves on its own again.
|
|
7718
|
+
// A reference the page could not get is asked for again.
|
|
7719
|
+
onRetry: state.code === FEDERATION_FAILED
|
|
7720
|
+
? () => { void this.showSignInStep(); }
|
|
7721
|
+
: state.code === SIGNIN_REFERENCE_UNAVAILABLE_CODE
|
|
7722
|
+
? () => this.retryReference()
|
|
7723
|
+
: () => this.showIdentityInput(),
|
|
7028
7724
|
onClose: () => this.handleClose(),
|
|
7029
7725
|
});
|
|
7030
7726
|
case 'service-unavailable':
|
|
@@ -7073,7 +7769,15 @@ class IdentityRenderer {
|
|
|
7073
7769
|
});
|
|
7074
7770
|
return;
|
|
7075
7771
|
}
|
|
7076
|
-
//
|
|
7772
|
+
// Read before the passkey check below, so a reference that lands while
|
|
7773
|
+
// the check runs finds this list held, as one landing just after it
|
|
7774
|
+
// would: the provider, read after the check, then leads the list, and
|
|
7775
|
+
// starts on its own from the untouched first step (showInitialAuthStep).
|
|
7776
|
+
const federationAwaited = this.federationAwaitingReference(this.recipient);
|
|
7777
|
+
// Enrich method IDs with metadata from static registry. The account's own
|
|
7778
|
+
// identity provider is set apart: it needs no identifier, and leads every
|
|
7779
|
+
// list that offers it (below), read once the rest of the list is known so
|
|
7780
|
+
// a reference that arrived meanwhile counts.
|
|
7077
7781
|
let methods = enrichMethods(methodIds);
|
|
7078
7782
|
if (this.recipient) {
|
|
7079
7783
|
// Filter by identifier type. Passkeys are SVID-scoped, so they remain
|
|
@@ -7104,6 +7808,9 @@ class IdentityRenderer {
|
|
|
7104
7808
|
if (this.verificationState.passkey.isFallbackMode) {
|
|
7105
7809
|
methods = methods.filter((m) => m.type !== 'passkey');
|
|
7106
7810
|
}
|
|
7811
|
+
if (this.offersFederationBeside(this.recipient)) {
|
|
7812
|
+
methods = [...enrichMethods(['federation'], this.federation), ...methods];
|
|
7813
|
+
}
|
|
7107
7814
|
if (methods.length === 0) {
|
|
7108
7815
|
this.setState(this.noMethodState());
|
|
7109
7816
|
return;
|
|
@@ -7113,8 +7820,11 @@ class IdentityRenderer {
|
|
|
7113
7820
|
// pick a method — it is the safest, fastest option. The back arrow on
|
|
7114
7821
|
// the passkey view re-enters this method with autoRoute=false so the
|
|
7115
7822
|
// user lands on the full picker (passkey still listed) and can pick
|
|
7116
|
-
// a code or SparkLink instead.
|
|
7823
|
+
// a code or SparkLink instead. A provider that starts on its own once the
|
|
7824
|
+
// pending reference lands goes first, as with the reference held
|
|
7825
|
+
// (startWithFederation), so the list waits for it instead.
|
|
7117
7826
|
if (autoRoute
|
|
7827
|
+
&& !this.federationStartsOnItsOwn(federationAwaited)
|
|
7118
7828
|
&& this.verificationState.passkey.hasPasskey === true
|
|
7119
7829
|
&& !this.verificationState.passkey.isFallbackMode
|
|
7120
7830
|
&& methods.some((m) => m.type === 'passkey')) {
|
|
@@ -7134,11 +7844,22 @@ class IdentityRenderer {
|
|
|
7134
7844
|
// link, with no consent, and again on every reload;
|
|
7135
7845
|
// - a text or call to a phone number the flow supplied: the person never
|
|
7136
7846
|
// typed it under the SMS and voice consent the identifier field carries,
|
|
7137
|
-
// so the picker carries that consent and the tap gives it
|
|
7847
|
+
// so the picker carries that consent and the tap gives it;
|
|
7848
|
+
// - the account's own identity provider, once the page may no longer leave
|
|
7849
|
+
// for it on its own (it already did, or a round trip came back): Back
|
|
7850
|
+
// from the provider must never be forwarded to it again;
|
|
7851
|
+
// - a list the provider is missing from only while the page's ask for the
|
|
7852
|
+
// sign-in's reference is out (federationAwaitingReference): with the
|
|
7853
|
+
// reference held the provider leads it, so it is never one method.
|
|
7138
7854
|
// (Passkey auto-route above still applies — a biometric prompt costs
|
|
7139
7855
|
// nothing and can be dismissed.)
|
|
7140
7856
|
const sendsToSuppliedPhone = this.identityPrefilled && methods[0].identityType === 'phone';
|
|
7141
|
-
|
|
7857
|
+
const heldFederation = methods[0].type === 'federation' && !this.federationMayAutoStart;
|
|
7858
|
+
if (methods.length === 1
|
|
7859
|
+
&& !this.isIdentityFixed()
|
|
7860
|
+
&& !sendsToSuppliedPhone
|
|
7861
|
+
&& !heldFederation
|
|
7862
|
+
&& federationAwaited === null) {
|
|
7142
7863
|
this.handleMethodSelect(methods[0]);
|
|
7143
7864
|
return;
|
|
7144
7865
|
}
|
|
@@ -7153,8 +7874,17 @@ class IdentityRenderer {
|
|
|
7153
7874
|
* its sender held to a passkey admits the passkey alone, so a person the
|
|
7154
7875
|
* check found holding none is told the request needs a passkey already
|
|
7155
7876
|
* registered with SparkVault and that only the sender can resend it at a
|
|
7156
|
-
* level they can clear: no retry here changes that.
|
|
7157
|
-
*
|
|
7877
|
+
* level they can clear: no retry here changes that. An account whose
|
|
7878
|
+
* remaining way in is its own identity provider, which this page does not
|
|
7879
|
+
* offer now (see `federationOffered`), depends on why:
|
|
7880
|
+
* - the page can never hold a reference (an SDK that predates it opened
|
|
7881
|
+
* the page): the site must update its sign-in, and no retry here changes
|
|
7882
|
+
* that;
|
|
7883
|
+
* - the page's ask for its reference is still out: the step waits for it;
|
|
7884
|
+
* - the ask found none for now: the person is told to try again, which
|
|
7885
|
+
* asks again.
|
|
7886
|
+
* Any other verification with nothing to offer is a configuration fault,
|
|
7887
|
+
* shown as one.
|
|
7158
7888
|
*/
|
|
7159
7889
|
noMethodState() {
|
|
7160
7890
|
if (this.verificationState.passkeyRequired && this.verificationState.passkey.hasPasskey === false) {
|
|
@@ -7164,6 +7894,20 @@ class IdentityRenderer {
|
|
|
7164
7894
|
message: strongerVerificationMessage('request', this.sdkConfig?.branding?.companyName),
|
|
7165
7895
|
};
|
|
7166
7896
|
}
|
|
7897
|
+
if (this.accountFederation && !this.federationOffered) {
|
|
7898
|
+
if (!this.askReference) {
|
|
7899
|
+
const name = this.sdkConfig?.federation?.display_name?.trim();
|
|
7900
|
+
return {
|
|
7901
|
+
view: 'error',
|
|
7902
|
+
code: FEDERATION_UNAVAILABLE_CODE,
|
|
7903
|
+
message: `This site needs to update its sign-in to use ${name || 'your organization\'s sign-in'}.`,
|
|
7904
|
+
};
|
|
7905
|
+
}
|
|
7906
|
+
if (this.referenceAsk === 'unavailable') {
|
|
7907
|
+
return { view: 'error', code: SIGNIN_REFERENCE_UNAVAILABLE_CODE, message: 'We couldn\'t start sign-in. Try again.' };
|
|
7908
|
+
}
|
|
7909
|
+
return { view: 'awaiting-reference' };
|
|
7910
|
+
}
|
|
7167
7911
|
return { view: 'error', message: 'No authentication methods available', code: 'no_methods' };
|
|
7168
7912
|
}
|
|
7169
7913
|
handleIdentitySubmit(result) {
|
|
@@ -7285,6 +8029,12 @@ class IdentityRenderer {
|
|
|
7285
8029
|
}
|
|
7286
8030
|
break;
|
|
7287
8031
|
}
|
|
8032
|
+
case 'federation': {
|
|
8033
|
+
// A click is always interactive; a start with no click (the only
|
|
8034
|
+
// method, auto-selected) is the page leaving on its own.
|
|
8035
|
+
await this.leaveForFederation({ silent: false, automatic: !userInitiated });
|
|
8036
|
+
break;
|
|
8037
|
+
}
|
|
7288
8038
|
default:
|
|
7289
8039
|
this.setState({
|
|
7290
8040
|
view: 'error',
|
|
@@ -7516,13 +8266,15 @@ class IdentityRenderer {
|
|
|
7516
8266
|
passkeyFallbackMethodsAvailable() {
|
|
7517
8267
|
if (!this.sdkConfig)
|
|
7518
8268
|
return false;
|
|
7519
|
-
const methods = enrichMethods(this.verificationState.methodIds);
|
|
8269
|
+
const methods = enrichMethods(this.verificationState.methodIds, this.federation);
|
|
7520
8270
|
if (!this.recipient) {
|
|
7521
|
-
return methods.some((m) => m.type === 'social');
|
|
8271
|
+
return methods.some((m) => m.type === 'social' || m.type === 'federation');
|
|
7522
8272
|
}
|
|
7523
8273
|
return methods.some((m) => {
|
|
7524
8274
|
if (m.type === 'passkey')
|
|
7525
8275
|
return false;
|
|
8276
|
+
if (m.type === 'federation')
|
|
8277
|
+
return this.offersFederationBeside(this.recipient);
|
|
7526
8278
|
if (this.identityType === 'phone')
|
|
7527
8279
|
return m.identityType === 'phone';
|
|
7528
8280
|
return m.identityType === 'email';
|
|
@@ -7551,9 +8303,104 @@ class IdentityRenderer {
|
|
|
7551
8303
|
this.setState({ view: 'oauth-pending', provider });
|
|
7552
8304
|
const { state } = await this.api.drawAuthorizationValues();
|
|
7553
8305
|
sessionStorage.setItem('sv_oauth_state', state);
|
|
7554
|
-
const authUrl = this.api.getSocialAuthUrl(provider, currentPageReturnUrl(), state, this.verificationState.authContext);
|
|
8306
|
+
const authUrl = this.api.getSocialAuthUrl(provider, currentPageReturnUrl(), state, this.verificationState.authContext, this.verificationState.signinRef);
|
|
7555
8307
|
window.location.href = authUrl;
|
|
7556
8308
|
}
|
|
8309
|
+
/**
|
|
8310
|
+
* The account's own identity provider, while this verification offers it:
|
|
8311
|
+
* this page offers it now (federationOffered), `/config` describes it, and
|
|
8312
|
+
* the verification's methods list it. A verify session's methods never do,
|
|
8313
|
+
* for such a sign-in cannot complete one.
|
|
8314
|
+
*/
|
|
8315
|
+
get federation() {
|
|
8316
|
+
return this.federationOffered ? this.accountFederation : null;
|
|
8317
|
+
}
|
|
8318
|
+
/**
|
|
8319
|
+
* Whether this page offers the account's own identity provider now (see
|
|
8320
|
+
* VerifyOptions.signinRef): while it holds its sign-in's reference, or
|
|
8321
|
+
* when it completes in its own window.
|
|
8322
|
+
*/
|
|
8323
|
+
get federationOffered() {
|
|
8324
|
+
return this.offeredWithoutReference || this.verificationState.signinRef !== null;
|
|
8325
|
+
}
|
|
8326
|
+
/** The account's own identity provider while `/config` describes it and the verification's methods list it. */
|
|
8327
|
+
get accountFederation() {
|
|
8328
|
+
const federation = this.sdkConfig?.federation;
|
|
8329
|
+
const methodIds = this.verificationState.methodIds;
|
|
8330
|
+
return federation && Array.isArray(methodIds) && methodIds.includes('federation') ? federation : null;
|
|
8331
|
+
}
|
|
8332
|
+
/**
|
|
8333
|
+
* Whether a list of methods offers the account's own identity provider
|
|
8334
|
+
* beside the identifier it is for. It needs no identifier, so the first
|
|
8335
|
+
* step offers it (above the identifier field, or in a list with none), and
|
|
8336
|
+
* so does a list for an identifier the flow supplied, whose person never saw
|
|
8337
|
+
* that step. An identifier the person typed came from the identifier
|
|
8338
|
+
* field, which already offered it.
|
|
8339
|
+
*/
|
|
8340
|
+
offersFederationBeside(recipient) {
|
|
8341
|
+
return !recipient || this.identityPrefilled;
|
|
8342
|
+
}
|
|
8343
|
+
/** The identifier field's leading method: the account's own identity provider, when offered. */
|
|
8344
|
+
leadingFederationMethod() {
|
|
8345
|
+
const [method] = enrichMethods(['federation'], this.federation);
|
|
8346
|
+
if (!method)
|
|
8347
|
+
return undefined;
|
|
8348
|
+
return { method, onSelect: () => { void this.handleMethodSelect(method, true); } };
|
|
8349
|
+
}
|
|
8350
|
+
/**
|
|
8351
|
+
* Leave for the account's own identity provider, the way a social sign-in
|
|
8352
|
+
* leaves (handleSocialLogin): the round trip returns to this page, query
|
|
8353
|
+
* intact, the state stored here is what its `#token` (or its refusal's
|
|
8354
|
+
* fragment) must answer, and the start carries the sign-in's reference
|
|
8355
|
+
* when the page holds one. A silent attempt shows a status the whole time
|
|
8356
|
+
* it runs. A start without the person's click (`automatic`) is recorded, so
|
|
8357
|
+
* a person who comes Back from the provider's page is not sent on again.
|
|
8358
|
+
*/
|
|
8359
|
+
async leaveForFederation({ silent, automatic }) {
|
|
8360
|
+
const federation = this.federation;
|
|
8361
|
+
if (!federation)
|
|
8362
|
+
return;
|
|
8363
|
+
if (automatic)
|
|
8364
|
+
this.federationMayAutoStart = false;
|
|
8365
|
+
this.setState(silent
|
|
8366
|
+
? { view: 'federation-checking', displayName: federation.display_name }
|
|
8367
|
+
: { view: 'oauth-pending', provider: federation.display_name });
|
|
8368
|
+
const { state } = await this.api.drawAuthorizationValues();
|
|
8369
|
+
sessionStorage.setItem('sv_oauth_state', state);
|
|
8370
|
+
if (automatic)
|
|
8371
|
+
markFederationAutoStart(this.api.accountId);
|
|
8372
|
+
this.watchForPageRestore();
|
|
8373
|
+
window.location.href = this.api.getFederationAuthUrl(currentPageReturnUrl(), state, this.verificationState.authContext, { silent, signinRef: this.verificationState.signinRef });
|
|
8374
|
+
}
|
|
8375
|
+
/**
|
|
8376
|
+
* A browser that restores this page from its back/forward cache, as the
|
|
8377
|
+
* person comes Back from the provider, runs nothing again, so the page would
|
|
8378
|
+
* keep the wait it left on. Show the sign-in's first step instead, with the
|
|
8379
|
+
* automatic start spent.
|
|
8380
|
+
*/
|
|
8381
|
+
watchForPageRestore() {
|
|
8382
|
+
if (this.pageRestoreHandler)
|
|
8383
|
+
return;
|
|
8384
|
+
this.pageRestoreHandler = (event) => {
|
|
8385
|
+
if (!event.persisted)
|
|
8386
|
+
return;
|
|
8387
|
+
takeFederationAutoStart(this.api.accountId);
|
|
8388
|
+
this.federationMayAutoStart = false;
|
|
8389
|
+
void this.showSignInStep();
|
|
8390
|
+
};
|
|
8391
|
+
window.addEventListener('pageshow', this.pageRestoreHandler);
|
|
8392
|
+
}
|
|
8393
|
+
/** The failure of a sign-in through the account's own identity provider, in fixed words, never the provider's. */
|
|
8394
|
+
federationFailedState() {
|
|
8395
|
+
const name = this.sdkConfig?.federation?.display_name;
|
|
8396
|
+
return {
|
|
8397
|
+
view: 'error',
|
|
8398
|
+
code: FEDERATION_FAILED,
|
|
8399
|
+
message: name
|
|
8400
|
+
? `We couldn't sign you in with ${name}. Please try again.`
|
|
8401
|
+
: 'We couldn\'t sign you in through your organization. Please try again.',
|
|
8402
|
+
};
|
|
8403
|
+
}
|
|
7557
8404
|
normalizeError(error) {
|
|
7558
8405
|
if (error instanceof IdentityApiError) {
|
|
7559
8406
|
return new SparkVaultError(error.message, error.code);
|
|
@@ -10106,7 +10953,13 @@ function createCloseButton(className, onClick) {
|
|
|
10106
10953
|
* The popup must open synchronously in the gesture or the browser blocks it as
|
|
10107
10954
|
* programmatic. `verify()` reaches `start()` through microtask-only awaits (the
|
|
10108
10955
|
* redirect-result check does no I/O; the preloaded config resolves from cache),
|
|
10109
|
-
* so transient activation survives.
|
|
10956
|
+
* so transient activation survives. Each popup's reference (app-sdk
|
|
10957
|
+
* SIGNIN_REFERENCE) is therefore drawn only after that popup opens, by the
|
|
10958
|
+
* owner (`drawSigninReference`). Once the owner has decided it (its pending
|
|
10959
|
+
* marker holds the drawn reference, or the popup has none), the launcher
|
|
10960
|
+
* posts it to the popup in answer to each "ready" ping: the reference, or
|
|
10961
|
+
* null. A popup told null may ask again (`SIGNIN_REFERENCE.retryMessage`),
|
|
10962
|
+
* and the owner then draws afresh for it.
|
|
10110
10963
|
*
|
|
10111
10964
|
* It is one dialog. The happy path is clean: logo, a subtle animation, and
|
|
10112
10965
|
* "continue in the secure window". A single warning appears under the logo only
|
|
@@ -10176,6 +11029,8 @@ class DialogLauncher {
|
|
|
10176
11029
|
this.modal = null;
|
|
10177
11030
|
this.alertEl = null;
|
|
10178
11031
|
this.popupWindow = null;
|
|
11032
|
+
// The current popup has pinged that its page loaded.
|
|
11033
|
+
this.popupReady = false;
|
|
10179
11034
|
this.openTimer = null;
|
|
10180
11035
|
this.settled = false;
|
|
10181
11036
|
// Bumped on every open so a superseded popup's late result or ready ping
|
|
@@ -10197,11 +11052,22 @@ class DialogLauncher {
|
|
|
10197
11052
|
this.modal = null;
|
|
10198
11053
|
this.alertEl = null;
|
|
10199
11054
|
}
|
|
11055
|
+
/**
|
|
11056
|
+
* The owner decided the current popup's reference: tell the popup if it
|
|
11057
|
+
* already pinged. A popup that loads later is told in answer to its ping.
|
|
11058
|
+
*/
|
|
11059
|
+
signinReferenceDecided() {
|
|
11060
|
+
if (this.popupReady)
|
|
11061
|
+
this.postSigninReference();
|
|
11062
|
+
}
|
|
10200
11063
|
openPopup() {
|
|
10201
11064
|
const generation = ++this.generation;
|
|
11065
|
+
this.popupReady = false;
|
|
10202
11066
|
this.popupLauncher
|
|
10203
11067
|
.openPopup({
|
|
10204
|
-
|
|
11068
|
+
// The popup opens before its reference can be drawn, so its URL says
|
|
11069
|
+
// this opener posts it.
|
|
11070
|
+
url: buildSigninUrl(this.config, this.options, { kind: 'popup' }),
|
|
10205
11071
|
windowName: 'sparkvault-login',
|
|
10206
11072
|
resultType: LOGIN_RESULT_TYPE,
|
|
10207
11073
|
readyType: LOGIN_READY_TYPE,
|
|
@@ -10212,15 +11078,59 @@ class DialogLauncher {
|
|
|
10212
11078
|
this.popupWindow = popup;
|
|
10213
11079
|
this.scheduleOpenWarning();
|
|
10214
11080
|
},
|
|
10215
|
-
// The page loaded and pinged back
|
|
10216
|
-
// open-failure warning no matter how long the person now takes.
|
|
10217
|
-
|
|
10218
|
-
|
|
11081
|
+
// The page loaded and pinged back: the open succeeded, so cancel the
|
|
11082
|
+
// open-failure warning no matter how long the person now takes. The
|
|
11083
|
+
// page pings on every load, a provider's round trip included, and
|
|
11084
|
+
// each load is told the popup's reference afresh.
|
|
11085
|
+
onReady: () => {
|
|
11086
|
+
if (generation !== this.generation)
|
|
11087
|
+
return;
|
|
11088
|
+
this.clearOpenTimer();
|
|
11089
|
+
this.popupReady = true;
|
|
11090
|
+
this.postSigninReference();
|
|
11091
|
+
},
|
|
11092
|
+
requestType: SIGNIN_REFERENCE.retryMessage,
|
|
11093
|
+
onRequest: () => {
|
|
11094
|
+
if (generation === this.generation)
|
|
11095
|
+
this.answerSigninReferenceRetry();
|
|
11096
|
+
},
|
|
10219
11097
|
})
|
|
10220
11098
|
.then((message) => { if (generation === this.generation)
|
|
10221
11099
|
this.handleResult(message); })
|
|
10222
11100
|
.catch((error) => { if (generation === this.generation)
|
|
10223
11101
|
this.handleError(error); });
|
|
11102
|
+
// Drawn only now, for this popup alone: it opens inside the click, which
|
|
11103
|
+
// no draw can finish within, and no earlier popup's reference is reused.
|
|
11104
|
+
this.callbacks.drawSigninReference();
|
|
11105
|
+
}
|
|
11106
|
+
/**
|
|
11107
|
+
* The current popup asked again for its reference. A popup that has none
|
|
11108
|
+
* gets a fresh draw (the owner re-arms the marker, then decides), one that
|
|
11109
|
+
* holds a reference is told it again, and one whose draw is still out is
|
|
11110
|
+
* told once that draw is decided.
|
|
11111
|
+
*/
|
|
11112
|
+
answerSigninReferenceRetry() {
|
|
11113
|
+
const reference = this.callbacks.signinReference();
|
|
11114
|
+
if (reference === null) {
|
|
11115
|
+
this.callbacks.drawSigninReference();
|
|
11116
|
+
return;
|
|
11117
|
+
}
|
|
11118
|
+
if (reference !== undefined)
|
|
11119
|
+
this.postSigninReference();
|
|
11120
|
+
}
|
|
11121
|
+
/**
|
|
11122
|
+
* Post the current popup's reference, once the owner decided it, to this
|
|
11123
|
+
* launcher's own popup: the reference the marker holds, or null for a
|
|
11124
|
+
* popup with none, so the page knows at once that it has none for now
|
|
11125
|
+
* instead of waiting it out. Only a document there on the trusted Identity
|
|
11126
|
+
* origin receives it: the browser drops it while the popup shows any other
|
|
11127
|
+
* origin (a provider's page).
|
|
11128
|
+
*/
|
|
11129
|
+
postSigninReference() {
|
|
11130
|
+
const reference = this.callbacks.signinReference();
|
|
11131
|
+
if (reference === undefined || !this.popupWindow)
|
|
11132
|
+
return;
|
|
11133
|
+
this.popupWindow.postMessage({ type: SIGNIN_REFERENCE.message, [SIGNIN_REFERENCE.param]: reference }, this.trustedOrigin);
|
|
10224
11134
|
}
|
|
10225
11135
|
handleResult(message) {
|
|
10226
11136
|
if (this.settled)
|
|
@@ -10333,9 +11243,8 @@ class DialogLauncher {
|
|
|
10333
11243
|
this.openTimer = null;
|
|
10334
11244
|
}
|
|
10335
11245
|
}
|
|
10336
|
-
/** "Try again": close any current popup and
|
|
11246
|
+
/** "Try again": close any current popup and open a fresh one, as the first opened. */
|
|
10337
11247
|
retry() {
|
|
10338
|
-
this.callbacks.onPopupReopened?.();
|
|
10339
11248
|
this.hideAlert();
|
|
10340
11249
|
this.closePopup();
|
|
10341
11250
|
this.openPopup();
|
|
@@ -10598,35 +11507,28 @@ function attachClickHandler(selector, onClick) {
|
|
|
10598
11507
|
}
|
|
10599
11508
|
|
|
10600
11509
|
/**
|
|
10601
|
-
*
|
|
10602
|
-
*
|
|
10603
|
-
*
|
|
10604
|
-
*
|
|
11510
|
+
* The pending sign-in marker: what lets a site whose popup result was lost (a
|
|
11511
|
+
* mobile browser discards the backgrounded opener tab, which clears the
|
|
11512
|
+
* message listener but not sessionStorage) recover it on its next load, for
|
|
11513
|
+
* at most SIGNIN_RECOVERY.pendingTtlMs.
|
|
10605
11514
|
*
|
|
10606
|
-
*
|
|
10607
|
-
*
|
|
10608
|
-
*
|
|
10609
|
-
*
|
|
10610
|
-
*
|
|
11515
|
+
* `sv_signin_pending` holds JSON `{ at, hint, ref }`:
|
|
11516
|
+
* - `at`: when the current popup opened, on this browser's clock; the
|
|
11517
|
+
* marker's TTL.
|
|
11518
|
+
* - `hint`: the email or phone the sign-in started with, or null when the
|
|
11519
|
+
* flow collects the identifier itself; the recovery bounce's `login_hint`.
|
|
11520
|
+
* - `ref`: the current popup's reference (app-sdk SIGNIN_REFERENCE), present
|
|
11521
|
+
* once drawn and written; the recovery bounce names it, and `/sso` then
|
|
11522
|
+
* mints only when the hub session it would mint from carries it. A marker
|
|
11523
|
+
* without one bounces with no reference.
|
|
10611
11524
|
*/
|
|
10612
|
-
const PORTAL_SECTIONS = ['home', 'identity', 'security', 'sessions', 'sites'];
|
|
10613
|
-
// The exact algorithms the Identity server signs identity tokens with: EdDSA by
|
|
10614
|
-
// default, RS256 when a client opts in via `id_token_signed_response_alg`. The
|
|
10615
|
-
// unverified client-side decode gates on this set so an unsigned (`none`) or
|
|
10616
|
-
// algorithm-confused token cannot masquerade as valid.
|
|
10617
|
-
const ACCEPTED_TOKEN_ALGS = ['EdDSA', 'RS256'];
|
|
10618
|
-
// A sign-in is "pending" from popup open until its result arrives; a marker
|
|
10619
|
-
// that outlives a lost result (a mobile opener-tab discard clears the message
|
|
10620
|
-
// listener but not sessionStorage) is what lets the next load self-heal.
|
|
10621
11525
|
const PENDING_KEY = 'sv_signin_pending';
|
|
10622
|
-
const PENDING_TTL_MS = 10 * 60 * 1000;
|
|
10623
11526
|
/**
|
|
10624
|
-
* Read and parse the pending marker
|
|
10625
|
-
*
|
|
10626
|
-
*
|
|
10627
|
-
*
|
|
10628
|
-
*
|
|
10629
|
-
* is bounded and never grows. Anything unreadable yields null.
|
|
11527
|
+
* Read and parse the pending marker. Anything unreadable yields null: a value
|
|
11528
|
+
* that is not a JSON object, an `at` that is no finite number, or a `ref`
|
|
11529
|
+
* that is present but no sign-in reference. A recovery that cannot name the
|
|
11530
|
+
* reference its marker records could mint any hub session in this browser, so
|
|
11531
|
+
* such a marker recovers nothing.
|
|
10630
11532
|
*/
|
|
10631
11533
|
function readPendingMarker() {
|
|
10632
11534
|
let raw = null;
|
|
@@ -10639,37 +11541,177 @@ function readPendingMarker() {
|
|
|
10639
11541
|
if (!raw) {
|
|
10640
11542
|
return null;
|
|
10641
11543
|
}
|
|
10642
|
-
let
|
|
10643
|
-
let hint = null;
|
|
11544
|
+
let parsed;
|
|
10644
11545
|
try {
|
|
10645
|
-
|
|
10646
|
-
if (typeof parsed === 'object' && parsed !== null) {
|
|
10647
|
-
const marker = parsed;
|
|
10648
|
-
if (typeof marker.at === 'number') {
|
|
10649
|
-
at = marker.at;
|
|
10650
|
-
}
|
|
10651
|
-
if (typeof marker.hint === 'string' && marker.hint) {
|
|
10652
|
-
hint = marker.hint;
|
|
10653
|
-
}
|
|
10654
|
-
}
|
|
10655
|
-
else if (typeof parsed === 'number') {
|
|
10656
|
-
// A bare timestamp parses as a JSON number.
|
|
10657
|
-
at = parsed;
|
|
10658
|
-
}
|
|
11546
|
+
parsed = JSON.parse(raw);
|
|
10659
11547
|
}
|
|
10660
11548
|
catch {
|
|
10661
|
-
|
|
11549
|
+
return null;
|
|
11550
|
+
}
|
|
11551
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
11552
|
+
return null;
|
|
11553
|
+
}
|
|
11554
|
+
const marker = parsed;
|
|
11555
|
+
if (typeof marker.at !== 'number' || !Number.isFinite(marker.at)) {
|
|
11556
|
+
return null;
|
|
10662
11557
|
}
|
|
10663
|
-
|
|
11558
|
+
const { ref } = marker;
|
|
11559
|
+
if (ref !== undefined && !isSigninReference(ref)) {
|
|
11560
|
+
return null;
|
|
11561
|
+
}
|
|
11562
|
+
return {
|
|
11563
|
+
at: marker.at,
|
|
11564
|
+
hint: typeof marker.hint === 'string' && marker.hint ? marker.hint : null,
|
|
11565
|
+
ref: typeof ref === 'string' ? ref : null,
|
|
11566
|
+
};
|
|
10664
11567
|
}
|
|
10665
|
-
/** True while a marker is within the
|
|
11568
|
+
/** True while a marker is within the recovery TTL. */
|
|
10666
11569
|
function isFreshPendingMarker(marker) {
|
|
10667
|
-
return marker !== null && Date.now() - marker.at <
|
|
11570
|
+
return marker !== null && Date.now() - marker.at < SIGNIN_RECOVERY.pendingTtlMs;
|
|
10668
11571
|
}
|
|
10669
|
-
/**
|
|
10670
|
-
function
|
|
10671
|
-
|
|
11572
|
+
/** Remove the pending marker. */
|
|
11573
|
+
function removePendingMarker() {
|
|
11574
|
+
try {
|
|
11575
|
+
sessionStorage.removeItem(PENDING_KEY);
|
|
11576
|
+
}
|
|
11577
|
+
catch {
|
|
11578
|
+
// Nothing to clear.
|
|
11579
|
+
}
|
|
11580
|
+
}
|
|
11581
|
+
/**
|
|
11582
|
+
* The reference a draw yields within SIGNIN_REFERENCE.drawDeadlineMs, else
|
|
11583
|
+
* null: a draw that fails or misses the deadline leaves the sign-in page
|
|
11584
|
+
* without one, and a draw that lands later is discarded. Never rejects.
|
|
11585
|
+
*/
|
|
11586
|
+
function signinReferenceInTime(draw) {
|
|
11587
|
+
return new Promise((settle) => {
|
|
11588
|
+
const deadline = setTimeout(() => settle(null), SIGNIN_REFERENCE.drawDeadlineMs);
|
|
11589
|
+
draw.then((reference) => { clearTimeout(deadline); settle(reference); }, () => { clearTimeout(deadline); settle(null); });
|
|
11590
|
+
});
|
|
11591
|
+
}
|
|
11592
|
+
/**
|
|
11593
|
+
* One popup sign-in's marker, from its first popup's open until the sign-in
|
|
11594
|
+
* settles. Every popup it opens, the first and each "Try again", is an open
|
|
11595
|
+
* of its own: it re-arms the marker holding no reference and draws its own
|
|
11596
|
+
* reference (signinReferenceInTime), which joins the marker once drawn. A
|
|
11597
|
+
* popup that has none asks again, and the same popup is then opened afresh,
|
|
11598
|
+
* with a draw of its own. An earlier open's reference is never reused, and
|
|
11599
|
+
* its draw, should it land later, is discarded. `reference` is what the
|
|
11600
|
+
* current popup is told, and the marker always holds it: a popup can never
|
|
11601
|
+
* hold a reference the marker does not.
|
|
11602
|
+
*/
|
|
11603
|
+
class PendingSignIn {
|
|
11604
|
+
constructor(hint) {
|
|
11605
|
+
this.hint = hint;
|
|
11606
|
+
this.at = 0;
|
|
11607
|
+
this.live = true;
|
|
11608
|
+
// Counts the opens and the ends of their popups, so a draw that lands after
|
|
11609
|
+
// its popup ended or was replaced is recognised and dropped.
|
|
11610
|
+
this.opens = 0;
|
|
11611
|
+
this.current = undefined;
|
|
11612
|
+
this.decided = Promise.resolve();
|
|
11613
|
+
}
|
|
11614
|
+
/**
|
|
11615
|
+
* The current popup's reference: undefined while its draw is out, null
|
|
11616
|
+
* when it has none (its draw failed or missed the deadline, the marker
|
|
11617
|
+
* write failed, or the popup already ended), else the reference the marker
|
|
11618
|
+
* holds.
|
|
11619
|
+
*/
|
|
11620
|
+
get reference() {
|
|
11621
|
+
return this.current;
|
|
11622
|
+
}
|
|
11623
|
+
/**
|
|
11624
|
+
* A popup opened, or the current one asked again for the reference it
|
|
11625
|
+
* lacks: arm the marker holding no reference, and draw this open's own.
|
|
11626
|
+
* Resolves true once this open's reference is decided while its popup is
|
|
11627
|
+
* still the current one of a live sign-in, so that popup may be told; false
|
|
11628
|
+
* when the popup ended or was replaced, or the sign-in ended. Never
|
|
11629
|
+
* rejects.
|
|
11630
|
+
*/
|
|
11631
|
+
open(draw) {
|
|
11632
|
+
if (!this.live)
|
|
11633
|
+
return Promise.resolve(false);
|
|
11634
|
+
const open = ++this.opens;
|
|
11635
|
+
this.at = Date.now();
|
|
11636
|
+
this.current = undefined;
|
|
11637
|
+
// A marker this open cannot write must not keep an earlier open's reference.
|
|
11638
|
+
if (!this.write(null))
|
|
11639
|
+
removePendingMarker();
|
|
11640
|
+
const decided = signinReferenceInTime(draw()).then((reference) => {
|
|
11641
|
+
if (!this.live || open !== this.opens)
|
|
11642
|
+
return false;
|
|
11643
|
+
this.current = reference !== null && this.write(reference) ? reference : null;
|
|
11644
|
+
return true;
|
|
11645
|
+
});
|
|
11646
|
+
this.decided = decided;
|
|
11647
|
+
return decided;
|
|
11648
|
+
}
|
|
11649
|
+
/**
|
|
11650
|
+
* The opener saw the popup end with no result, so there is no lost result
|
|
11651
|
+
* to recover: without this, a reload while the retry alert is up would
|
|
11652
|
+
* bounce for nothing. The ended popup is told nothing more, and its draw,
|
|
11653
|
+
* should it land, is dropped.
|
|
11654
|
+
*/
|
|
11655
|
+
retire() {
|
|
11656
|
+
if (!this.live)
|
|
11657
|
+
return;
|
|
11658
|
+
this.opens += 1;
|
|
11659
|
+
this.current = null;
|
|
11660
|
+
removePendingMarker();
|
|
11661
|
+
}
|
|
11662
|
+
/** The sign-in settled, or another replaced it: retire the marker, and nothing this sign-in does later touches it. */
|
|
11663
|
+
end() {
|
|
11664
|
+
this.retire();
|
|
11665
|
+
this.live = false;
|
|
11666
|
+
}
|
|
11667
|
+
/**
|
|
11668
|
+
* The current popup's reference, waiting at most `waitMs` for an open still
|
|
11669
|
+
* drawing it: the reference the marker holds, else null (the popup has
|
|
11670
|
+
* none, or its draw has not landed in time). Never rejects.
|
|
11671
|
+
*/
|
|
11672
|
+
referenceWithin(waitMs) {
|
|
11673
|
+
if (this.current !== undefined)
|
|
11674
|
+
return Promise.resolve(this.current);
|
|
11675
|
+
return new Promise((settle) => {
|
|
11676
|
+
const deadline = setTimeout(() => settle(this.current ?? null), waitMs);
|
|
11677
|
+
void this.decided.then(() => {
|
|
11678
|
+
clearTimeout(deadline);
|
|
11679
|
+
settle(this.current ?? null);
|
|
11680
|
+
});
|
|
11681
|
+
});
|
|
11682
|
+
}
|
|
11683
|
+
/** Write the marker; a write that fails leaves the stored marker as it was. */
|
|
11684
|
+
write(reference) {
|
|
11685
|
+
const marker = { at: this.at, hint: this.hint, ...(reference ? { ref: reference } : {}) };
|
|
11686
|
+
try {
|
|
11687
|
+
sessionStorage.setItem(PENDING_KEY, JSON.stringify(marker));
|
|
11688
|
+
}
|
|
11689
|
+
catch {
|
|
11690
|
+
return false;
|
|
11691
|
+
}
|
|
11692
|
+
return true;
|
|
11693
|
+
}
|
|
10672
11694
|
}
|
|
11695
|
+
|
|
11696
|
+
/**
|
|
11697
|
+
* Identity Module
|
|
11698
|
+
*
|
|
11699
|
+
* Passwordless sign-in through the first-party SparkVault popup.
|
|
11700
|
+
* Supports passkey, OTP, SparkLink, social authentication, and the account's
|
|
11701
|
+
* own identity provider.
|
|
11702
|
+
*
|
|
11703
|
+
* @example Programmatic
|
|
11704
|
+
* const result = await sv.products.identity.signIn();
|
|
11705
|
+
*
|
|
11706
|
+
* @example Attached to clicks
|
|
11707
|
+
* sv.products.identity.attach('.login-btn');
|
|
11708
|
+
*/
|
|
11709
|
+
const PORTAL_SECTIONS = ['home', 'identity', 'security', 'sessions', 'sites'];
|
|
11710
|
+
// The exact algorithms the Identity server signs identity tokens with: EdDSA by
|
|
11711
|
+
// default, RS256 when a client opts in via `id_token_signed_response_alg`. The
|
|
11712
|
+
// unverified client-side decode gates on this set so an unsigned (`none`) or
|
|
11713
|
+
// algorithm-confused token cannot masquerade as valid.
|
|
11714
|
+
const ACCEPTED_TOKEN_ALGS = ['EdDSA', 'RS256'];
|
|
10673
11715
|
/**
|
|
10674
11716
|
* Whether `handleRedirectResult()` has anything to do on this load — a returned
|
|
10675
11717
|
* sign-in fragment to consume, or a pending sign-in to self-heal. Public + side
|
|
@@ -10685,7 +11727,7 @@ function isSignInRecoveryPending() {
|
|
|
10685
11727
|
if (/[#&](sv_code|sv_error|sso)=/.test(window.location.hash || '')) {
|
|
10686
11728
|
return true;
|
|
10687
11729
|
}
|
|
10688
|
-
return
|
|
11730
|
+
return isFreshPendingMarker(readPendingMarker());
|
|
10689
11731
|
}
|
|
10690
11732
|
function isTokenClaims(payload) {
|
|
10691
11733
|
if (typeof payload !== 'object' || payload === null) {
|
|
@@ -10736,6 +11778,8 @@ class IdentityModule {
|
|
|
10736
11778
|
constructor(config) {
|
|
10737
11779
|
this.renderer = null;
|
|
10738
11780
|
this.launcher = null;
|
|
11781
|
+
// The popup sign-in in flight: its pending marker and reference.
|
|
11782
|
+
this.pendingSignIn = null;
|
|
10739
11783
|
this.config = config;
|
|
10740
11784
|
this.api = new IdentityApi(config);
|
|
10741
11785
|
// Preload config in background for instant dialog opening
|
|
@@ -10873,8 +11917,10 @@ class IdentityModule {
|
|
|
10873
11917
|
* Resilience: pair this with `handleRedirectResult()` on page load. If the
|
|
10874
11918
|
* popup's result is ever lost (a mobile browser discards the backgrounded
|
|
10875
11919
|
* opener tab), the next load silently self-heals from the SSO session the
|
|
10876
|
-
*
|
|
10877
|
-
*
|
|
11920
|
+
* popup signed in or chose; a sign-in that opened none (the account's own
|
|
11921
|
+
* identity provider) comes back signed out, to sign in again. `flow:
|
|
11922
|
+
* 'redirect'` opts a caller out of the popup into a same-tab navigation
|
|
11923
|
+
* instead.
|
|
10878
11924
|
*
|
|
10879
11925
|
* @example
|
|
10880
11926
|
* const result = await sv.products.identity.signIn();
|
|
@@ -10892,13 +11938,12 @@ class IdentityModule {
|
|
|
10892
11938
|
* Core flow runner. Default mode (no `target`) opens the popup; `flow:
|
|
10893
11939
|
* 'redirect'` navigates the tab instead; local mode (`renderMode: 'local'` /
|
|
10894
11940
|
* `target`) renders into the current document and powers the
|
|
10895
|
-
* SparkVault-hosted sign-in surfaces (see the internal `render`)
|
|
11941
|
+
* SparkVault-hosted sign-in surfaces (see the internal `render`), which
|
|
11942
|
+
* hands it what a round trip to the account's own identity provider
|
|
11943
|
+
* returned (`federationReturn`).
|
|
10896
11944
|
*/
|
|
10897
|
-
async runFlow(options = {}) {
|
|
10898
|
-
|
|
10899
|
-
this.launcher.close();
|
|
10900
|
-
this.launcher = null;
|
|
10901
|
-
}
|
|
11945
|
+
async runFlow(options = {}, federationReturn = null) {
|
|
11946
|
+
this.closeLauncher();
|
|
10902
11947
|
if (this.renderer) {
|
|
10903
11948
|
this.renderer.close();
|
|
10904
11949
|
}
|
|
@@ -10941,7 +11986,7 @@ class IdentityModule {
|
|
|
10941
11986
|
},
|
|
10942
11987
|
};
|
|
10943
11988
|
const startLocalRender = (container) => {
|
|
10944
|
-
this.renderer = new IdentityRenderer(container, this.api, mergedOptions, hostCallbacks);
|
|
11989
|
+
this.renderer = new IdentityRenderer(container, this.api, mergedOptions, hostCallbacks, federationReturn);
|
|
10945
11990
|
this.renderer.start().catch((error) => {
|
|
10946
11991
|
// A startup failure must surface inside the SparkVault dialog, never
|
|
10947
11992
|
// close it silently. Render the error in-dialog instead (consistent with
|
|
@@ -10963,10 +12008,11 @@ class IdentityModule {
|
|
|
10963
12008
|
// returns via handleRedirectResult() (the escape hatch for hosts that
|
|
10964
12009
|
// want to skip the popup on mobile). Then this page is unloading, so the
|
|
10965
12010
|
// promise never settles on success; it rejects only if the redirect
|
|
10966
|
-
// cannot start.
|
|
12011
|
+
// cannot start. The sign-in completes in that tab, which no recovery
|
|
12012
|
+
// stands in for, so it draws no reference.
|
|
10967
12013
|
if (mergedOptions.flow === 'redirect') {
|
|
10968
12014
|
try {
|
|
10969
|
-
if (!await this.startRedirectFlow(mergedOptions)) {
|
|
12015
|
+
if (!await this.startRedirectFlow(mergedOptions, null)) {
|
|
10970
12016
|
hostCallbacks.onError(new ValidationError('Sign-in requires browser session storage. Enable site data for this site and try again.'));
|
|
10971
12017
|
}
|
|
10972
12018
|
}
|
|
@@ -10979,24 +12025,44 @@ class IdentityModule {
|
|
|
10979
12025
|
// as in flight so that if its result is lost (a mobile browser discards
|
|
10980
12026
|
// the backgrounded opener tab, killing the postMessage listener),
|
|
10981
12027
|
// handleRedirectResult() can silently self-heal on the next load from
|
|
10982
|
-
// the SSO session the popup
|
|
10983
|
-
|
|
10984
|
-
|
|
10985
|
-
this.
|
|
10986
|
-
|
|
10987
|
-
|
|
10988
|
-
|
|
12028
|
+
// the SSO session the popup signed in or chose, which that popup's
|
|
12029
|
+
// reference names (see pending-signin.ts).
|
|
12030
|
+
const pending = new PendingSignIn(mergedOptions.email || mergedOptions.phone || null);
|
|
12031
|
+
this.pendingSignIn = pending;
|
|
12032
|
+
const launcher = new DialogLauncher(this.config, this.api, mergedOptions, {
|
|
12033
|
+
onSuccess: (result) => { pending.end(); hostCallbacks.onSuccess(result); },
|
|
12034
|
+
onError: (error) => { pending.end(); hostCallbacks.onError(error); },
|
|
12035
|
+
onCancel: () => { pending.end(); hostCallbacks.onCancel(); },
|
|
10989
12036
|
// Self-heal exists for a result the opener never observed. An observed
|
|
10990
12037
|
// no-result end retires the marker (no spurious bounce on a reload
|
|
10991
|
-
// while the retry alert is up)
|
|
10992
|
-
onPopupClosedUnresolved: () =>
|
|
10993
|
-
|
|
12038
|
+
// while the retry alert is up).
|
|
12039
|
+
onPopupClosedUnresolved: () => pending.retire(),
|
|
12040
|
+
// Every popup, the first and each "Try again", arms the marker anew
|
|
12041
|
+
// with a reference of its own, and so does a popup that has none and
|
|
12042
|
+
// asks again. It reaches the popup only once the marker holds it (or
|
|
12043
|
+
// as null, once the popup has none).
|
|
12044
|
+
drawSigninReference: () => {
|
|
12045
|
+
void pending.open(() => this.api.drawSigninReference()).then((stillCurrent) => {
|
|
12046
|
+
if (stillCurrent)
|
|
12047
|
+
launcher.signinReferenceDecided();
|
|
12048
|
+
});
|
|
12049
|
+
},
|
|
10994
12050
|
// COOP-severed popup: postMessage can never deliver, so switch this tab
|
|
10995
|
-
// to the redirect flow (returns via handleRedirectResult).
|
|
10996
|
-
// marker
|
|
10997
|
-
|
|
12051
|
+
// to the redirect flow (returns via handleRedirectResult). It carries
|
|
12052
|
+
// the reference the marker holds for this popup, waiting a moment for
|
|
12053
|
+
// a draw still out, and the marker stays armed: the returned #sv_code
|
|
12054
|
+
// fragment retires it. With none by then, the marker is retired, for
|
|
12055
|
+
// no recovery may stand in for a page sent without a reference.
|
|
12056
|
+
onPopupSevered: async () => {
|
|
12057
|
+
const signinRef = await pending.referenceWithin(SIGNIN_REFERENCE.redirectWaitMs);
|
|
12058
|
+
if (signinRef === null)
|
|
12059
|
+
pending.retire();
|
|
12060
|
+
return this.startRedirectFlow(mergedOptions, signinRef);
|
|
12061
|
+
},
|
|
12062
|
+
signinReference: () => pending.reference,
|
|
10998
12063
|
});
|
|
10999
|
-
this.launcher
|
|
12064
|
+
this.launcher = launcher;
|
|
12065
|
+
launcher.start();
|
|
11000
12066
|
return settledPromise;
|
|
11001
12067
|
}
|
|
11002
12068
|
startLocalRender(isInline
|
|
@@ -11029,6 +12095,7 @@ class IdentityModule {
|
|
|
11029
12095
|
phone: options.phone,
|
|
11030
12096
|
authContext: options.authContext,
|
|
11031
12097
|
prompt: options.prompt,
|
|
12098
|
+
method: options.method,
|
|
11032
12099
|
onSuccess: options.onSuccess,
|
|
11033
12100
|
onError: options.onError,
|
|
11034
12101
|
onCancel: options.onCancel,
|
|
@@ -11104,10 +12171,13 @@ class IdentityModule {
|
|
|
11104
12171
|
* `onSuccess` (and resolve with it).
|
|
11105
12172
|
* 2. A sign-in was in flight but never delivered (a mobile browser
|
|
11106
12173
|
* discarded the backgrounded opener tab, killing the popup's
|
|
11107
|
-
* postMessage) — silently re-mint from the SSO session the
|
|
11108
|
-
*
|
|
11109
|
-
*
|
|
11110
|
-
*
|
|
12174
|
+
* postMessage) — silently re-mint from the SSO session the popup signed
|
|
12175
|
+
* in or chose, by navigating this tab through the silent SSO endpoint
|
|
12176
|
+
* and straight back with a code (case 1 on return). The bounce names
|
|
12177
|
+
* the sign-in's reference, and the endpoint mints only when the
|
|
12178
|
+
* session it would mint from carries it. Nothing is shown; with no
|
|
12179
|
+
* such session (a sign-in that opened none, such as one through the
|
|
12180
|
+
* account's own identity provider) it comes back logged-out, no oracle.
|
|
11111
12181
|
*
|
|
11112
12182
|
* The code is one-time, PKCE-bound, and origin-locked — never the token. The
|
|
11113
12183
|
* host must still verify `result.token` server-side via the Identity JWKS.
|
|
@@ -11136,8 +12206,8 @@ class IdentityModule {
|
|
|
11136
12206
|
// No returned result. If a sign-in was in flight and its result never
|
|
11137
12207
|
// arrived, self-heal once from the SSO session (mobile opener-tab discard).
|
|
11138
12208
|
const pending = this.consumeSignInPending();
|
|
11139
|
-
if (pending
|
|
11140
|
-
await this.startRecoveryBounce(pending
|
|
12209
|
+
if (pending) {
|
|
12210
|
+
await this.startRecoveryBounce(pending);
|
|
11141
12211
|
}
|
|
11142
12212
|
return null;
|
|
11143
12213
|
}
|
|
@@ -11148,7 +12218,7 @@ class IdentityModule {
|
|
|
11148
12218
|
// A returned fragment means this sign-in resolved (redeem, cancel, or
|
|
11149
12219
|
// error), so retire any pending marker — otherwise it could fire one
|
|
11150
12220
|
// spurious silent bounce on a later load inside its TTL.
|
|
11151
|
-
|
|
12221
|
+
removePendingMarker();
|
|
11152
12222
|
// Consume exactly once: fragment and one-shot state/verifier are cleared
|
|
11153
12223
|
// up front on every path, so a failing result cannot wedge future loads
|
|
11154
12224
|
// (and a StrictMode double-invocation finds an empty hash and no-ops).
|
|
@@ -11202,8 +12272,8 @@ class IdentityModule {
|
|
|
11202
12272
|
}
|
|
11203
12273
|
}
|
|
11204
12274
|
/**
|
|
11205
|
-
* Silently re-mint the sign-in result from the SSO session the
|
|
11206
|
-
*
|
|
12275
|
+
* Silently re-mint the sign-in result from the SSO session the popup signed
|
|
12276
|
+
* in or chose. Navigates this tab through the silent SSO endpoint
|
|
11207
12277
|
* (a top-level GET, so the `SameSite=Lax` hub cookie rides along) which,
|
|
11208
12278
|
* PKCE-bound, returns a one-time code in the fragment — handled by case 1 on
|
|
11209
12279
|
* return. No-op (stays put) if session storage or WebCrypto is unavailable,
|
|
@@ -11213,52 +12283,73 @@ class IdentityModule {
|
|
|
11213
12283
|
* malformed answer) rejects `handleRedirectResult()` with that error, and the
|
|
11214
12284
|
* page stays put.
|
|
11215
12285
|
*/
|
|
11216
|
-
async startRecoveryBounce(
|
|
12286
|
+
async startRecoveryBounce(pending) {
|
|
12287
|
+
const handoff = await this.armHandoffReturn();
|
|
12288
|
+
if (!handoff) {
|
|
12289
|
+
return;
|
|
12290
|
+
}
|
|
11217
12291
|
const sso = new URL(`${this.config.identityBaseUrl}/${this.config.accountId}/sso`);
|
|
11218
12292
|
// With several hub sessions, login_hint names the account the interrupted
|
|
11219
|
-
// sign-in was addressing
|
|
11220
|
-
//
|
|
11221
|
-
//
|
|
11222
|
-
//
|
|
11223
|
-
|
|
11224
|
-
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11228
|
-
|
|
11229
|
-
|
|
11230
|
-
|
|
11231
|
-
|
|
11232
|
-
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
|
|
11236
|
-
|
|
12293
|
+
// sign-in was addressing: /sso mints silently ONLY for a hint that matched
|
|
12294
|
+
// exactly one hub session's verified identifiers — every unsatisfiable hint
|
|
12295
|
+
// (a stranger's address, an ambiguous match, an account not eligible here)
|
|
12296
|
+
// comes back with no result at all rather than a different account's.
|
|
12297
|
+
if (pending.hint) {
|
|
12298
|
+
sso.searchParams.set('login_hint', pending.hint);
|
|
12299
|
+
}
|
|
12300
|
+
// The sign-in's reference, recorded on the hub session the popup signed
|
|
12301
|
+
// in or chose: /sso mints only when that session carries it. Without it, a
|
|
12302
|
+
// sign-in that opened no hub session of its own (the account's own
|
|
12303
|
+
// identity provider) would recover as whatever session this browser
|
|
12304
|
+
// already held, someone else entirely.
|
|
12305
|
+
if (pending.ref) {
|
|
12306
|
+
sso.searchParams.set(SIGNIN_REFERENCE.param, pending.ref);
|
|
12307
|
+
}
|
|
12308
|
+
sso.searchParams.set('redirect_uri', handoff.redirectUri);
|
|
12309
|
+
sso.searchParams.set('state', handoff.state);
|
|
12310
|
+
sso.searchParams.set('code_challenge', handoff.codeChallenge);
|
|
12311
|
+
window.location.assign(sso.toString());
|
|
12312
|
+
}
|
|
12313
|
+
/**
|
|
12314
|
+
* Navigate this tab to the interactive sign-in page: explicit `flow:
|
|
12315
|
+
* 'redirect'`, or a popup whose handle COOP severed. Plain sign-in carries
|
|
12316
|
+
* redirect_uri + state + PKCE challenge and returns via the fragment code;
|
|
12317
|
+
* OIDC/simple modes navigate without them (their server-rendered pages drive
|
|
12318
|
+
* the server-validated redirect back). Either carries `signinRef`, the
|
|
12319
|
+
* severed popup's reference; a redirect draws none of its own.
|
|
11237
12320
|
*
|
|
12321
|
+
* @param signinRef - The reference the pending marker holds for this
|
|
12322
|
+
* sign-in, or null for a page sent without one
|
|
11238
12323
|
* @returns false when the return leg cannot be armed (no session storage or
|
|
11239
12324
|
* WebCrypto) — the caller surfaces an actionable error instead of a
|
|
11240
12325
|
* silent dead-end.
|
|
11241
12326
|
*/
|
|
11242
|
-
async startRedirectFlow(options) {
|
|
12327
|
+
async startRedirectFlow(options, signinRef) {
|
|
12328
|
+
if (signinRef === null) {
|
|
12329
|
+
// With no marker, no recovery can stand in for this page's result, so
|
|
12330
|
+
// the page needs no reference. A marker left from an earlier sign-in
|
|
12331
|
+
// would otherwise bounce on the next load in place of this one.
|
|
12332
|
+
removePendingMarker();
|
|
12333
|
+
}
|
|
11243
12334
|
const authContext = options.authContext;
|
|
11244
12335
|
if (authContext?.authRequestId || authContext?.simpleMode?.sessionId) {
|
|
11245
|
-
window.location.assign(buildSigninUrl(this.config, options));
|
|
12336
|
+
window.location.assign(buildSigninUrl(this.config, options, { kind: 'redirect', signinRef }));
|
|
11246
12337
|
return true;
|
|
11247
12338
|
}
|
|
11248
|
-
const
|
|
11249
|
-
if (!
|
|
12339
|
+
const handoff = await this.armHandoffReturn();
|
|
12340
|
+
if (!handoff) {
|
|
11250
12341
|
return false;
|
|
11251
12342
|
}
|
|
11252
|
-
window.location.assign(
|
|
12343
|
+
window.location.assign(buildSigninUrl(this.config, options, { kind: 'redirect', signinRef, handoff }));
|
|
11253
12344
|
return true;
|
|
11254
12345
|
}
|
|
11255
12346
|
/**
|
|
11256
|
-
* Arm the PKCE + state return leg
|
|
11257
|
-
*
|
|
11258
|
-
* Returns null when session storage or WebCrypto is
|
|
11259
|
-
* can degrade.
|
|
12347
|
+
* Arm the PKCE + state return leg of a handoff navigation and return what
|
|
12348
|
+
* the navigation carries for it (redirect_uri = this page, per
|
|
12349
|
+
* `currentPageReturnUrl`). Returns null when session storage or WebCrypto is
|
|
12350
|
+
* unavailable so callers can degrade.
|
|
11260
12351
|
*/
|
|
11261
|
-
async
|
|
12352
|
+
async armHandoffReturn() {
|
|
11262
12353
|
const { state, codeVerifier } = await this.api.drawAuthorizationValues();
|
|
11263
12354
|
// Derive the challenge BEFORE persisting: a WebCrypto failure (insecure
|
|
11264
12355
|
// context) then leaves no orphaned state/verifier behind in storage.
|
|
@@ -11276,49 +12367,25 @@ class IdentityModule {
|
|
|
11276
12367
|
catch {
|
|
11277
12368
|
return null;
|
|
11278
12369
|
}
|
|
11279
|
-
|
|
11280
|
-
if (build) {
|
|
11281
|
-
return build({ redirectUri, state, codeChallenge });
|
|
11282
|
-
}
|
|
11283
|
-
const url = new URL(base);
|
|
11284
|
-
url.searchParams.set('redirect_uri', redirectUri);
|
|
11285
|
-
url.searchParams.set('state', state);
|
|
11286
|
-
url.searchParams.set('code_challenge', codeChallenge);
|
|
11287
|
-
return url.toString();
|
|
11288
|
-
}
|
|
11289
|
-
/**
|
|
11290
|
-
* Arm the self-heal marker for an in-flight sign-in. `hint` is the identifier
|
|
11291
|
-
* (email or phone) the sign-in was started with, when the caller supplied
|
|
11292
|
-
* one — the recovery bounce forwards it as the /sso `login_hint`, so with
|
|
11293
|
-
* several hub sessions recovery re-mints the account this sign-in was for,
|
|
11294
|
-
* never a different one.
|
|
11295
|
-
*/
|
|
11296
|
-
markSignInPending(hint) {
|
|
11297
|
-
try {
|
|
11298
|
-
sessionStorage.setItem(PENDING_KEY, JSON.stringify({ at: Date.now(), hint }));
|
|
11299
|
-
}
|
|
11300
|
-
catch {
|
|
11301
|
-
// No storage → no self-heal; the popup still delivers when it can.
|
|
11302
|
-
}
|
|
11303
|
-
}
|
|
11304
|
-
clearSignInPending() {
|
|
11305
|
-
try {
|
|
11306
|
-
sessionStorage.removeItem(PENDING_KEY);
|
|
11307
|
-
}
|
|
11308
|
-
catch {
|
|
11309
|
-
// Nothing to clear.
|
|
11310
|
-
}
|
|
12370
|
+
return { redirectUri: currentPageReturnUrl(), state, codeChallenge };
|
|
11311
12371
|
}
|
|
11312
12372
|
/**
|
|
11313
|
-
* Consume the pending marker:
|
|
11314
|
-
* sign-in is still awaiting its result
|
|
11315
|
-
* carried, for the recovery bounce's `login_hint
|
|
12373
|
+
* Consume the pending marker: the marker once (then cleared) while a recent
|
|
12374
|
+
* sign-in is still awaiting its result, else null. Its `hint` is the
|
|
12375
|
+
* identifier that sign-in carried, for the recovery bounce's `login_hint`,
|
|
12376
|
+
* and its `ref` the sign-in's reference, when the marker holds one.
|
|
11316
12377
|
*/
|
|
11317
12378
|
consumeSignInPending() {
|
|
11318
12379
|
const marker = readPendingMarker();
|
|
11319
|
-
|
|
11320
|
-
|
|
11321
|
-
|
|
12380
|
+
removePendingMarker();
|
|
12381
|
+
return isFreshPendingMarker(marker) ? marker : null;
|
|
12382
|
+
}
|
|
12383
|
+
/** Close the popup sign-in's launcher, ending the sign-in it ran. */
|
|
12384
|
+
closeLauncher() {
|
|
12385
|
+
this.launcher?.close();
|
|
12386
|
+
this.launcher = null;
|
|
12387
|
+
this.pendingSignIn?.end();
|
|
12388
|
+
this.pendingSignIn = null;
|
|
11322
12389
|
}
|
|
11323
12390
|
/** Remove the result fragment from the URL bar (and history entry). */
|
|
11324
12391
|
clearUrlFragment() {
|
|
@@ -11337,8 +12404,9 @@ class IdentityModule {
|
|
|
11337
12404
|
}
|
|
11338
12405
|
}
|
|
11339
12406
|
/**
|
|
11340
|
-
* Complete a social round trip
|
|
11341
|
-
*
|
|
12407
|
+
* Complete a social round trip, or one through the account's own identity
|
|
12408
|
+
* provider, that returned to the sign-in page as `#token=…&state=…`. Only
|
|
12409
|
+
* `render()`, the Identity-origin sign-in page,
|
|
11342
12410
|
* reads it: no SDK flow returns a `#token` to a site (a site's results arrive
|
|
11343
12411
|
* by the popup's postMessage, FedCM, or a PKCE-bound `#sv_code`), so on a site
|
|
11344
12412
|
* it could only be someone else's token, or the site's own direct
|
|
@@ -11349,7 +12417,7 @@ class IdentityModule {
|
|
|
11349
12417
|
return null;
|
|
11350
12418
|
}
|
|
11351
12419
|
const params = new URLSearchParams(window.location.hash.slice(1));
|
|
11352
|
-
const token = params.get(
|
|
12420
|
+
const token = params.get(SIGNIN_RESULT_FRAGMENT.token);
|
|
11353
12421
|
if (!token) {
|
|
11354
12422
|
return null;
|
|
11355
12423
|
}
|
|
@@ -11372,7 +12440,7 @@ class IdentityModule {
|
|
|
11372
12440
|
// provider. Anyone can compose a URL carrying their own genuinely-signed
|
|
11373
12441
|
// token, so a fragment with no stored state, or a different one, is an
|
|
11374
12442
|
// unsolicited result (login CSRF) and is refused.
|
|
11375
|
-
if (!expectedState || params.get(
|
|
12443
|
+
if (!expectedState || params.get(SIGNIN_RESULT_FRAGMENT.state) !== expectedState) {
|
|
11376
12444
|
throw new ValidationError('Invalid OAuth state');
|
|
11377
12445
|
}
|
|
11378
12446
|
// Unverified client-side decode — surfaces the claims for the result
|
|
@@ -11396,7 +12464,38 @@ class IdentityModule {
|
|
|
11396
12464
|
catch {
|
|
11397
12465
|
// Storage disabled (private mode): nothing to clear.
|
|
11398
12466
|
}
|
|
12467
|
+
// The round trip came back, so a start this tab made on its own is
|
|
12468
|
+
// answered and must not hold back the page's next sign-in.
|
|
12469
|
+
takeFederationAutoStart(this.config.accountId);
|
|
12470
|
+
}
|
|
12471
|
+
}
|
|
12472
|
+
/**
|
|
12473
|
+
* Read a refusal a round trip through the account's own identity provider
|
|
12474
|
+
* returned to the sign-in page (`#error=…&state=…`, see federation-flow.ts).
|
|
12475
|
+
* Such a fragment is consumed exactly once, with the state it answers,
|
|
12476
|
+
* whatever it holds. Null for any other fragment, and for a refusal whose
|
|
12477
|
+
* state is not the one this browser stored before it left: an answer to no
|
|
12478
|
+
* sign-in this browser started, which the page ignores.
|
|
12479
|
+
*/
|
|
12480
|
+
consumeFederationReturn() {
|
|
12481
|
+
if (typeof window === 'undefined' || !window.location.hash) {
|
|
12482
|
+
return null;
|
|
12483
|
+
}
|
|
12484
|
+
const params = new URLSearchParams(window.location.hash.slice(1));
|
|
12485
|
+
const refusal = federationRefusalIn(params);
|
|
12486
|
+
if (!refusal) {
|
|
12487
|
+
return null;
|
|
12488
|
+
}
|
|
12489
|
+
let expectedState = null;
|
|
12490
|
+
try {
|
|
12491
|
+
expectedState = sessionStorage.getItem('sv_oauth_state');
|
|
12492
|
+
sessionStorage.removeItem('sv_oauth_state');
|
|
12493
|
+
}
|
|
12494
|
+
catch {
|
|
12495
|
+
// Storage disabled: no sign-in could have stored a state here.
|
|
11399
12496
|
}
|
|
12497
|
+
this.clearUrlFragment();
|
|
12498
|
+
return expectedState && params.get(SIGNIN_RESULT_FRAGMENT.state) === expectedState ? refusal : null;
|
|
11400
12499
|
}
|
|
11401
12500
|
/**
|
|
11402
12501
|
* Close the identity dialog/inline UI if open.
|
|
@@ -11405,10 +12504,7 @@ class IdentityModule {
|
|
|
11405
12504
|
* mode) or the local renderer (inline / local mode).
|
|
11406
12505
|
*/
|
|
11407
12506
|
close() {
|
|
11408
|
-
|
|
11409
|
-
this.launcher.close();
|
|
11410
|
-
this.launcher = null;
|
|
11411
|
-
}
|
|
12507
|
+
this.closeLauncher();
|
|
11412
12508
|
if (this.renderer) {
|
|
11413
12509
|
this.renderer.close();
|
|
11414
12510
|
this.renderer = null;
|
|
@@ -11452,9 +12548,12 @@ class IdentityModule {
|
|
|
11452
12548
|
/**
|
|
11453
12549
|
* Render the flow into a page element instead of a popup.
|
|
11454
12550
|
*
|
|
11455
|
-
* A social login
|
|
11456
|
-
*
|
|
11457
|
-
* `
|
|
12551
|
+
* A social login, or one through the account's own identity provider,
|
|
12552
|
+
* started here returns to this same page with its result in the fragment,
|
|
12553
|
+
* so a returned `#token` is completed first (see `consumeRedirectResult`)
|
|
12554
|
+
* instead of starting the flow again, and a returned refusal of the
|
|
12555
|
+
* account's own identity provider is handed to the flow it starts (see
|
|
12556
|
+
* `consumeFederationReturn`).
|
|
11458
12557
|
*
|
|
11459
12558
|
* @internal Used only by the SparkVault-hosted sign-in popup and hosted login
|
|
11460
12559
|
* page (which own their chrome and pass `renderMode: 'local'`). Customer
|
|
@@ -11466,7 +12565,7 @@ class IdentityModule {
|
|
|
11466
12565
|
options.onSuccess?.(returned);
|
|
11467
12566
|
return returned;
|
|
11468
12567
|
}
|
|
11469
|
-
return this.runFlow(options);
|
|
12568
|
+
return this.runFlow(options, this.consumeFederationReturn());
|
|
11470
12569
|
}
|
|
11471
12570
|
}
|
|
11472
12571
|
|
|
@@ -28351,7 +29450,7 @@ class SparkVault {
|
|
|
28351
29450
|
}
|
|
28352
29451
|
/** Get the SDK version */
|
|
28353
29452
|
static get version() {
|
|
28354
|
-
return '16.0
|
|
29453
|
+
return '16.1.0';
|
|
28355
29454
|
}
|
|
28356
29455
|
}
|
|
28357
29456
|
if (typeof window !== 'undefined') {
|