@sparkvault/sdk-js 1.27.2 → 1.27.4
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/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 +228 -114
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +228 -114
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +2 -1
package/dist/sparkvault.cjs.js
CHANGED
|
@@ -65,14 +65,72 @@ class PopupBlockedError extends SparkVaultError {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* SparkVault-owned domain registry.
|
|
70
|
+
*
|
|
71
|
+
* Keep platform domain decisions centralized: CSP, redirect safety, custom
|
|
72
|
+
* domain reservation, and Identity postMessage trust all depend on the same
|
|
73
|
+
* ownership boundary.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
const SPARKVAULT_ROOT_DOMAIN = 'sparkvault.com';
|
|
77
|
+
|
|
78
|
+
const SPARKVAULT_PLATFORM_SV_HOSTS = Object.freeze([
|
|
79
|
+
'auth.sv',
|
|
80
|
+
'x.sv',
|
|
81
|
+
'files.sv',
|
|
82
|
+
'file.sv',
|
|
83
|
+
'send.sv',
|
|
84
|
+
'spark.sv',
|
|
85
|
+
'by.sv',
|
|
86
|
+
'at.sv',
|
|
87
|
+
'db.sv'
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
const SPARKVAULT_WEBSOCKET_HOSTS = Object.freeze([
|
|
91
|
+
'ws.sparkvault.com'
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
Object.freeze([
|
|
95
|
+
SPARKVAULT_ROOT_DOMAIN,
|
|
96
|
+
'app.sparkvault.com',
|
|
97
|
+
'api.sparkvault.com',
|
|
98
|
+
'cdn.sparkvault.com',
|
|
99
|
+
'forge.sparkvault.com',
|
|
100
|
+
'img.sparkvault.com',
|
|
101
|
+
...SPARKVAULT_WEBSOCKET_HOSTS,
|
|
102
|
+
...SPARKVAULT_PLATFORM_SV_HOSTS
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
function normalizeHostname(hostname) {
|
|
106
|
+
if (typeof hostname !== 'string') return '';
|
|
107
|
+
return hostname.trim().toLowerCase().replace(/\.$/, '');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function isSparkVaultRootOrSubdomain(hostname) {
|
|
111
|
+
const normalized = normalizeHostname(hostname);
|
|
112
|
+
return normalized === SPARKVAULT_ROOT_DOMAIN || normalized.endsWith(`.${SPARKVAULT_ROOT_DOMAIN}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function isSparkVaultPlatformSvHost(hostname) {
|
|
116
|
+
return SPARKVAULT_PLATFORM_SV_HOSTS.includes(normalizeHostname(hostname));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function isSparkVaultOwnedHostname(hostname) {
|
|
120
|
+
return isSparkVaultRootOrSubdomain(hostname) || isSparkVaultPlatformSvHost(hostname);
|
|
121
|
+
}
|
|
122
|
+
|
|
68
123
|
/**
|
|
69
124
|
* SparkVault SDK Configuration
|
|
70
125
|
*/
|
|
126
|
+
function escapeRegExp(value) {
|
|
127
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
128
|
+
}
|
|
129
|
+
const SPARKVAULT_PLATFORM_SV_DOWNLOAD_PATTERN = new RegExp(`(^|\\.)(${SPARKVAULT_PLATFORM_SV_HOSTS.map(escapeRegExp).join('|')})$`, 'i');
|
|
71
130
|
// Hosts that are allowed to serve backend-issued ingot download URLs.
|
|
72
|
-
// Keep in sync with the sdk-mobile default in packages/sdk-mobile/src/config.ts.
|
|
73
131
|
const DEFAULT_ALLOWED_DOWNLOAD_HOST_PATTERNS = [
|
|
74
|
-
|
|
75
|
-
|
|
132
|
+
new RegExp(`(^|\\.)${escapeRegExp(SPARKVAULT_ROOT_DOMAIN)}$`, 'i'),
|
|
133
|
+
SPARKVAULT_PLATFORM_SV_DOWNLOAD_PATTERN,
|
|
76
134
|
/\.amazonaws\.com$/i,
|
|
77
135
|
/\.cloudfront\.net$/i,
|
|
78
136
|
];
|
|
@@ -971,12 +1029,12 @@ class IdentityApi extends SparkVaultApi {
|
|
|
971
1029
|
return this.configCache !== null;
|
|
972
1030
|
}
|
|
973
1031
|
/**
|
|
974
|
-
* Check
|
|
1032
|
+
* Check whether the SVID resolved from an email or phone has registered passkeys.
|
|
975
1033
|
*
|
|
976
1034
|
* Returns:
|
|
977
1035
|
* - identity_valid: identity passes per-type validity check
|
|
978
1036
|
* (email: MX lookup; phone: E.164 format)
|
|
979
|
-
* - has_passkey: whether any passkeys are registered
|
|
1037
|
+
* - has_passkey: whether any passkeys are registered on the resolved SVID
|
|
980
1038
|
* (cross-tenant — single global RP)
|
|
981
1039
|
*/
|
|
982
1040
|
async checkPasskey(identity, identityType = 'email') {
|
|
@@ -1026,7 +1084,7 @@ class IdentityApi extends SparkVaultApi {
|
|
|
1026
1084
|
});
|
|
1027
1085
|
}
|
|
1028
1086
|
/**
|
|
1029
|
-
* Start passkey registration
|
|
1087
|
+
* Start passkey registration from a freshly verified identifier.
|
|
1030
1088
|
*/
|
|
1031
1089
|
async startPasskeyRegister(identity, identityType = 'email', registrationToken) {
|
|
1032
1090
|
const body = identityType === 'phone'
|
|
@@ -1064,19 +1122,19 @@ class IdentityApi extends SparkVaultApi {
|
|
|
1064
1122
|
});
|
|
1065
1123
|
}
|
|
1066
1124
|
/**
|
|
1067
|
-
* Start passkey verification
|
|
1125
|
+
* Start discoverable passkey verification. Legacy identity parameters are
|
|
1126
|
+
* intentionally ignored; the credential userHandle routes completion to the
|
|
1127
|
+
* SVID.
|
|
1068
1128
|
*/
|
|
1069
|
-
async startPasskeyVerify(
|
|
1070
|
-
const identityField = identityType === 'phone' ? { phone: identity } : { email: identity };
|
|
1129
|
+
async startPasskeyVerify(_identity, _identityType = 'email', authContext) {
|
|
1071
1130
|
// Backend returns { options: PublicKeyCredentialRequestOptions, session: {...} }
|
|
1072
1131
|
// Extract and flatten to match PasskeyChallengeResponse
|
|
1073
|
-
const response = await this.request('POST', '/passkey/verify',
|
|
1132
|
+
const response = await this.request('POST', '/passkey/verify', this.buildAuthContextParams(authContext));
|
|
1074
1133
|
return {
|
|
1075
1134
|
challenge: response.options.challenge,
|
|
1076
1135
|
rpId: response.options.rpId,
|
|
1077
1136
|
rpName: 'SparkVault Identity', // Not returned by verify endpoint
|
|
1078
1137
|
timeout: response.options.timeout,
|
|
1079
|
-
allowCredentials: response.options.allowCredentials,
|
|
1080
1138
|
session: response.session,
|
|
1081
1139
|
};
|
|
1082
1140
|
}
|
|
@@ -1172,7 +1230,6 @@ const METHOD_REGISTRY = {
|
|
|
1172
1230
|
passkey: {
|
|
1173
1231
|
id: 'passkey',
|
|
1174
1232
|
type: 'passkey',
|
|
1175
|
-
identityType: 'email',
|
|
1176
1233
|
name: 'Passkey',
|
|
1177
1234
|
description: 'Use biometrics or security key',
|
|
1178
1235
|
icon: 'passkey',
|
|
@@ -1317,19 +1374,20 @@ class VerificationState {
|
|
|
1317
1374
|
return this._sdkConfig?.accountId ?? '';
|
|
1318
1375
|
}
|
|
1319
1376
|
/**
|
|
1320
|
-
* Get enriched methods filtered by
|
|
1377
|
+
* Get enriched methods filtered by the fallback identifier type.
|
|
1321
1378
|
*/
|
|
1322
1379
|
getAvailableMethods() {
|
|
1323
1380
|
if (!this._sdkConfig)
|
|
1324
1381
|
return [];
|
|
1325
1382
|
const methodIds = this._sdkConfig.methods ?? [];
|
|
1326
1383
|
let methods = enrichMethods(methodIds);
|
|
1327
|
-
// Filter by
|
|
1384
|
+
// Filter by identifier type. Passkeys are SVID-scoped and remain
|
|
1385
|
+
// available regardless of whether the fallback identifier is email or phone.
|
|
1328
1386
|
if (this._identityType === 'phone') {
|
|
1329
|
-
methods = methods.filter((m) => m.type === '
|
|
1387
|
+
methods = methods.filter((m) => m.type === 'passkey' || m.identityType === 'phone');
|
|
1330
1388
|
}
|
|
1331
1389
|
else {
|
|
1332
|
-
methods = methods.filter((m) => m.identityType === 'email');
|
|
1390
|
+
methods = methods.filter((m) => m.identityType === 'email' || m.identityType === undefined);
|
|
1333
1391
|
}
|
|
1334
1392
|
return methods;
|
|
1335
1393
|
}
|
|
@@ -1359,7 +1417,9 @@ class VerificationState {
|
|
|
1359
1417
|
this._identityType = type;
|
|
1360
1418
|
}
|
|
1361
1419
|
getAllowedIdentityTypes() {
|
|
1362
|
-
|
|
1420
|
+
if (!this._sdkConfig)
|
|
1421
|
+
return ['email'];
|
|
1422
|
+
const allowed = this._sdkConfig.allowedIdentityTypes ?? ['email'];
|
|
1363
1423
|
return allowed;
|
|
1364
1424
|
}
|
|
1365
1425
|
// --- Auth Context (OIDC/simple mode) ---
|
|
@@ -1384,11 +1444,9 @@ class VerificationState {
|
|
|
1384
1444
|
}
|
|
1385
1445
|
/**
|
|
1386
1446
|
* Check if we should show passkey registration prompt
|
|
1387
|
-
* Based on: passkey enabled,
|
|
1447
|
+
* Based on: passkey enabled, the current SVID doesn't have one, not dismissed
|
|
1388
1448
|
*/
|
|
1389
1449
|
shouldShowPasskeyPrompt() {
|
|
1390
|
-
if (this._identityType !== 'email')
|
|
1391
|
-
return false;
|
|
1392
1450
|
if (!this.isPasskeyEnabled())
|
|
1393
1451
|
return false;
|
|
1394
1452
|
if (this.isPasskeyPromptDismissed())
|
|
@@ -1472,7 +1530,7 @@ class PasskeyHandler {
|
|
|
1472
1530
|
this.accountId = config.accountId;
|
|
1473
1531
|
}
|
|
1474
1532
|
/**
|
|
1475
|
-
* Check if
|
|
1533
|
+
* Check if the current identifier resolves to an SVID with registered passkeys.
|
|
1476
1534
|
* @returns Check result with emailValid and hasPasskey, or null on error
|
|
1477
1535
|
*/
|
|
1478
1536
|
async checkPasskey() {
|
|
@@ -1512,14 +1570,17 @@ class PasskeyHandler {
|
|
|
1512
1570
|
*/
|
|
1513
1571
|
async openPasskeyPopup(mode, registrationToken) {
|
|
1514
1572
|
return new Promise((resolve) => {
|
|
1515
|
-
//
|
|
1516
|
-
//
|
|
1573
|
+
// Registration carries the freshly verified identifier so the backend
|
|
1574
|
+
// can attach the credential to that SVID. Verification is discoverable:
|
|
1575
|
+
// the credential userHandle routes completion to the SVID.
|
|
1517
1576
|
const params = new URLSearchParams({
|
|
1518
1577
|
mode,
|
|
1519
1578
|
origin: window.location.origin,
|
|
1520
1579
|
});
|
|
1521
|
-
|
|
1522
|
-
|
|
1580
|
+
if (mode === 'register' && this.state.recipient) {
|
|
1581
|
+
const identityParam = this.state.identityType === 'phone' ? 'phone' : 'email';
|
|
1582
|
+
params.set(identityParam, this.state.recipient);
|
|
1583
|
+
}
|
|
1523
1584
|
// Add auth context for OIDC/simple mode flows
|
|
1524
1585
|
const authContext = this.state.authContext;
|
|
1525
1586
|
if (authContext?.authRequestId) {
|
|
@@ -1576,6 +1637,9 @@ class PasskeyHandler {
|
|
|
1576
1637
|
token: data.data.token || '',
|
|
1577
1638
|
identity: data.data.identity || this.state.recipient,
|
|
1578
1639
|
identityType: data.data.identity_type || 'email',
|
|
1640
|
+
svid: data.data.svid,
|
|
1641
|
+
sessionId: data.data.session_id,
|
|
1642
|
+
refreshToken: data.data.refresh_token,
|
|
1579
1643
|
redirect: data.data.redirect,
|
|
1580
1644
|
},
|
|
1581
1645
|
});
|
|
@@ -1618,12 +1682,7 @@ class PasskeyHandler {
|
|
|
1618
1682
|
isValidMessageOrigin(origin) {
|
|
1619
1683
|
try {
|
|
1620
1684
|
const url = new URL(origin);
|
|
1621
|
-
|
|
1622
|
-
// Allow sparkvault.com and subdomains
|
|
1623
|
-
if (hostname === 'sparkvault.com' || hostname.endsWith('.sparkvault.com')) {
|
|
1624
|
-
return true;
|
|
1625
|
-
}
|
|
1626
|
-
return false;
|
|
1685
|
+
return url.protocol === 'https:' && url.origin === origin && !url.port && isSparkVaultOwnedHostname(url.hostname);
|
|
1627
1686
|
}
|
|
1628
1687
|
catch {
|
|
1629
1688
|
return false;
|
|
@@ -1679,7 +1738,7 @@ class TotpHandler {
|
|
|
1679
1738
|
this.state = state;
|
|
1680
1739
|
}
|
|
1681
1740
|
/**
|
|
1682
|
-
* Send TOTP code via email or
|
|
1741
|
+
* Send TOTP code via email, SMS, or voice
|
|
1683
1742
|
*/
|
|
1684
1743
|
async send(method) {
|
|
1685
1744
|
try {
|
|
@@ -1763,6 +1822,9 @@ class TotpHandler {
|
|
|
1763
1822
|
token: response.token,
|
|
1764
1823
|
identity: response.identity ?? this.state.recipient,
|
|
1765
1824
|
identityType: response.identity_type ?? this.state.identityType,
|
|
1825
|
+
svid: response.svid,
|
|
1826
|
+
sessionId: response.session_id,
|
|
1827
|
+
refreshToken: response.refresh_token,
|
|
1766
1828
|
redirect: response.redirect,
|
|
1767
1829
|
},
|
|
1768
1830
|
};
|
|
@@ -4103,26 +4165,33 @@ class MethodSelectView {
|
|
|
4103
4165
|
this.methodClickHandlers = new Map();
|
|
4104
4166
|
this.props = props;
|
|
4105
4167
|
// Bind handlers once for proper removal
|
|
4106
|
-
this.boundHandleBack = () => this.props.onBack();
|
|
4168
|
+
this.boundHandleBack = () => this.props.onBack?.();
|
|
4107
4169
|
}
|
|
4108
4170
|
render() {
|
|
4109
4171
|
const container = div();
|
|
4110
|
-
this.backLink = this.createBackLink();
|
|
4172
|
+
this.backLink = this.props.onBack ? this.createBackLink() : null;
|
|
4111
4173
|
const title = document.createElement('h3');
|
|
4112
4174
|
title.className = 'sv-title';
|
|
4113
4175
|
title.textContent = 'Choose how to sign in';
|
|
4114
|
-
const
|
|
4115
|
-
subtitle
|
|
4116
|
-
subtitle
|
|
4176
|
+
const email = this.props.email;
|
|
4177
|
+
const subtitle = email ? document.createElement('p') : null;
|
|
4178
|
+
if (subtitle && email) {
|
|
4179
|
+
subtitle.className = 'sv-subtitle';
|
|
4180
|
+
subtitle.textContent = escapeHtml(email);
|
|
4181
|
+
}
|
|
4117
4182
|
const methodsContainer = div();
|
|
4118
4183
|
for (const method of this.props.methods) {
|
|
4119
4184
|
const methodButton = this.createMethodButton(method);
|
|
4120
4185
|
this.methodButtons.push(methodButton);
|
|
4121
4186
|
methodsContainer.appendChild(methodButton);
|
|
4122
4187
|
}
|
|
4123
|
-
|
|
4188
|
+
if (this.backLink) {
|
|
4189
|
+
container.appendChild(this.backLink);
|
|
4190
|
+
}
|
|
4124
4191
|
container.appendChild(title);
|
|
4125
|
-
|
|
4192
|
+
if (subtitle) {
|
|
4193
|
+
container.appendChild(subtitle);
|
|
4194
|
+
}
|
|
4126
4195
|
container.appendChild(methodsContainer);
|
|
4127
4196
|
return container;
|
|
4128
4197
|
}
|
|
@@ -4183,7 +4252,7 @@ class MethodSelectView {
|
|
|
4183
4252
|
/**
|
|
4184
4253
|
* TOTP Verification View
|
|
4185
4254
|
*
|
|
4186
|
-
* Collects and validates the 6-digit TOTP code sent via email or
|
|
4255
|
+
* Collects and validates the 6-digit TOTP code sent via email, SMS, or voice.
|
|
4187
4256
|
*/
|
|
4188
4257
|
const CODE_LENGTH = 6;
|
|
4189
4258
|
class TotpVerifyView {
|
|
@@ -4507,13 +4576,13 @@ class PasskeyView {
|
|
|
4507
4576
|
this.fallbackLink = null;
|
|
4508
4577
|
this.props = props;
|
|
4509
4578
|
// Bind handlers once for proper removal
|
|
4510
|
-
this.boundHandleBack = () => this.props.onBack();
|
|
4579
|
+
this.boundHandleBack = () => this.props.onBack?.();
|
|
4511
4580
|
this.boundHandleStart = () => this.handleStart();
|
|
4512
4581
|
this.boundHandleFallback = props.onFallback ? () => props.onFallback() : null;
|
|
4513
4582
|
}
|
|
4514
4583
|
render() {
|
|
4515
4584
|
const container = div();
|
|
4516
|
-
this.backLink = this.createBackLink();
|
|
4585
|
+
this.backLink = this.props.onBack ? this.createBackLink() : null;
|
|
4517
4586
|
const iconContainer = div();
|
|
4518
4587
|
iconContainer.appendChild(createPasskeyIcon());
|
|
4519
4588
|
const title = document.createElement('h3');
|
|
@@ -4522,10 +4591,10 @@ class PasskeyView {
|
|
|
4522
4591
|
const subtitle = document.createElement('p');
|
|
4523
4592
|
subtitle.className = 'sv-subtitle';
|
|
4524
4593
|
if (this.props.mode === 'register') {
|
|
4525
|
-
subtitle.innerHTML = `Create a passkey for<br><strong>${escapeHtml(this.props.
|
|
4594
|
+
subtitle.innerHTML = `Create a passkey for<br><strong>${escapeHtml(this.props.identityLabel)}</strong><br>to sign in faster next time`;
|
|
4526
4595
|
}
|
|
4527
4596
|
else {
|
|
4528
|
-
subtitle.innerHTML =
|
|
4597
|
+
subtitle.innerHTML = 'Use a passkey linked to your SparkVault Identity';
|
|
4529
4598
|
}
|
|
4530
4599
|
this.errorContainer = div();
|
|
4531
4600
|
if (this.props.error) {
|
|
@@ -4542,7 +4611,9 @@ class PasskeyView {
|
|
|
4542
4611
|
this.actionButton.className = 'sv-btn sv-btn-primary';
|
|
4543
4612
|
this.actionButton.textContent = buttonText;
|
|
4544
4613
|
this.actionButton.addEventListener('click', this.boundHandleStart);
|
|
4545
|
-
|
|
4614
|
+
if (this.backLink) {
|
|
4615
|
+
container.appendChild(this.backLink);
|
|
4616
|
+
}
|
|
4546
4617
|
container.appendChild(iconContainer);
|
|
4547
4618
|
container.appendChild(title);
|
|
4548
4619
|
container.appendChild(subtitle);
|
|
@@ -4558,7 +4629,7 @@ class PasskeyView {
|
|
|
4558
4629
|
createFallbackLink() {
|
|
4559
4630
|
const link = document.createElement('button');
|
|
4560
4631
|
link.className = 'sv-fallback-link';
|
|
4561
|
-
link.textContent = 'Having trouble? Use
|
|
4632
|
+
link.textContent = 'Having trouble? Use a code instead';
|
|
4562
4633
|
if (this.boundHandleFallback) {
|
|
4563
4634
|
link.addEventListener('click', this.boundHandleFallback);
|
|
4564
4635
|
}
|
|
@@ -4631,7 +4702,7 @@ class PasskeyPromptView {
|
|
|
4631
4702
|
title.textContent = 'Add a passkey for faster sign-in?';
|
|
4632
4703
|
const subtitle = document.createElement('p');
|
|
4633
4704
|
subtitle.className = 'sv-subtitle';
|
|
4634
|
-
subtitle.innerHTML = `Next time, sign in instantly as<br><strong>${escapeHtml(this.props.
|
|
4705
|
+
subtitle.innerHTML = `Next time, sign in instantly as<br><strong>${escapeHtml(this.props.identityLabel)}</strong>`;
|
|
4635
4706
|
// Error message if registration failed
|
|
4636
4707
|
const errorContainer = div();
|
|
4637
4708
|
if (this.props.error) {
|
|
@@ -5324,13 +5395,7 @@ class IdentityRenderer {
|
|
|
5324
5395
|
? config.branding.backdrop_blur
|
|
5325
5396
|
: true;
|
|
5326
5397
|
this.container.updateBackdropBlur(resolvedBackdropBlur);
|
|
5327
|
-
|
|
5328
|
-
if (this.recipient) {
|
|
5329
|
-
this.showMethodSelect();
|
|
5330
|
-
}
|
|
5331
|
-
else {
|
|
5332
|
-
this.showIdentityInput();
|
|
5333
|
-
}
|
|
5398
|
+
await this.showInitialAuthStep();
|
|
5334
5399
|
}
|
|
5335
5400
|
catch (error) {
|
|
5336
5401
|
this.setState(this.viewStateForConfigError(error));
|
|
@@ -5387,12 +5452,7 @@ class IdentityRenderer {
|
|
|
5387
5452
|
? config.branding.backdrop_blur
|
|
5388
5453
|
: true;
|
|
5389
5454
|
this.container.updateBackdropBlur(resolvedBackdropBlur);
|
|
5390
|
-
|
|
5391
|
-
this.showMethodSelect();
|
|
5392
|
-
}
|
|
5393
|
-
else {
|
|
5394
|
-
this.showIdentityInput();
|
|
5395
|
-
}
|
|
5455
|
+
await this.showInitialAuthStep();
|
|
5396
5456
|
}
|
|
5397
5457
|
catch (error) {
|
|
5398
5458
|
this.setState(this.viewStateForConfigError(error));
|
|
@@ -5424,6 +5484,13 @@ class IdentityRenderer {
|
|
|
5424
5484
|
this.verificationState.setViewState(state);
|
|
5425
5485
|
this.render();
|
|
5426
5486
|
}
|
|
5487
|
+
async showInitialAuthStep() {
|
|
5488
|
+
if (this.recipient || this.getAllowedIdentityTypes().length === 0) {
|
|
5489
|
+
await this.showMethodSelect();
|
|
5490
|
+
return;
|
|
5491
|
+
}
|
|
5492
|
+
this.showIdentityInput();
|
|
5493
|
+
}
|
|
5427
5494
|
render() {
|
|
5428
5495
|
const body = this.container.getBody();
|
|
5429
5496
|
if (!body)
|
|
@@ -5472,7 +5539,7 @@ class IdentityRenderer {
|
|
|
5472
5539
|
email: state.email,
|
|
5473
5540
|
methods: state.methods,
|
|
5474
5541
|
onSelectMethod: (method) => this.handleMethodSelect(method),
|
|
5475
|
-
onBack: () => this.showIdentityInput(),
|
|
5542
|
+
onBack: state.email ? () => this.showIdentityInput() : undefined,
|
|
5476
5543
|
});
|
|
5477
5544
|
case 'totp-verify':
|
|
5478
5545
|
return new TotpVerifyView({
|
|
@@ -5489,7 +5556,7 @@ class IdentityRenderer {
|
|
|
5489
5556
|
const { passkey } = this.verificationState;
|
|
5490
5557
|
const isFromPrompt = state.mode === 'register' && passkey.pendingResult !== null;
|
|
5491
5558
|
return new PasskeyView({
|
|
5492
|
-
|
|
5559
|
+
identityLabel: state.recipient,
|
|
5493
5560
|
mode: state.mode,
|
|
5494
5561
|
error: state.error,
|
|
5495
5562
|
onStart: () => this.handlePasskeyStart(),
|
|
@@ -5497,7 +5564,11 @@ class IdentityRenderer {
|
|
|
5497
5564
|
? () => this.handlePasskeyRegistrationSkip()
|
|
5498
5565
|
: state.mode === 'verify'
|
|
5499
5566
|
// From passkey verify, enable fallback so showMethodSelect doesn't loop back
|
|
5500
|
-
?
|
|
5567
|
+
? this.passkeyFallbackMethodsAvailable()
|
|
5568
|
+
? () => this.handlePasskeyFallback()
|
|
5569
|
+
: this.recipient
|
|
5570
|
+
? () => this.showIdentityInput()
|
|
5571
|
+
: undefined
|
|
5501
5572
|
: () => this.showMethodSelect(),
|
|
5502
5573
|
onFallback: passkey.hasPasskey && !passkey.isFallbackMode
|
|
5503
5574
|
? () => this.handlePasskeyFallback()
|
|
@@ -5506,7 +5577,7 @@ class IdentityRenderer {
|
|
|
5506
5577
|
}
|
|
5507
5578
|
case 'passkey-prompt':
|
|
5508
5579
|
return new PasskeyPromptView({
|
|
5509
|
-
|
|
5580
|
+
identityLabel: state.recipient,
|
|
5510
5581
|
onAddPasskey: () => this.handlePasskeyPromptAdd(state.pendingResult),
|
|
5511
5582
|
onSkip: () => this.handlePasskeyPromptSkip(state.pendingResult),
|
|
5512
5583
|
error: state.error,
|
|
@@ -5558,45 +5629,22 @@ class IdentityRenderer {
|
|
|
5558
5629
|
}
|
|
5559
5630
|
// Enrich method IDs with metadata from static registry
|
|
5560
5631
|
let methods = enrichMethods(methodIds);
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5567
|
-
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
if (methods.length === 0) {
|
|
5571
|
-
this.setState({
|
|
5572
|
-
view: 'error',
|
|
5573
|
-
message: 'No authentication methods available',
|
|
5574
|
-
code: 'no_methods',
|
|
5632
|
+
if (this.recipient) {
|
|
5633
|
+
// Filter by identifier type. Passkeys are SVID-scoped, so they remain
|
|
5634
|
+
// available regardless of whether the fallback identifier is email or phone.
|
|
5635
|
+
methods = methods.filter((m) => {
|
|
5636
|
+
if (this.identityType === 'phone') {
|
|
5637
|
+
return m.type === 'passkey' || m.identityType === 'phone';
|
|
5638
|
+
}
|
|
5639
|
+
// Email users can use email-based methods
|
|
5640
|
+
return m.identityType === 'email' || m.identityType === undefined;
|
|
5575
5641
|
});
|
|
5576
|
-
return;
|
|
5577
5642
|
}
|
|
5578
|
-
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
// Use passkey handler for the check (also validates email domain)
|
|
5584
|
-
const checkResult = await this.passkeyHandler.checkPasskey();
|
|
5585
|
-
// Handle invalid email domain
|
|
5586
|
-
if (checkResult !== null && !checkResult.emailValid) {
|
|
5587
|
-
this.showIdentityInput('This email domain cannot receive messages. Please check your email address.');
|
|
5588
|
-
return;
|
|
5589
|
-
}
|
|
5590
|
-
if (checkResult?.hasPasskey === true) {
|
|
5591
|
-
// User has passkey - go straight to passkey verification
|
|
5592
|
-
this.setState({
|
|
5593
|
-
view: 'passkey',
|
|
5594
|
-
email: this.recipient,
|
|
5595
|
-
mode: 'verify',
|
|
5596
|
-
});
|
|
5597
|
-
return;
|
|
5598
|
-
}
|
|
5599
|
-
// User doesn't have passkey - filter out passkey option
|
|
5643
|
+
else {
|
|
5644
|
+
// No PII prompt is needed when only SVID-routed methods are enabled.
|
|
5645
|
+
methods = methods.filter((m) => m.type === 'passkey' || m.type === 'social');
|
|
5646
|
+
}
|
|
5647
|
+
if (this.verificationState.passkey.isFallbackMode) {
|
|
5600
5648
|
methods = methods.filter((m) => m.type !== 'passkey');
|
|
5601
5649
|
}
|
|
5602
5650
|
if (methods.length === 0) {
|
|
@@ -5628,7 +5676,11 @@ class IdentityRenderer {
|
|
|
5628
5676
|
try {
|
|
5629
5677
|
switch (method.type) {
|
|
5630
5678
|
case 'totp': {
|
|
5631
|
-
const totpMethod = method.id === 'totp_sms'
|
|
5679
|
+
const totpMethod = method.id === 'totp_sms'
|
|
5680
|
+
? 'sms'
|
|
5681
|
+
: method.id === 'totp_voice'
|
|
5682
|
+
? 'voice'
|
|
5683
|
+
: 'email';
|
|
5632
5684
|
this.setState({ view: 'loading' });
|
|
5633
5685
|
const result = await this.totpHandler.send(totpMethod);
|
|
5634
5686
|
if (!result.success) {
|
|
@@ -5650,7 +5702,7 @@ class IdentityRenderer {
|
|
|
5650
5702
|
case 'passkey': {
|
|
5651
5703
|
this.setState({
|
|
5652
5704
|
view: 'passkey',
|
|
5653
|
-
|
|
5705
|
+
recipient: this.recipient,
|
|
5654
5706
|
mode: 'verify',
|
|
5655
5707
|
});
|
|
5656
5708
|
break;
|
|
@@ -5723,7 +5775,7 @@ class IdentityRenderer {
|
|
|
5723
5775
|
if (!result.result.redirect && await this.shouldShowPasskeyPrompt()) {
|
|
5724
5776
|
this.setState({
|
|
5725
5777
|
view: 'passkey-prompt',
|
|
5726
|
-
|
|
5778
|
+
recipient: this.recipient,
|
|
5727
5779
|
pendingResult: result.result,
|
|
5728
5780
|
});
|
|
5729
5781
|
return;
|
|
@@ -5825,7 +5877,7 @@ class IdentityRenderer {
|
|
|
5825
5877
|
if (result.errorType === 'not_found') {
|
|
5826
5878
|
this.setState({
|
|
5827
5879
|
view: 'passkey',
|
|
5828
|
-
|
|
5880
|
+
recipient: this.recipient,
|
|
5829
5881
|
mode: 'register',
|
|
5830
5882
|
error: result.error,
|
|
5831
5883
|
});
|
|
@@ -5833,7 +5885,7 @@ class IdentityRenderer {
|
|
|
5833
5885
|
else {
|
|
5834
5886
|
this.setState({
|
|
5835
5887
|
view: 'passkey',
|
|
5836
|
-
|
|
5888
|
+
recipient: this.recipient,
|
|
5837
5889
|
mode: currentMode,
|
|
5838
5890
|
error: result.error,
|
|
5839
5891
|
});
|
|
@@ -5841,13 +5893,28 @@ class IdentityRenderer {
|
|
|
5841
5893
|
}
|
|
5842
5894
|
}
|
|
5843
5895
|
/**
|
|
5844
|
-
* Handle fallback from passkey to
|
|
5845
|
-
* User clicked "Having trouble? Use
|
|
5896
|
+
* Handle fallback from passkey to an identifier-based code.
|
|
5897
|
+
* User clicked "Having trouble? Use a code instead".
|
|
5846
5898
|
*/
|
|
5847
5899
|
async handlePasskeyFallback() {
|
|
5848
5900
|
this.verificationState.enablePasskeyFallback();
|
|
5849
5901
|
await this.showMethodSelect();
|
|
5850
5902
|
}
|
|
5903
|
+
passkeyFallbackMethodsAvailable() {
|
|
5904
|
+
if (!this.sdkConfig)
|
|
5905
|
+
return false;
|
|
5906
|
+
const methods = enrichMethods(this.sdkConfig.methods ?? []);
|
|
5907
|
+
if (!this.recipient) {
|
|
5908
|
+
return methods.some((m) => m.type === 'social');
|
|
5909
|
+
}
|
|
5910
|
+
return methods.some((m) => {
|
|
5911
|
+
if (m.type === 'passkey')
|
|
5912
|
+
return false;
|
|
5913
|
+
if (this.identityType === 'phone')
|
|
5914
|
+
return m.identityType === 'phone';
|
|
5915
|
+
return m.identityType === 'email';
|
|
5916
|
+
});
|
|
5917
|
+
}
|
|
5851
5918
|
/**
|
|
5852
5919
|
* Handle skipping passkey registration when coming from passkey prompt.
|
|
5853
5920
|
* User clicked "Back" or cancelled registration after being prompted.
|
|
@@ -5925,7 +5992,7 @@ class IdentityRenderer {
|
|
|
5925
5992
|
const { passkey } = this.verificationState;
|
|
5926
5993
|
if (passkey.hasPasskey === null) {
|
|
5927
5994
|
const checkResult = await this.passkeyHandler.checkPasskey();
|
|
5928
|
-
// Only prompt if
|
|
5995
|
+
// Only prompt if the verified identifier resolves to an SVID without a passkey.
|
|
5929
5996
|
return checkResult !== null && checkResult.emailValid && !checkResult.hasPasskey;
|
|
5930
5997
|
}
|
|
5931
5998
|
return !passkey.hasPasskey;
|
|
@@ -5953,7 +6020,7 @@ class IdentityRenderer {
|
|
|
5953
6020
|
// User cancelled browser dialog - go back to prompt so they can skip or try again
|
|
5954
6021
|
this.setState({
|
|
5955
6022
|
view: 'passkey-prompt',
|
|
5956
|
-
|
|
6023
|
+
recipient: this.recipient,
|
|
5957
6024
|
pendingResult,
|
|
5958
6025
|
});
|
|
5959
6026
|
}
|
|
@@ -5962,7 +6029,7 @@ class IdentityRenderer {
|
|
|
5962
6029
|
const errorMessage = result.error || 'Failed to create passkey. Please try again.';
|
|
5963
6030
|
this.setState({
|
|
5964
6031
|
view: 'passkey-prompt',
|
|
5965
|
-
|
|
6032
|
+
recipient: this.recipient,
|
|
5966
6033
|
pendingResult,
|
|
5967
6034
|
error: errorMessage,
|
|
5968
6035
|
});
|
|
@@ -6087,6 +6154,9 @@ class IdentityRenderer {
|
|
|
6087
6154
|
token: data.token,
|
|
6088
6155
|
identity: data.identity,
|
|
6089
6156
|
identityType: data.identityType || 'email',
|
|
6157
|
+
svid: typeof data.svid === 'string' ? data.svid : undefined,
|
|
6158
|
+
sessionId: typeof data.session_id === 'string' ? data.session_id : undefined,
|
|
6159
|
+
refreshToken: typeof data.refresh_token === 'string' ? data.refresh_token : undefined,
|
|
6090
6160
|
// For simple-mode flows the server also emits a signed
|
|
6091
6161
|
// success-callback URL; without it the SDK has nowhere to send
|
|
6092
6162
|
// the user after WebSocket success.
|
|
@@ -6133,7 +6203,7 @@ class IdentityRenderer {
|
|
|
6133
6203
|
if (!result.redirect && await this.shouldShowPasskeyPrompt()) {
|
|
6134
6204
|
this.setState({
|
|
6135
6205
|
view: 'passkey-prompt',
|
|
6136
|
-
|
|
6206
|
+
recipient: this.recipient,
|
|
6137
6207
|
pendingResult: result,
|
|
6138
6208
|
});
|
|
6139
6209
|
return;
|
|
@@ -6525,6 +6595,11 @@ class IdentityModule {
|
|
|
6525
6595
|
* });
|
|
6526
6596
|
*/
|
|
6527
6597
|
async verify(options = {}) {
|
|
6598
|
+
const redirectResult = await this.consumeRedirectResult();
|
|
6599
|
+
if (redirectResult) {
|
|
6600
|
+
options.onSuccess?.(redirectResult);
|
|
6601
|
+
return redirectResult;
|
|
6602
|
+
}
|
|
6528
6603
|
if (this.renderer) {
|
|
6529
6604
|
this.renderer.close();
|
|
6530
6605
|
}
|
|
@@ -6636,8 +6711,19 @@ class IdentityModule {
|
|
|
6636
6711
|
observer?.observe(document.body, { childList: true, subtree: true });
|
|
6637
6712
|
});
|
|
6638
6713
|
};
|
|
6639
|
-
// Defer attachment until DOM is ready
|
|
6640
|
-
|
|
6714
|
+
// Defer attachment until DOM is ready, then complete any full-page
|
|
6715
|
+
// social-login redirect result before the user has to click again.
|
|
6716
|
+
onDomReady(() => {
|
|
6717
|
+
attachToElements();
|
|
6718
|
+
this.consumeRedirectResult()
|
|
6719
|
+
.then((result) => {
|
|
6720
|
+
if (result)
|
|
6721
|
+
options.onSuccess?.(result);
|
|
6722
|
+
})
|
|
6723
|
+
.catch((error) => {
|
|
6724
|
+
options.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
6725
|
+
});
|
|
6726
|
+
});
|
|
6641
6727
|
// Return cleanup function
|
|
6642
6728
|
return () => {
|
|
6643
6729
|
observer?.disconnect();
|
|
@@ -6675,6 +6761,34 @@ class IdentityModule {
|
|
|
6675
6761
|
}
|
|
6676
6762
|
return payload;
|
|
6677
6763
|
}
|
|
6764
|
+
/**
|
|
6765
|
+
* Complete full-page redirect results produced by social-login flows.
|
|
6766
|
+
* The Identity Product redirects back with `#token=...` so the token does
|
|
6767
|
+
* not hit server logs. Consume it once, validate the issuer/expiry shape,
|
|
6768
|
+
* then remove it from the URL bar.
|
|
6769
|
+
*/
|
|
6770
|
+
async consumeRedirectResult() {
|
|
6771
|
+
if (typeof window === 'undefined' || !window.location.hash) {
|
|
6772
|
+
return null;
|
|
6773
|
+
}
|
|
6774
|
+
const params = new URLSearchParams(window.location.hash.slice(1));
|
|
6775
|
+
const token = params.get('token');
|
|
6776
|
+
if (!token) {
|
|
6777
|
+
return null;
|
|
6778
|
+
}
|
|
6779
|
+
const claims = await this.verifyToken(token);
|
|
6780
|
+
const result = {
|
|
6781
|
+
token,
|
|
6782
|
+
identity: claims.identity,
|
|
6783
|
+
identityType: claims.identity_type,
|
|
6784
|
+
svid: claims.svid,
|
|
6785
|
+
sessionId: claims.session_id,
|
|
6786
|
+
};
|
|
6787
|
+
if (typeof window.history?.replaceState === 'function') {
|
|
6788
|
+
window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
|
|
6789
|
+
}
|
|
6790
|
+
return result;
|
|
6791
|
+
}
|
|
6678
6792
|
/**
|
|
6679
6793
|
* Close the identity dialog/inline UI if open.
|
|
6680
6794
|
*/
|