@sparkvault/sdk-js 1.27.4 → 1.27.6

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 CHANGED
@@ -276,12 +276,12 @@ Authentication methods are configured in your Identity Product settings. The SDK
276
276
  | `totp_sms` | 6-digit code sent via SMS | Phone |
277
277
  | `totp_voice` | 6-digit code sent via voice call | Phone |
278
278
  | `sparklink` | One-click sign-in link via email | Email |
279
- | `social_google` | Sign in with Google | Email |
280
- | `social_apple` | Sign in with Apple | Email |
281
- | `social_microsoft` | Sign in with Microsoft | Email |
282
- | `social_github` | Sign in with GitHub | Email |
283
- | `social_facebook` | Sign in with Facebook | Email |
284
- | `social_linkedin` | Sign in with LinkedIn | Email |
279
+ | `social_google` | Sign in with Google | Social account |
280
+ | `social_apple` | Sign in with Apple | Social account |
281
+ | `social_microsoft` | Sign in with Microsoft | Social account |
282
+ | `social_github` | Sign in with GitHub | Social account |
283
+ | `social_facebook` | Sign in with Facebook | Social account |
284
+ | `social_linkedin` | Sign in with LinkedIn | Social account |
285
285
 
286
286
  ## Backend Token Verification
287
287
 
@@ -97,7 +97,7 @@ export declare class IdentityApi extends SparkVaultApi {
97
97
  /**
98
98
  * Get OAuth redirect URL for social provider
99
99
  */
100
- getSocialAuthUrl(provider: string, redirectUri: string, state: string): string;
100
+ getSocialAuthUrl(provider: string, redirectUri: string, state: string, authContext?: AuthContext): string;
101
101
  /**
102
102
  * Send SparkLink email for identity verification.
103
103
  * Includes connectionId for WebSocket push notification of verification result.
@@ -1164,11 +1164,24 @@ class IdentityApi extends SparkVaultApi {
1164
1164
  /**
1165
1165
  * Get OAuth redirect URL for social provider
1166
1166
  */
1167
- getSocialAuthUrl(provider, redirectUri, state) {
1167
+ getSocialAuthUrl(provider, redirectUri, state, authContext) {
1168
1168
  const params = new URLSearchParams({
1169
1169
  redirect_uri: redirectUri,
1170
1170
  state,
1171
1171
  });
1172
+ if (authContext?.authRequestId) {
1173
+ params.set('auth_request_id', authContext.authRequestId);
1174
+ }
1175
+ if (authContext?.simpleMode) {
1176
+ const simpleMode = authContext.simpleMode.sessionId
1177
+ ? { session_id: authContext.simpleMode.sessionId }
1178
+ : {
1179
+ success_url: authContext.simpleMode.successUrl,
1180
+ failure_url: authContext.simpleMode.failureUrl,
1181
+ state: authContext.simpleMode.state,
1182
+ };
1183
+ params.set('simple_mode', JSON.stringify(simpleMode));
1184
+ }
1172
1185
  return `${this.baseUrl}/social/${provider}?${params}`;
1173
1186
  }
1174
1187
  /**
@@ -5936,7 +5949,7 @@ class IdentityRenderer {
5936
5949
  const redirectUri = window.location.origin + window.location.pathname;
5937
5950
  sessionStorage.setItem('sv_oauth_state', state);
5938
5951
  sessionStorage.setItem('sv_oauth_email', this.recipient);
5939
- const authUrl = this.api.getSocialAuthUrl(provider, redirectUri, state);
5952
+ const authUrl = this.api.getSocialAuthUrl(provider, redirectUri, state, this.verificationState.authContext);
5940
5953
  window.location.href = authUrl;
5941
5954
  }
5942
5955
  normalizeError(error) {
@@ -6776,6 +6789,10 @@ class IdentityModule {
6776
6789
  if (!token) {
6777
6790
  return null;
6778
6791
  }
6792
+ const expectedState = sessionStorage.getItem('sv_oauth_state');
6793
+ if (expectedState && params.get('state') !== expectedState) {
6794
+ throw new ValidationError('Invalid OAuth state');
6795
+ }
6779
6796
  const claims = await this.verifyToken(token);
6780
6797
  const result = {
6781
6798
  token,
@@ -6787,6 +6804,8 @@ class IdentityModule {
6787
6804
  if (typeof window.history?.replaceState === 'function') {
6788
6805
  window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
6789
6806
  }
6807
+ sessionStorage.removeItem('sv_oauth_state');
6808
+ sessionStorage.removeItem('sv_oauth_email');
6790
6809
  return result;
6791
6810
  }
6792
6811
  /**