@sparkvault/sdk-js 2.1.1 → 2.1.2

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.
@@ -32,6 +32,12 @@ export declare class WidgetEmbedder {
32
32
  constructor(config: ResolvedConfig, options: VerifyOptions, callbacks: EmbedderCallbacks);
33
33
  start(): void;
34
34
  close(): void;
35
+ /**
36
+ * Begin a social-login redirect from the host. State and redirect_uri are
37
+ * the customer's top origin so `consumeRedirectResult` validates them on
38
+ * return. Mirrors the SDK's getSocialAuthUrl.
39
+ */
40
+ private startSocial;
35
41
  private buildUrl;
36
42
  private handleMessage;
37
43
  }
@@ -51,6 +51,12 @@ export interface VerifyOptions {
51
51
  * this hook instead of navigating the iframe. Omitted outside the iframe.
52
52
  */
53
53
  onNavigate?: (url: string) => void;
54
+ /**
55
+ * Social-login override (internal). When embedded, social must be started
56
+ * from the host so its OAuth state and redirect_uri live on the customer's
57
+ * top origin. The renderer hands the provider up instead of redirecting.
58
+ */
59
+ onSocial?: (provider: string) => void;
54
60
  /** Called when user cancels (if omitted, uses server-configured redirect) */
55
61
  onCancel?: () => void;
56
62
  /** Called when verification completes (if omitted, uses server-configured redirect) */
package/dist/index.d.ts CHANGED
@@ -116,6 +116,12 @@ interface VerifyOptions {
116
116
  * this hook instead of navigating the iframe. Omitted outside the iframe.
117
117
  */
118
118
  onNavigate?: (url: string) => void;
119
+ /**
120
+ * Social-login override (internal). When embedded, social must be started
121
+ * from the host so its OAuth state and redirect_uri live on the customer's
122
+ * top origin. The renderer hands the provider up instead of redirecting.
123
+ */
124
+ onSocial?: (provider: string) => void;
119
125
  /** Called when user cancels (if omitted, uses server-configured redirect) */
120
126
  onCancel?: () => void;
121
127
  /** Called when verification completes (if omitted, uses server-configured redirect) */
@@ -6526,6 +6526,13 @@ class IdentityRenderer {
6526
6526
  }
6527
6527
  handleSocialLogin(provider) {
6528
6528
  this.setState({ view: 'oauth-pending', provider });
6529
+ // When embedded, social must originate from the host: the OAuth state and
6530
+ // redirect_uri belong to the customer's top origin, not this iframe (whose
6531
+ // sessionStorage and URL the return would never match). Hand it up.
6532
+ if (this.options.onSocial) {
6533
+ this.options.onSocial(provider);
6534
+ return;
6535
+ }
6529
6536
  const state = generateState();
6530
6537
  const redirectUri = window.location.origin + window.location.pathname;
6531
6538
  sessionStorage.setItem('sv_oauth_state', state);
@@ -6908,8 +6915,10 @@ class IdentityRenderer {
6908
6915
  */
6909
6916
  /** Result envelope posted by the widget page. */
6910
6917
  const RESULT_TYPE = 'sparkvault-identity-result';
6911
- /** Top-window navigation request posted by the widget (social / OIDC). */
6918
+ /** Top-window navigation request posted by the widget (OIDC / generic). */
6912
6919
  const REDIRECT_TYPE = 'sparkvault-identity-redirect';
6920
+ /** Social-login start request posted by the widget. */
6921
+ const SOCIAL_TYPE = 'sparkvault-identity-social';
6913
6922
  class WidgetEmbedder {
6914
6923
  constructor(config, options, callbacks) {
6915
6924
  this.config = config;
@@ -6956,6 +6965,43 @@ class WidgetEmbedder {
6956
6965
  window.removeEventListener('message', this.boundHandleMessage);
6957
6966
  document.body.style.overflow = this.previousBodyOverflow;
6958
6967
  }
6968
+ /**
6969
+ * Begin a social-login redirect from the host. State and redirect_uri are
6970
+ * the customer's top origin so `consumeRedirectResult` validates them on
6971
+ * return. Mirrors the SDK's getSocialAuthUrl.
6972
+ */
6973
+ startSocial(provider) {
6974
+ // Provider comes from the trusted widget origin, but never build a URL from
6975
+ // an unexpected value.
6976
+ if (!/^[a-z0-9_]+$/i.test(provider))
6977
+ return;
6978
+ const state = generateState();
6979
+ try {
6980
+ sessionStorage.setItem('sv_oauth_state', state);
6981
+ }
6982
+ catch {
6983
+ // Storage disabled (private mode): proceed; the backend still binds state.
6984
+ }
6985
+ const url = new URL(`${this.config.identityBaseUrl}/${this.config.accountId}/social/${provider}`);
6986
+ url.searchParams.set('redirect_uri', window.location.origin + window.location.pathname);
6987
+ url.searchParams.set('state', state);
6988
+ const authContext = this.options.authContext;
6989
+ if (authContext?.authRequestId) {
6990
+ url.searchParams.set('auth_request_id', authContext.authRequestId);
6991
+ }
6992
+ if (authContext?.simpleMode) {
6993
+ const simpleMode = authContext.simpleMode.sessionId
6994
+ ? { session_id: authContext.simpleMode.sessionId }
6995
+ : {
6996
+ success_url: authContext.simpleMode.successUrl,
6997
+ failure_url: authContext.simpleMode.failureUrl,
6998
+ state: authContext.simpleMode.state,
6999
+ };
7000
+ url.searchParams.set('simple_mode', JSON.stringify(simpleMode));
7001
+ }
7002
+ this.close();
7003
+ window.location.href = url.toString();
7004
+ }
6959
7005
  buildUrl() {
6960
7006
  const url = new URL(`${this.config.identityBaseUrl}/${this.config.accountId}/widget`);
6961
7007
  url.searchParams.set('origin', window.location.origin);
@@ -6987,7 +7033,13 @@ class WidgetEmbedder {
6987
7033
  const data = event.data;
6988
7034
  if (!data || typeof data.type !== 'string')
6989
7035
  return;
6990
- // Social / OIDC redirect: the widget cannot navigate the top window from a
7036
+ // Social login: start it from the host so the OAuth state and redirect_uri
7037
+ // live on the customer's top origin (where the return is consumed).
7038
+ if (data.type === SOCIAL_TYPE && typeof data.provider === 'string') {
7039
+ this.startSocial(data.provider);
7040
+ return;
7041
+ }
7042
+ // OIDC / generic redirect: the widget cannot navigate the top window from a
6991
7043
  // cross-origin frame, so it asks us to. Navigating away tears down the
6992
7044
  // iframe; on return the host SDK consumes the redirect token.
6993
7045
  if (data.type === REDIRECT_TYPE && typeof data.url === 'string') {