@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.
@@ -6522,6 +6522,13 @@ class IdentityRenderer {
6522
6522
  }
6523
6523
  handleSocialLogin(provider) {
6524
6524
  this.setState({ view: 'oauth-pending', provider });
6525
+ // When embedded, social must originate from the host: the OAuth state and
6526
+ // redirect_uri belong to the customer's top origin, not this iframe (whose
6527
+ // sessionStorage and URL the return would never match). Hand it up.
6528
+ if (this.options.onSocial) {
6529
+ this.options.onSocial(provider);
6530
+ return;
6531
+ }
6525
6532
  const state = generateState();
6526
6533
  const redirectUri = window.location.origin + window.location.pathname;
6527
6534
  sessionStorage.setItem('sv_oauth_state', state);
@@ -6904,8 +6911,10 @@ class IdentityRenderer {
6904
6911
  */
6905
6912
  /** Result envelope posted by the widget page. */
6906
6913
  const RESULT_TYPE = 'sparkvault-identity-result';
6907
- /** Top-window navigation request posted by the widget (social / OIDC). */
6914
+ /** Top-window navigation request posted by the widget (OIDC / generic). */
6908
6915
  const REDIRECT_TYPE = 'sparkvault-identity-redirect';
6916
+ /** Social-login start request posted by the widget. */
6917
+ const SOCIAL_TYPE = 'sparkvault-identity-social';
6909
6918
  class WidgetEmbedder {
6910
6919
  constructor(config, options, callbacks) {
6911
6920
  this.config = config;
@@ -6952,6 +6961,43 @@ class WidgetEmbedder {
6952
6961
  window.removeEventListener('message', this.boundHandleMessage);
6953
6962
  document.body.style.overflow = this.previousBodyOverflow;
6954
6963
  }
6964
+ /**
6965
+ * Begin a social-login redirect from the host. State and redirect_uri are
6966
+ * the customer's top origin so `consumeRedirectResult` validates them on
6967
+ * return. Mirrors the SDK's getSocialAuthUrl.
6968
+ */
6969
+ startSocial(provider) {
6970
+ // Provider comes from the trusted widget origin, but never build a URL from
6971
+ // an unexpected value.
6972
+ if (!/^[a-z0-9_]+$/i.test(provider))
6973
+ return;
6974
+ const state = generateState();
6975
+ try {
6976
+ sessionStorage.setItem('sv_oauth_state', state);
6977
+ }
6978
+ catch {
6979
+ // Storage disabled (private mode): proceed; the backend still binds state.
6980
+ }
6981
+ const url = new URL(`${this.config.identityBaseUrl}/${this.config.accountId}/social/${provider}`);
6982
+ url.searchParams.set('redirect_uri', window.location.origin + window.location.pathname);
6983
+ url.searchParams.set('state', state);
6984
+ const authContext = this.options.authContext;
6985
+ if (authContext?.authRequestId) {
6986
+ url.searchParams.set('auth_request_id', authContext.authRequestId);
6987
+ }
6988
+ if (authContext?.simpleMode) {
6989
+ const simpleMode = authContext.simpleMode.sessionId
6990
+ ? { session_id: authContext.simpleMode.sessionId }
6991
+ : {
6992
+ success_url: authContext.simpleMode.successUrl,
6993
+ failure_url: authContext.simpleMode.failureUrl,
6994
+ state: authContext.simpleMode.state,
6995
+ };
6996
+ url.searchParams.set('simple_mode', JSON.stringify(simpleMode));
6997
+ }
6998
+ this.close();
6999
+ window.location.href = url.toString();
7000
+ }
6955
7001
  buildUrl() {
6956
7002
  const url = new URL(`${this.config.identityBaseUrl}/${this.config.accountId}/widget`);
6957
7003
  url.searchParams.set('origin', window.location.origin);
@@ -6983,7 +7029,13 @@ class WidgetEmbedder {
6983
7029
  const data = event.data;
6984
7030
  if (!data || typeof data.type !== 'string')
6985
7031
  return;
6986
- // Social / OIDC redirect: the widget cannot navigate the top window from a
7032
+ // Social login: start it from the host so the OAuth state and redirect_uri
7033
+ // live on the customer's top origin (where the return is consumed).
7034
+ if (data.type === SOCIAL_TYPE && typeof data.provider === 'string') {
7035
+ this.startSocial(data.provider);
7036
+ return;
7037
+ }
7038
+ // OIDC / generic redirect: the widget cannot navigate the top window from a
6987
7039
  // cross-origin frame, so it asks us to. Navigating away tears down the
6988
7040
  // iframe; on return the host SDK consumes the redirect token.
6989
7041
  if (data.type === REDIRECT_TYPE && typeof data.url === 'string') {