@sparkvault/sdk-js 1.27.1 → 1.27.3
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 -1
- package/dist/identity/api.d.ts +7 -5
- package/dist/identity/handlers/passkey-handler.d.ts +3 -3
- package/dist/identity/handlers/totp-handler.d.ts +2 -2
- package/dist/identity/index.d.ts +7 -0
- package/dist/identity/renderer.d.ts +4 -2
- package/dist/identity/state.d.ts +5 -5
- package/dist/identity/types.d.ts +37 -18
- package/dist/identity/views/method-select.d.ts +2 -2
- package/dist/identity/views/passkey-prompt.d.ts +1 -1
- package/dist/identity/views/passkey.d.ts +3 -3
- package/dist/identity/views/totp-verify.d.ts +2 -2
- package/dist/index.d.ts +25 -7
- package/dist/sparkvault.cjs.js +176 -110
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +176 -110
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/sparkvault.cjs.js
CHANGED
|
@@ -971,12 +971,12 @@ class IdentityApi extends SparkVaultApi {
|
|
|
971
971
|
return this.configCache !== null;
|
|
972
972
|
}
|
|
973
973
|
/**
|
|
974
|
-
* Check
|
|
974
|
+
* Check whether the SVID resolved from an email or phone has registered passkeys.
|
|
975
975
|
*
|
|
976
976
|
* Returns:
|
|
977
977
|
* - identity_valid: identity passes per-type validity check
|
|
978
978
|
* (email: MX lookup; phone: E.164 format)
|
|
979
|
-
* - has_passkey: whether any passkeys are registered
|
|
979
|
+
* - has_passkey: whether any passkeys are registered on the resolved SVID
|
|
980
980
|
* (cross-tenant — single global RP)
|
|
981
981
|
*/
|
|
982
982
|
async checkPasskey(identity, identityType = 'email') {
|
|
@@ -1026,7 +1026,7 @@ class IdentityApi extends SparkVaultApi {
|
|
|
1026
1026
|
});
|
|
1027
1027
|
}
|
|
1028
1028
|
/**
|
|
1029
|
-
* Start passkey registration
|
|
1029
|
+
* Start passkey registration from a freshly verified identifier.
|
|
1030
1030
|
*/
|
|
1031
1031
|
async startPasskeyRegister(identity, identityType = 'email', registrationToken) {
|
|
1032
1032
|
const body = identityType === 'phone'
|
|
@@ -1064,19 +1064,19 @@ class IdentityApi extends SparkVaultApi {
|
|
|
1064
1064
|
});
|
|
1065
1065
|
}
|
|
1066
1066
|
/**
|
|
1067
|
-
* Start passkey verification
|
|
1067
|
+
* Start discoverable passkey verification. Legacy identity parameters are
|
|
1068
|
+
* intentionally ignored; the credential userHandle routes completion to the
|
|
1069
|
+
* SVID.
|
|
1068
1070
|
*/
|
|
1069
|
-
async startPasskeyVerify(
|
|
1070
|
-
const identityField = identityType === 'phone' ? { phone: identity } : { email: identity };
|
|
1071
|
+
async startPasskeyVerify(_identity, _identityType = 'email', authContext) {
|
|
1071
1072
|
// Backend returns { options: PublicKeyCredentialRequestOptions, session: {...} }
|
|
1072
1073
|
// Extract and flatten to match PasskeyChallengeResponse
|
|
1073
|
-
const response = await this.request('POST', '/passkey/verify',
|
|
1074
|
+
const response = await this.request('POST', '/passkey/verify', this.buildAuthContextParams(authContext));
|
|
1074
1075
|
return {
|
|
1075
1076
|
challenge: response.options.challenge,
|
|
1076
1077
|
rpId: response.options.rpId,
|
|
1077
1078
|
rpName: 'SparkVault Identity', // Not returned by verify endpoint
|
|
1078
1079
|
timeout: response.options.timeout,
|
|
1079
|
-
allowCredentials: response.options.allowCredentials,
|
|
1080
1080
|
session: response.session,
|
|
1081
1081
|
};
|
|
1082
1082
|
}
|
|
@@ -1172,7 +1172,6 @@ const METHOD_REGISTRY = {
|
|
|
1172
1172
|
passkey: {
|
|
1173
1173
|
id: 'passkey',
|
|
1174
1174
|
type: 'passkey',
|
|
1175
|
-
identityType: 'email',
|
|
1176
1175
|
name: 'Passkey',
|
|
1177
1176
|
description: 'Use biometrics or security key',
|
|
1178
1177
|
icon: 'passkey',
|
|
@@ -1317,19 +1316,20 @@ class VerificationState {
|
|
|
1317
1316
|
return this._sdkConfig?.accountId ?? '';
|
|
1318
1317
|
}
|
|
1319
1318
|
/**
|
|
1320
|
-
* Get enriched methods filtered by
|
|
1319
|
+
* Get enriched methods filtered by the fallback identifier type.
|
|
1321
1320
|
*/
|
|
1322
1321
|
getAvailableMethods() {
|
|
1323
1322
|
if (!this._sdkConfig)
|
|
1324
1323
|
return [];
|
|
1325
1324
|
const methodIds = this._sdkConfig.methods ?? [];
|
|
1326
1325
|
let methods = enrichMethods(methodIds);
|
|
1327
|
-
// Filter by
|
|
1326
|
+
// Filter by identifier type. Passkeys are SVID-scoped and remain
|
|
1327
|
+
// available regardless of whether the fallback identifier is email or phone.
|
|
1328
1328
|
if (this._identityType === 'phone') {
|
|
1329
|
-
methods = methods.filter((m) => m.type === '
|
|
1329
|
+
methods = methods.filter((m) => m.type === 'passkey' || m.identityType === 'phone');
|
|
1330
1330
|
}
|
|
1331
1331
|
else {
|
|
1332
|
-
methods = methods.filter((m) => m.identityType === 'email');
|
|
1332
|
+
methods = methods.filter((m) => m.identityType === 'email' || m.identityType === undefined);
|
|
1333
1333
|
}
|
|
1334
1334
|
return methods;
|
|
1335
1335
|
}
|
|
@@ -1359,7 +1359,9 @@ class VerificationState {
|
|
|
1359
1359
|
this._identityType = type;
|
|
1360
1360
|
}
|
|
1361
1361
|
getAllowedIdentityTypes() {
|
|
1362
|
-
|
|
1362
|
+
if (!this._sdkConfig)
|
|
1363
|
+
return ['email'];
|
|
1364
|
+
const allowed = this._sdkConfig.allowedIdentityTypes ?? ['email'];
|
|
1363
1365
|
return allowed;
|
|
1364
1366
|
}
|
|
1365
1367
|
// --- Auth Context (OIDC/simple mode) ---
|
|
@@ -1384,11 +1386,9 @@ class VerificationState {
|
|
|
1384
1386
|
}
|
|
1385
1387
|
/**
|
|
1386
1388
|
* Check if we should show passkey registration prompt
|
|
1387
|
-
* Based on: passkey enabled,
|
|
1389
|
+
* Based on: passkey enabled, the current SVID doesn't have one, not dismissed
|
|
1388
1390
|
*/
|
|
1389
1391
|
shouldShowPasskeyPrompt() {
|
|
1390
|
-
if (this._identityType !== 'email')
|
|
1391
|
-
return false;
|
|
1392
1392
|
if (!this.isPasskeyEnabled())
|
|
1393
1393
|
return false;
|
|
1394
1394
|
if (this.isPasskeyPromptDismissed())
|
|
@@ -1472,7 +1472,7 @@ class PasskeyHandler {
|
|
|
1472
1472
|
this.accountId = config.accountId;
|
|
1473
1473
|
}
|
|
1474
1474
|
/**
|
|
1475
|
-
* Check if
|
|
1475
|
+
* Check if the current identifier resolves to an SVID with registered passkeys.
|
|
1476
1476
|
* @returns Check result with emailValid and hasPasskey, or null on error
|
|
1477
1477
|
*/
|
|
1478
1478
|
async checkPasskey() {
|
|
@@ -1512,14 +1512,17 @@ class PasskeyHandler {
|
|
|
1512
1512
|
*/
|
|
1513
1513
|
async openPasskeyPopup(mode, registrationToken) {
|
|
1514
1514
|
return new Promise((resolve) => {
|
|
1515
|
-
//
|
|
1516
|
-
//
|
|
1515
|
+
// Registration carries the freshly verified identifier so the backend
|
|
1516
|
+
// can attach the credential to that SVID. Verification is discoverable:
|
|
1517
|
+
// the credential userHandle routes completion to the SVID.
|
|
1517
1518
|
const params = new URLSearchParams({
|
|
1518
1519
|
mode,
|
|
1519
1520
|
origin: window.location.origin,
|
|
1520
1521
|
});
|
|
1521
|
-
|
|
1522
|
-
|
|
1522
|
+
if (mode === 'register' && this.state.recipient) {
|
|
1523
|
+
const identityParam = this.state.identityType === 'phone' ? 'phone' : 'email';
|
|
1524
|
+
params.set(identityParam, this.state.recipient);
|
|
1525
|
+
}
|
|
1523
1526
|
// Add auth context for OIDC/simple mode flows
|
|
1524
1527
|
const authContext = this.state.authContext;
|
|
1525
1528
|
if (authContext?.authRequestId) {
|
|
@@ -1576,6 +1579,9 @@ class PasskeyHandler {
|
|
|
1576
1579
|
token: data.data.token || '',
|
|
1577
1580
|
identity: data.data.identity || this.state.recipient,
|
|
1578
1581
|
identityType: data.data.identity_type || 'email',
|
|
1582
|
+
svid: data.data.svid,
|
|
1583
|
+
sessionId: data.data.session_id,
|
|
1584
|
+
refreshToken: data.data.refresh_token,
|
|
1579
1585
|
redirect: data.data.redirect,
|
|
1580
1586
|
},
|
|
1581
1587
|
});
|
|
@@ -1679,7 +1685,7 @@ class TotpHandler {
|
|
|
1679
1685
|
this.state = state;
|
|
1680
1686
|
}
|
|
1681
1687
|
/**
|
|
1682
|
-
* Send TOTP code via email or
|
|
1688
|
+
* Send TOTP code via email, SMS, or voice
|
|
1683
1689
|
*/
|
|
1684
1690
|
async send(method) {
|
|
1685
1691
|
try {
|
|
@@ -1763,6 +1769,9 @@ class TotpHandler {
|
|
|
1763
1769
|
token: response.token,
|
|
1764
1770
|
identity: response.identity ?? this.state.recipient,
|
|
1765
1771
|
identityType: response.identity_type ?? this.state.identityType,
|
|
1772
|
+
svid: response.svid,
|
|
1773
|
+
sessionId: response.session_id,
|
|
1774
|
+
refreshToken: response.refresh_token,
|
|
1766
1775
|
redirect: response.redirect,
|
|
1767
1776
|
},
|
|
1768
1777
|
};
|
|
@@ -4103,26 +4112,33 @@ class MethodSelectView {
|
|
|
4103
4112
|
this.methodClickHandlers = new Map();
|
|
4104
4113
|
this.props = props;
|
|
4105
4114
|
// Bind handlers once for proper removal
|
|
4106
|
-
this.boundHandleBack = () => this.props.onBack();
|
|
4115
|
+
this.boundHandleBack = () => this.props.onBack?.();
|
|
4107
4116
|
}
|
|
4108
4117
|
render() {
|
|
4109
4118
|
const container = div();
|
|
4110
|
-
this.backLink = this.createBackLink();
|
|
4119
|
+
this.backLink = this.props.onBack ? this.createBackLink() : null;
|
|
4111
4120
|
const title = document.createElement('h3');
|
|
4112
4121
|
title.className = 'sv-title';
|
|
4113
4122
|
title.textContent = 'Choose how to sign in';
|
|
4114
|
-
const
|
|
4115
|
-
subtitle
|
|
4116
|
-
subtitle
|
|
4123
|
+
const email = this.props.email;
|
|
4124
|
+
const subtitle = email ? document.createElement('p') : null;
|
|
4125
|
+
if (subtitle && email) {
|
|
4126
|
+
subtitle.className = 'sv-subtitle';
|
|
4127
|
+
subtitle.textContent = escapeHtml(email);
|
|
4128
|
+
}
|
|
4117
4129
|
const methodsContainer = div();
|
|
4118
4130
|
for (const method of this.props.methods) {
|
|
4119
4131
|
const methodButton = this.createMethodButton(method);
|
|
4120
4132
|
this.methodButtons.push(methodButton);
|
|
4121
4133
|
methodsContainer.appendChild(methodButton);
|
|
4122
4134
|
}
|
|
4123
|
-
|
|
4135
|
+
if (this.backLink) {
|
|
4136
|
+
container.appendChild(this.backLink);
|
|
4137
|
+
}
|
|
4124
4138
|
container.appendChild(title);
|
|
4125
|
-
|
|
4139
|
+
if (subtitle) {
|
|
4140
|
+
container.appendChild(subtitle);
|
|
4141
|
+
}
|
|
4126
4142
|
container.appendChild(methodsContainer);
|
|
4127
4143
|
return container;
|
|
4128
4144
|
}
|
|
@@ -4183,7 +4199,7 @@ class MethodSelectView {
|
|
|
4183
4199
|
/**
|
|
4184
4200
|
* TOTP Verification View
|
|
4185
4201
|
*
|
|
4186
|
-
* Collects and validates the 6-digit TOTP code sent via email or
|
|
4202
|
+
* Collects and validates the 6-digit TOTP code sent via email, SMS, or voice.
|
|
4187
4203
|
*/
|
|
4188
4204
|
const CODE_LENGTH = 6;
|
|
4189
4205
|
class TotpVerifyView {
|
|
@@ -4507,13 +4523,13 @@ class PasskeyView {
|
|
|
4507
4523
|
this.fallbackLink = null;
|
|
4508
4524
|
this.props = props;
|
|
4509
4525
|
// Bind handlers once for proper removal
|
|
4510
|
-
this.boundHandleBack = () => this.props.onBack();
|
|
4526
|
+
this.boundHandleBack = () => this.props.onBack?.();
|
|
4511
4527
|
this.boundHandleStart = () => this.handleStart();
|
|
4512
4528
|
this.boundHandleFallback = props.onFallback ? () => props.onFallback() : null;
|
|
4513
4529
|
}
|
|
4514
4530
|
render() {
|
|
4515
4531
|
const container = div();
|
|
4516
|
-
this.backLink = this.createBackLink();
|
|
4532
|
+
this.backLink = this.props.onBack ? this.createBackLink() : null;
|
|
4517
4533
|
const iconContainer = div();
|
|
4518
4534
|
iconContainer.appendChild(createPasskeyIcon());
|
|
4519
4535
|
const title = document.createElement('h3');
|
|
@@ -4522,10 +4538,10 @@ class PasskeyView {
|
|
|
4522
4538
|
const subtitle = document.createElement('p');
|
|
4523
4539
|
subtitle.className = 'sv-subtitle';
|
|
4524
4540
|
if (this.props.mode === 'register') {
|
|
4525
|
-
subtitle.innerHTML = `Create a passkey for<br><strong>${escapeHtml(this.props.
|
|
4541
|
+
subtitle.innerHTML = `Create a passkey for<br><strong>${escapeHtml(this.props.identityLabel)}</strong><br>to sign in faster next time`;
|
|
4526
4542
|
}
|
|
4527
4543
|
else {
|
|
4528
|
-
subtitle.innerHTML =
|
|
4544
|
+
subtitle.innerHTML = 'Use a passkey linked to your SparkVault Identity';
|
|
4529
4545
|
}
|
|
4530
4546
|
this.errorContainer = div();
|
|
4531
4547
|
if (this.props.error) {
|
|
@@ -4542,7 +4558,9 @@ class PasskeyView {
|
|
|
4542
4558
|
this.actionButton.className = 'sv-btn sv-btn-primary';
|
|
4543
4559
|
this.actionButton.textContent = buttonText;
|
|
4544
4560
|
this.actionButton.addEventListener('click', this.boundHandleStart);
|
|
4545
|
-
|
|
4561
|
+
if (this.backLink) {
|
|
4562
|
+
container.appendChild(this.backLink);
|
|
4563
|
+
}
|
|
4546
4564
|
container.appendChild(iconContainer);
|
|
4547
4565
|
container.appendChild(title);
|
|
4548
4566
|
container.appendChild(subtitle);
|
|
@@ -4558,7 +4576,7 @@ class PasskeyView {
|
|
|
4558
4576
|
createFallbackLink() {
|
|
4559
4577
|
const link = document.createElement('button');
|
|
4560
4578
|
link.className = 'sv-fallback-link';
|
|
4561
|
-
link.textContent = 'Having trouble? Use
|
|
4579
|
+
link.textContent = 'Having trouble? Use a code instead';
|
|
4562
4580
|
if (this.boundHandleFallback) {
|
|
4563
4581
|
link.addEventListener('click', this.boundHandleFallback);
|
|
4564
4582
|
}
|
|
@@ -4631,7 +4649,7 @@ class PasskeyPromptView {
|
|
|
4631
4649
|
title.textContent = 'Add a passkey for faster sign-in?';
|
|
4632
4650
|
const subtitle = document.createElement('p');
|
|
4633
4651
|
subtitle.className = 'sv-subtitle';
|
|
4634
|
-
subtitle.innerHTML = `Next time, sign in instantly as<br><strong>${escapeHtml(this.props.
|
|
4652
|
+
subtitle.innerHTML = `Next time, sign in instantly as<br><strong>${escapeHtml(this.props.identityLabel)}</strong>`;
|
|
4635
4653
|
// Error message if registration failed
|
|
4636
4654
|
const errorContainer = div();
|
|
4637
4655
|
if (this.props.error) {
|
|
@@ -5212,6 +5230,14 @@ class ProductNotConfiguredView {
|
|
|
5212
5230
|
* Orchestrates view state and rendering for identity verification flows.
|
|
5213
5231
|
* Uses extracted handlers for TOTP and Passkey operations.
|
|
5214
5232
|
*/
|
|
5233
|
+
const SPARKLINK_CSP_BLOCKED_ERROR = {
|
|
5234
|
+
message: [
|
|
5235
|
+
'Connection blocked by security policy.',
|
|
5236
|
+
'Please contact the site administrator to add wss://ws.sparkvault.com',
|
|
5237
|
+
'to the Content-Security-Policy connect-src directive.',
|
|
5238
|
+
].join(' '),
|
|
5239
|
+
code: 'sparklink_csp_blocked',
|
|
5240
|
+
};
|
|
5215
5241
|
class IdentityRenderer {
|
|
5216
5242
|
constructor(container, api, options, callbacks) {
|
|
5217
5243
|
// View management
|
|
@@ -5251,7 +5277,6 @@ class IdentityRenderer {
|
|
|
5251
5277
|
this.callbacks.onSuccess(result);
|
|
5252
5278
|
}
|
|
5253
5279
|
catch (err) {
|
|
5254
|
-
// eslint-disable-next-line no-console
|
|
5255
5280
|
console.warn('[SparkVault SDK] onSuccess threw, continuing to redirect', err);
|
|
5256
5281
|
}
|
|
5257
5282
|
}
|
|
@@ -5317,13 +5342,7 @@ class IdentityRenderer {
|
|
|
5317
5342
|
? config.branding.backdrop_blur
|
|
5318
5343
|
: true;
|
|
5319
5344
|
this.container.updateBackdropBlur(resolvedBackdropBlur);
|
|
5320
|
-
|
|
5321
|
-
if (this.recipient) {
|
|
5322
|
-
this.showMethodSelect();
|
|
5323
|
-
}
|
|
5324
|
-
else {
|
|
5325
|
-
this.showIdentityInput();
|
|
5326
|
-
}
|
|
5345
|
+
await this.showInitialAuthStep();
|
|
5327
5346
|
}
|
|
5328
5347
|
catch (error) {
|
|
5329
5348
|
this.setState(this.viewStateForConfigError(error));
|
|
@@ -5380,12 +5399,7 @@ class IdentityRenderer {
|
|
|
5380
5399
|
? config.branding.backdrop_blur
|
|
5381
5400
|
: true;
|
|
5382
5401
|
this.container.updateBackdropBlur(resolvedBackdropBlur);
|
|
5383
|
-
|
|
5384
|
-
this.showMethodSelect();
|
|
5385
|
-
}
|
|
5386
|
-
else {
|
|
5387
|
-
this.showIdentityInput();
|
|
5388
|
-
}
|
|
5402
|
+
await this.showInitialAuthStep();
|
|
5389
5403
|
}
|
|
5390
5404
|
catch (error) {
|
|
5391
5405
|
this.setState(this.viewStateForConfigError(error));
|
|
@@ -5417,6 +5431,13 @@ class IdentityRenderer {
|
|
|
5417
5431
|
this.verificationState.setViewState(state);
|
|
5418
5432
|
this.render();
|
|
5419
5433
|
}
|
|
5434
|
+
async showInitialAuthStep() {
|
|
5435
|
+
if (this.recipient || this.getAllowedIdentityTypes().length === 0) {
|
|
5436
|
+
await this.showMethodSelect();
|
|
5437
|
+
return;
|
|
5438
|
+
}
|
|
5439
|
+
this.showIdentityInput();
|
|
5440
|
+
}
|
|
5420
5441
|
render() {
|
|
5421
5442
|
const body = this.container.getBody();
|
|
5422
5443
|
if (!body)
|
|
@@ -5465,7 +5486,7 @@ class IdentityRenderer {
|
|
|
5465
5486
|
email: state.email,
|
|
5466
5487
|
methods: state.methods,
|
|
5467
5488
|
onSelectMethod: (method) => this.handleMethodSelect(method),
|
|
5468
|
-
onBack: () => this.showIdentityInput(),
|
|
5489
|
+
onBack: state.email ? () => this.showIdentityInput() : undefined,
|
|
5469
5490
|
});
|
|
5470
5491
|
case 'totp-verify':
|
|
5471
5492
|
return new TotpVerifyView({
|
|
@@ -5482,7 +5503,7 @@ class IdentityRenderer {
|
|
|
5482
5503
|
const { passkey } = this.verificationState;
|
|
5483
5504
|
const isFromPrompt = state.mode === 'register' && passkey.pendingResult !== null;
|
|
5484
5505
|
return new PasskeyView({
|
|
5485
|
-
|
|
5506
|
+
identityLabel: state.recipient,
|
|
5486
5507
|
mode: state.mode,
|
|
5487
5508
|
error: state.error,
|
|
5488
5509
|
onStart: () => this.handlePasskeyStart(),
|
|
@@ -5490,7 +5511,11 @@ class IdentityRenderer {
|
|
|
5490
5511
|
? () => this.handlePasskeyRegistrationSkip()
|
|
5491
5512
|
: state.mode === 'verify'
|
|
5492
5513
|
// From passkey verify, enable fallback so showMethodSelect doesn't loop back
|
|
5493
|
-
?
|
|
5514
|
+
? this.passkeyFallbackMethodsAvailable()
|
|
5515
|
+
? () => this.handlePasskeyFallback()
|
|
5516
|
+
: this.recipient
|
|
5517
|
+
? () => this.showIdentityInput()
|
|
5518
|
+
: undefined
|
|
5494
5519
|
: () => this.showMethodSelect(),
|
|
5495
5520
|
onFallback: passkey.hasPasskey && !passkey.isFallbackMode
|
|
5496
5521
|
? () => this.handlePasskeyFallback()
|
|
@@ -5499,7 +5524,7 @@ class IdentityRenderer {
|
|
|
5499
5524
|
}
|
|
5500
5525
|
case 'passkey-prompt':
|
|
5501
5526
|
return new PasskeyPromptView({
|
|
5502
|
-
|
|
5527
|
+
identityLabel: state.recipient,
|
|
5503
5528
|
onAddPasskey: () => this.handlePasskeyPromptAdd(state.pendingResult),
|
|
5504
5529
|
onSkip: () => this.handlePasskeyPromptSkip(state.pendingResult),
|
|
5505
5530
|
error: state.error,
|
|
@@ -5551,45 +5576,22 @@ class IdentityRenderer {
|
|
|
5551
5576
|
}
|
|
5552
5577
|
// Enrich method IDs with metadata from static registry
|
|
5553
5578
|
let methods = enrichMethods(methodIds);
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
if (methods.length === 0) {
|
|
5564
|
-
this.setState({
|
|
5565
|
-
view: 'error',
|
|
5566
|
-
message: 'No authentication methods available',
|
|
5567
|
-
code: 'no_methods',
|
|
5579
|
+
if (this.recipient) {
|
|
5580
|
+
// Filter by identifier type. Passkeys are SVID-scoped, so they remain
|
|
5581
|
+
// available regardless of whether the fallback identifier is email or phone.
|
|
5582
|
+
methods = methods.filter((m) => {
|
|
5583
|
+
if (this.identityType === 'phone') {
|
|
5584
|
+
return m.type === 'passkey' || m.identityType === 'phone';
|
|
5585
|
+
}
|
|
5586
|
+
// Email users can use email-based methods
|
|
5587
|
+
return m.identityType === 'email' || m.identityType === undefined;
|
|
5568
5588
|
});
|
|
5569
|
-
return;
|
|
5570
5589
|
}
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
// Use passkey handler for the check (also validates email domain)
|
|
5577
|
-
const checkResult = await this.passkeyHandler.checkPasskey();
|
|
5578
|
-
// Handle invalid email domain
|
|
5579
|
-
if (checkResult !== null && !checkResult.emailValid) {
|
|
5580
|
-
this.showIdentityInput('This email domain cannot receive messages. Please check your email address.');
|
|
5581
|
-
return;
|
|
5582
|
-
}
|
|
5583
|
-
if (checkResult?.hasPasskey === true) {
|
|
5584
|
-
// User has passkey - go straight to passkey verification
|
|
5585
|
-
this.setState({
|
|
5586
|
-
view: 'passkey',
|
|
5587
|
-
email: this.recipient,
|
|
5588
|
-
mode: 'verify',
|
|
5589
|
-
});
|
|
5590
|
-
return;
|
|
5591
|
-
}
|
|
5592
|
-
// User doesn't have passkey - filter out passkey option
|
|
5590
|
+
else {
|
|
5591
|
+
// No PII prompt is needed when only SVID-routed methods are enabled.
|
|
5592
|
+
methods = methods.filter((m) => m.type === 'passkey' || m.type === 'social');
|
|
5593
|
+
}
|
|
5594
|
+
if (this.verificationState.passkey.isFallbackMode) {
|
|
5593
5595
|
methods = methods.filter((m) => m.type !== 'passkey');
|
|
5594
5596
|
}
|
|
5595
5597
|
if (methods.length === 0) {
|
|
@@ -5621,7 +5623,11 @@ class IdentityRenderer {
|
|
|
5621
5623
|
try {
|
|
5622
5624
|
switch (method.type) {
|
|
5623
5625
|
case 'totp': {
|
|
5624
|
-
const totpMethod = method.id === 'totp_sms'
|
|
5626
|
+
const totpMethod = method.id === 'totp_sms'
|
|
5627
|
+
? 'sms'
|
|
5628
|
+
: method.id === 'totp_voice'
|
|
5629
|
+
? 'voice'
|
|
5630
|
+
: 'email';
|
|
5625
5631
|
this.setState({ view: 'loading' });
|
|
5626
5632
|
const result = await this.totpHandler.send(totpMethod);
|
|
5627
5633
|
if (!result.success) {
|
|
@@ -5643,7 +5649,7 @@ class IdentityRenderer {
|
|
|
5643
5649
|
case 'passkey': {
|
|
5644
5650
|
this.setState({
|
|
5645
5651
|
view: 'passkey',
|
|
5646
|
-
|
|
5652
|
+
recipient: this.recipient,
|
|
5647
5653
|
mode: 'verify',
|
|
5648
5654
|
});
|
|
5649
5655
|
break;
|
|
@@ -5658,8 +5664,7 @@ class IdentityRenderer {
|
|
|
5658
5664
|
// CSP blocking WebSocket - provide developer-friendly error
|
|
5659
5665
|
this.setState({
|
|
5660
5666
|
view: 'error',
|
|
5661
|
-
|
|
5662
|
-
code: 'sparklink_csp_blocked',
|
|
5667
|
+
...SPARKLINK_CSP_BLOCKED_ERROR,
|
|
5663
5668
|
});
|
|
5664
5669
|
}
|
|
5665
5670
|
else {
|
|
@@ -5717,7 +5722,7 @@ class IdentityRenderer {
|
|
|
5717
5722
|
if (!result.result.redirect && await this.shouldShowPasskeyPrompt()) {
|
|
5718
5723
|
this.setState({
|
|
5719
5724
|
view: 'passkey-prompt',
|
|
5720
|
-
|
|
5725
|
+
recipient: this.recipient,
|
|
5721
5726
|
pendingResult: result.result,
|
|
5722
5727
|
});
|
|
5723
5728
|
return;
|
|
@@ -5819,7 +5824,7 @@ class IdentityRenderer {
|
|
|
5819
5824
|
if (result.errorType === 'not_found') {
|
|
5820
5825
|
this.setState({
|
|
5821
5826
|
view: 'passkey',
|
|
5822
|
-
|
|
5827
|
+
recipient: this.recipient,
|
|
5823
5828
|
mode: 'register',
|
|
5824
5829
|
error: result.error,
|
|
5825
5830
|
});
|
|
@@ -5827,7 +5832,7 @@ class IdentityRenderer {
|
|
|
5827
5832
|
else {
|
|
5828
5833
|
this.setState({
|
|
5829
5834
|
view: 'passkey',
|
|
5830
|
-
|
|
5835
|
+
recipient: this.recipient,
|
|
5831
5836
|
mode: currentMode,
|
|
5832
5837
|
error: result.error,
|
|
5833
5838
|
});
|
|
@@ -5835,13 +5840,28 @@ class IdentityRenderer {
|
|
|
5835
5840
|
}
|
|
5836
5841
|
}
|
|
5837
5842
|
/**
|
|
5838
|
-
* Handle fallback from passkey to
|
|
5839
|
-
* User clicked "Having trouble? Use
|
|
5843
|
+
* Handle fallback from passkey to an identifier-based code.
|
|
5844
|
+
* User clicked "Having trouble? Use a code instead".
|
|
5840
5845
|
*/
|
|
5841
5846
|
async handlePasskeyFallback() {
|
|
5842
5847
|
this.verificationState.enablePasskeyFallback();
|
|
5843
5848
|
await this.showMethodSelect();
|
|
5844
5849
|
}
|
|
5850
|
+
passkeyFallbackMethodsAvailable() {
|
|
5851
|
+
if (!this.sdkConfig)
|
|
5852
|
+
return false;
|
|
5853
|
+
const methods = enrichMethods(this.sdkConfig.methods ?? []);
|
|
5854
|
+
if (!this.recipient) {
|
|
5855
|
+
return methods.some((m) => m.type === 'social');
|
|
5856
|
+
}
|
|
5857
|
+
return methods.some((m) => {
|
|
5858
|
+
if (m.type === 'passkey')
|
|
5859
|
+
return false;
|
|
5860
|
+
if (this.identityType === 'phone')
|
|
5861
|
+
return m.identityType === 'phone';
|
|
5862
|
+
return m.identityType === 'email';
|
|
5863
|
+
});
|
|
5864
|
+
}
|
|
5845
5865
|
/**
|
|
5846
5866
|
* Handle skipping passkey registration when coming from passkey prompt.
|
|
5847
5867
|
* User clicked "Back" or cancelled registration after being prompted.
|
|
@@ -5919,7 +5939,7 @@ class IdentityRenderer {
|
|
|
5919
5939
|
const { passkey } = this.verificationState;
|
|
5920
5940
|
if (passkey.hasPasskey === null) {
|
|
5921
5941
|
const checkResult = await this.passkeyHandler.checkPasskey();
|
|
5922
|
-
// Only prompt if
|
|
5942
|
+
// Only prompt if the verified identifier resolves to an SVID without a passkey.
|
|
5923
5943
|
return checkResult !== null && checkResult.emailValid && !checkResult.hasPasskey;
|
|
5924
5944
|
}
|
|
5925
5945
|
return !passkey.hasPasskey;
|
|
@@ -5947,7 +5967,7 @@ class IdentityRenderer {
|
|
|
5947
5967
|
// User cancelled browser dialog - go back to prompt so they can skip or try again
|
|
5948
5968
|
this.setState({
|
|
5949
5969
|
view: 'passkey-prompt',
|
|
5950
|
-
|
|
5970
|
+
recipient: this.recipient,
|
|
5951
5971
|
pendingResult,
|
|
5952
5972
|
});
|
|
5953
5973
|
}
|
|
@@ -5956,7 +5976,7 @@ class IdentityRenderer {
|
|
|
5956
5976
|
const errorMessage = result.error || 'Failed to create passkey. Please try again.';
|
|
5957
5977
|
this.setState({
|
|
5958
5978
|
view: 'passkey-prompt',
|
|
5959
|
-
|
|
5979
|
+
recipient: this.recipient,
|
|
5960
5980
|
pendingResult,
|
|
5961
5981
|
error: errorMessage,
|
|
5962
5982
|
});
|
|
@@ -6081,6 +6101,9 @@ class IdentityRenderer {
|
|
|
6081
6101
|
token: data.token,
|
|
6082
6102
|
identity: data.identity,
|
|
6083
6103
|
identityType: data.identityType || 'email',
|
|
6104
|
+
svid: typeof data.svid === 'string' ? data.svid : undefined,
|
|
6105
|
+
sessionId: typeof data.session_id === 'string' ? data.session_id : undefined,
|
|
6106
|
+
refreshToken: typeof data.refresh_token === 'string' ? data.refresh_token : undefined,
|
|
6084
6107
|
// For simple-mode flows the server also emits a signed
|
|
6085
6108
|
// success-callback URL; without it the SDK has nowhere to send
|
|
6086
6109
|
// the user after WebSocket success.
|
|
@@ -6127,7 +6150,7 @@ class IdentityRenderer {
|
|
|
6127
6150
|
if (!result.redirect && await this.shouldShowPasskeyPrompt()) {
|
|
6128
6151
|
this.setState({
|
|
6129
6152
|
view: 'passkey-prompt',
|
|
6130
|
-
|
|
6153
|
+
recipient: this.recipient,
|
|
6131
6154
|
pendingResult: result,
|
|
6132
6155
|
});
|
|
6133
6156
|
return;
|
|
@@ -6167,8 +6190,7 @@ class IdentityRenderer {
|
|
|
6167
6190
|
if (wsResult.error === 'csp') {
|
|
6168
6191
|
this.setState({
|
|
6169
6192
|
view: 'error',
|
|
6170
|
-
|
|
6171
|
-
code: 'sparklink_csp_blocked',
|
|
6193
|
+
...SPARKLINK_CSP_BLOCKED_ERROR,
|
|
6172
6194
|
});
|
|
6173
6195
|
}
|
|
6174
6196
|
else {
|
|
@@ -6520,6 +6542,11 @@ class IdentityModule {
|
|
|
6520
6542
|
* });
|
|
6521
6543
|
*/
|
|
6522
6544
|
async verify(options = {}) {
|
|
6545
|
+
const redirectResult = await this.consumeRedirectResult();
|
|
6546
|
+
if (redirectResult) {
|
|
6547
|
+
options.onSuccess?.(redirectResult);
|
|
6548
|
+
return redirectResult;
|
|
6549
|
+
}
|
|
6523
6550
|
if (this.renderer) {
|
|
6524
6551
|
this.renderer.close();
|
|
6525
6552
|
}
|
|
@@ -6631,8 +6658,19 @@ class IdentityModule {
|
|
|
6631
6658
|
observer?.observe(document.body, { childList: true, subtree: true });
|
|
6632
6659
|
});
|
|
6633
6660
|
};
|
|
6634
|
-
// Defer attachment until DOM is ready
|
|
6635
|
-
|
|
6661
|
+
// Defer attachment until DOM is ready, then complete any full-page
|
|
6662
|
+
// social-login redirect result before the user has to click again.
|
|
6663
|
+
onDomReady(() => {
|
|
6664
|
+
attachToElements();
|
|
6665
|
+
this.consumeRedirectResult()
|
|
6666
|
+
.then((result) => {
|
|
6667
|
+
if (result)
|
|
6668
|
+
options.onSuccess?.(result);
|
|
6669
|
+
})
|
|
6670
|
+
.catch((error) => {
|
|
6671
|
+
options.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
6672
|
+
});
|
|
6673
|
+
});
|
|
6636
6674
|
// Return cleanup function
|
|
6637
6675
|
return () => {
|
|
6638
6676
|
observer?.disconnect();
|
|
@@ -6670,6 +6708,34 @@ class IdentityModule {
|
|
|
6670
6708
|
}
|
|
6671
6709
|
return payload;
|
|
6672
6710
|
}
|
|
6711
|
+
/**
|
|
6712
|
+
* Complete full-page redirect results produced by social-login flows.
|
|
6713
|
+
* The Identity Product redirects back with `#token=...` so the token does
|
|
6714
|
+
* not hit server logs. Consume it once, validate the issuer/expiry shape,
|
|
6715
|
+
* then remove it from the URL bar.
|
|
6716
|
+
*/
|
|
6717
|
+
async consumeRedirectResult() {
|
|
6718
|
+
if (typeof window === 'undefined' || !window.location.hash) {
|
|
6719
|
+
return null;
|
|
6720
|
+
}
|
|
6721
|
+
const params = new URLSearchParams(window.location.hash.slice(1));
|
|
6722
|
+
const token = params.get('token');
|
|
6723
|
+
if (!token) {
|
|
6724
|
+
return null;
|
|
6725
|
+
}
|
|
6726
|
+
const claims = await this.verifyToken(token);
|
|
6727
|
+
const result = {
|
|
6728
|
+
token,
|
|
6729
|
+
identity: claims.identity,
|
|
6730
|
+
identityType: claims.identity_type,
|
|
6731
|
+
svid: claims.svid,
|
|
6732
|
+
sessionId: claims.session_id,
|
|
6733
|
+
};
|
|
6734
|
+
if (typeof window.history?.replaceState === 'function') {
|
|
6735
|
+
window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
|
|
6736
|
+
}
|
|
6737
|
+
return result;
|
|
6738
|
+
}
|
|
6673
6739
|
/**
|
|
6674
6740
|
* Close the identity dialog/inline UI if open.
|
|
6675
6741
|
*/
|