@civic/auth 0.8.3-beta.1 → 0.9.0-beta.1
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/CHANGELOG.md +5 -0
- package/README.md +3 -3
- package/dist/constants.d.ts +2 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -1
- package/dist/constants.js.map +1 -1
- package/dist/nextjs/config.d.ts +3 -0
- package/dist/nextjs/config.d.ts.map +1 -1
- package/dist/nextjs/config.js +3 -0
- package/dist/nextjs/config.js.map +1 -1
- package/dist/nextjs/providers/NextAuthProvider.d.ts.map +1 -1
- package/dist/nextjs/providers/NextAuthProvider.js +1 -1
- package/dist/nextjs/providers/NextAuthProvider.js.map +1 -1
- package/dist/reactjs/core/GlobalAuthManager.d.ts +1 -0
- package/dist/reactjs/core/GlobalAuthManager.d.ts.map +1 -1
- package/dist/reactjs/core/GlobalAuthManager.js +3 -1
- package/dist/reactjs/core/GlobalAuthManager.js.map +1 -1
- package/dist/reactjs/providers/CivicAuthProvider.d.ts +1 -0
- package/dist/reactjs/providers/CivicAuthProvider.d.ts.map +1 -1
- package/dist/reactjs/providers/CivicAuthProvider.js +3 -1
- package/dist/reactjs/providers/CivicAuthProvider.js.map +1 -1
- package/dist/services/AuthenticationService.d.ts +8 -2
- package/dist/services/AuthenticationService.d.ts.map +1 -1
- package/dist/services/AuthenticationService.js +20 -6
- package/dist/services/AuthenticationService.js.map +1 -1
- package/dist/shared/components/IFrameAndLoading.d.ts.map +1 -1
- package/dist/shared/components/IFrameAndLoading.js +1 -1
- package/dist/shared/components/IFrameAndLoading.js.map +1 -1
- package/dist/shared/hooks/useSignIn.d.ts.map +1 -1
- package/dist/shared/hooks/useSignIn.js +4 -3
- package/dist/shared/hooks/useSignIn.js.map +1 -1
- package/dist/shared/lib/iframeUtils.d.ts +1 -0
- package/dist/shared/lib/iframeUtils.d.ts.map +1 -1
- package/dist/shared/lib/iframeUtils.js +9 -0
- package/dist/shared/lib/iframeUtils.js.map +1 -1
- package/dist/shared/lib/types.d.ts +1 -0
- package/dist/shared/lib/types.d.ts.map +1 -1
- package/dist/shared/lib/types.js.map +1 -1
- package/dist/shared/providers/CivicAuthConfigContext.d.ts +2 -1
- package/dist/shared/providers/CivicAuthConfigContext.d.ts.map +1 -1
- package/dist/shared/providers/CivicAuthConfigContext.js +3 -1
- package/dist/shared/providers/CivicAuthConfigContext.js.map +1 -1
- package/dist/shared/version.d.ts +1 -1
- package/dist/shared/version.js +1 -1
- package/dist/shared/version.js.map +1 -1
- package/dist/vanillajs/auth/CivicAuth.d.ts +1 -0
- package/dist/vanillajs/auth/CivicAuth.d.ts.map +1 -1
- package/dist/vanillajs/auth/CivicAuth.js +15 -1
- package/dist/vanillajs/auth/CivicAuth.js.map +1 -1
- package/dist/vanillajs/auth/config/ConfigProcessor.d.ts.map +1 -1
- package/dist/vanillajs/auth/config/ConfigProcessor.js +1 -0
- package/dist/vanillajs/auth/config/ConfigProcessor.js.map +1 -1
- package/dist/vanillajs/auth/handlers/IframeAuthHandler.d.ts +10 -0
- package/dist/vanillajs/auth/handlers/IframeAuthHandler.d.ts.map +1 -1
- package/dist/vanillajs/auth/handlers/IframeAuthHandler.js +24 -1
- package/dist/vanillajs/auth/handlers/IframeAuthHandler.js.map +1 -1
- package/dist/vanillajs/auth/handlers/MessageHandler.d.ts +2 -0
- package/dist/vanillajs/auth/handlers/MessageHandler.d.ts.map +1 -1
- package/dist/vanillajs/auth/handlers/MessageHandler.js +7 -0
- package/dist/vanillajs/auth/handlers/MessageHandler.js.map +1 -1
- package/dist/vanillajs/auth/types/AuthTypes.d.ts +3 -0
- package/dist/vanillajs/auth/types/AuthTypes.d.ts.map +1 -1
- package/dist/vanillajs/auth/types/AuthTypes.js.map +1 -1
- package/dist/vanillajs/iframe/IframeManager.d.ts.map +1 -1
- package/dist/vanillajs/iframe/IframeManager.js +11 -6
- package/dist/vanillajs/iframe/IframeManager.js.map +1 -1
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import { CivicAuthError, CivicAuthErrorCode } from "../types/AuthTypes.js";
|
|
|
3
3
|
import { SignalObserver } from "../../iframe/SignalObserver.js";
|
|
4
4
|
import { IframeManager } from "../../iframe/IframeManager.js";
|
|
5
5
|
import { createLogger as createLoggerFn } from "../../utils/logger.js";
|
|
6
|
+
import { WAIT_FOR_LOGIN_APP_BROWSER_DETECTION_TIMEOUT } from "../../../constants.js";
|
|
6
7
|
export class IframeAuthHandler {
|
|
7
8
|
config;
|
|
8
9
|
logger = createLoggerFn("iframe-auth");
|
|
@@ -349,7 +350,11 @@ export class IframeAuthHandler {
|
|
|
349
350
|
}
|
|
350
351
|
catch (error) {
|
|
351
352
|
this.logger.debug("Cannot access iframe URL (likely cross-origin) - assuming login app, showing content.", { error: error instanceof Error ? error.message : String(error) });
|
|
352
|
-
|
|
353
|
+
setTimeout(() => {
|
|
354
|
+
// Force hide loader after a short delay to ensure any initial loading is complete
|
|
355
|
+
// to give the login-app time to send any post message signals
|
|
356
|
+
this.iframeManager?.forceHideLoader();
|
|
357
|
+
}, WAIT_FOR_LOGIN_APP_BROWSER_DETECTION_TIMEOUT);
|
|
353
358
|
}
|
|
354
359
|
}
|
|
355
360
|
checkIframeRedirect() {
|
|
@@ -537,6 +542,24 @@ export class IframeAuthHandler {
|
|
|
537
542
|
return isPreloaded;
|
|
538
543
|
return isPreloaded && this.iframeManager.getPreloadedUrl() === url;
|
|
539
544
|
}
|
|
545
|
+
/**
|
|
546
|
+
* Force the iframe to hide, even if it is currently showing
|
|
547
|
+
*
|
|
548
|
+
* This is useful for cleanup or when you want to ensure the iframe is not visible
|
|
549
|
+
* regardless of its current state.
|
|
550
|
+
*/
|
|
551
|
+
forceHideIframe() {
|
|
552
|
+
if (this.iframeManager) {
|
|
553
|
+
this.iframeManager.hide();
|
|
554
|
+
this.logger.debug("Forced iframe to hide");
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
this.logger.warn("Cannot force hide iframe, iframe manager not initialized");
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Force the iframe to show the loading indicator
|
|
562
|
+
*/
|
|
540
563
|
forceShowLoader() {
|
|
541
564
|
if (this.iframeManager) {
|
|
542
565
|
this.iframeManager.forceShowLoader();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IframeAuthHandler.js","sourceRoot":"","sources":["../../../../src/vanillajs/auth/handlers/IframeAuthHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAWvE,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAA2B;IACjC,MAAM,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;IACvC,aAAa,CAA+B;IAC5C,WAAW,CAAyB;IACpC,OAAO,CAAa;IACpB,cAAc,CAAgC;IAC9C,aAAa,CAAiB;IAC9B,aAAa,CAAqB;IAClC,cAAc,CAAkB;IAChC,uBAAuB,CAA+B;IACtD,gBAAgB,CAAU,CAAC,0BAA0B;IAE7D,YAAY,aAAsC;QAChD,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;QACnC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC,aAAa,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC,WAAW,CAAC;QAC7C,IAAI,CAAC,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC;QACrC,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC,cAAc,CAA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\"../../types/index.js\";\nimport type { ProcessedCivicAuthConfig } from \"../types/AuthTypes.js\";\nimport { CivicAuthError, CivicAuthErrorCode } from \"../types/AuthTypes.js\";\nimport { SignalObserver } from \"../../iframe/SignalObserver.js\";\nimport { IframeManager } from \"../../iframe/IframeManager.js\";\nimport type { createLogger } from \"../../utils/logger.js\";\nimport { createLogger as createLoggerFn } from \"../../utils/logger.js\";\n\nexport interface IframeAuthHandlerConfig {\n config: ProcessedCivicAuthConfig;\n logger: ReturnType<typeof createLogger>;\n onAuthSuccess: (result: AuthResult) => void;\n onAuthError: (error: Error) => void;\n cleanup: () => void;\n messageHandler: (event: MessageEvent) => void;\n}\n\nexport class IframeAuthHandler {\n private config: ProcessedCivicAuthConfig;\n private logger = createLoggerFn(\"iframe-auth\");\n private onAuthSuccess: (result: AuthResult) => void;\n private onAuthError: (error: Error) => void;\n private cleanup: () => void;\n private messageHandler: (event: MessageEvent) => void;\n private iframeManager?: IframeManager;\n private iframeElement?: HTMLIFrameElement;\n private signalObserver?: SignalObserver;\n private earlyAuthSuccessHandler: (event: CustomEvent) => void;\n private isPreloadEnabled: boolean; // Initialized from config\n\n constructor(handlerConfig: IframeAuthHandlerConfig) {\n this.config = handlerConfig.config;\n this.logger = handlerConfig.logger;\n this.onAuthSuccess = handlerConfig.onAuthSuccess;\n this.onAuthError = handlerConfig.onAuthError;\n this.cleanup = handlerConfig.cleanup;\n this.messageHandler = handlerConfig.messageHandler;\n\n // Set preload enabled state from config\n this.isPreloadEnabled = this.config.preloadIframe;\n\n // Listen for early auth success signals from login-app\n this.earlyAuthSuccessHandler = (event: CustomEvent) => {\n this.logger.info(\"Received early auth success signal from login-app\", {\n detail: event.detail,\n });\n\n // Close the modal immediately but keep iframe for callback processing\n if (this.iframeManager) {\n this.logger.info(\"Closing modal early due to auth success signal\");\n this.iframeManager.hide();\n\n // Emit event to notify that modal is closing early\n this.config.events?.emit(AuthEvent.SIGN_IN_STARTED, {\n detail: \"Modal closed early due to auth success signal\",\n });\n }\n };\n\n window.addEventListener(\n \"civic-auth-success-early\",\n this.earlyAuthSuccessHandler as EventListener,\n );\n }\n\n /**\n * Preloads the iframe with the authentication URL for instant display later\n * This creates the iframe in the background but keeps it completely hidden\n */\n public async preloadIframe(fullAuthUrl: string): Promise<void> {\n if (!this.isPreloadEnabled) {\n this.logger.debug(\"Iframe preloading is disabled, skipping preload\");\n return;\n }\n\n this.logger.debug(\"Preloading iframe for instant sign-in\", {\n url: fullAuthUrl,\n });\n\n // Determine the actual display mode for IframeManager first\n const iframeDisplayMode = this.determineIframeDisplayMode();\n\n let container = this.getContainerElement();\n\n // For modal mode, if no container is provided, create one dynamically\n if (iframeDisplayMode === \"modal\" && !container) {\n container = this.createModalContainer();\n }\n\n if (!container) {\n const error = new CivicAuthError(\n \"Target container element not found for preloading.\",\n CivicAuthErrorCode.CONTAINER_NOT_FOUND,\n );\n this.logger.error(error.message);\n throw error;\n }\n\n this.logger.debug(\"Creating IframeManager for preloading\", {\n url: fullAuthUrl,\n containerId: container?.id,\n iframeId: this.config.iframeId,\n origin: window.location.origin,\n iframeDisplayMode,\n });\n\n // Create IframeManager with appropriate display mode\n this.iframeManager = new IframeManager({\n container: container,\n displayMode: iframeDisplayMode,\n iframeId: this.config.iframeId,\n onClose: () => {\n this.logger.debug(\"Authentication close requested during preload\");\n // For preload, we don't want to trigger auth error, just cleanup\n this.cleanupIframe();\n },\n });\n\n // Preload the iframe using IframeManager\n this.iframeElement = this.iframeManager.preloadIframe(fullAuthUrl);\n\n // Set up event handlers for the preloaded iframe\n this.setupIframeEventHandlers();\n this.setupIframeNavigationMonitoring();\n\n this.logger.debug(\"Iframe preloaded successfully\", { url: fullAuthUrl });\n }\n\n public async handleIframeAuth(\n fullAuthUrl: string,\n ): Promise<HTMLIFrameElement> {\n // Check if we have a preloaded iframe that we can show instantly\n // We use the preloaded iframe if available, even if URLs don't exactly match,\n // since PKCE challenges and other parameters may differ between preload and actual auth\n if (this.iframeManager?.isIframePreloaded() && this.iframeElement) {\n const preloadedUrl = this.iframeManager.getPreloadedUrl();\n this.logger.debug(\"Using preloaded iframe for instant sign-in\", {\n preloadedUrl,\n requestedUrl: fullAuthUrl,\n urlsMatch: preloadedUrl === fullAuthUrl,\n });\n\n // Don't change iframe.src for preloaded iframes - use them as-is to avoid reload\n // The preloaded authentication flow will work perfectly without URL changes\n this.logger.debug(\"Using preloaded iframe without reload\", {\n preloadedUrl,\n requestedUrl: fullAuthUrl,\n action: \"skipping_url_change_to_prevent_reload\",\n });\n\n // Update the onClose handler for active authentication\n // During preload, onClose only cleaned up, but during active auth it should emit error events\n this.iframeManager.updateOnCloseHandler(() => {\n this.logger.debug(\n \"Authentication close requested by user (backdrop click, close button, or Escape key)\",\n );\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: \"Authentication cancelled by user\",\n });\n\n const error = new CivicAuthError(\n \"Authentication cancelled by user\",\n CivicAuthErrorCode.USER_CANCELLED,\n );\n\n this.onAuthError(error);\n this.cleanup();\n });\n\n // Show the preloaded iframe instantly\n this.iframeElement = this.iframeManager.createIframe(fullAuthUrl);\n\n this.config.events?.emit(AuthEvent.SIGN_IN_STARTED, {\n detail: \"Preloaded iframe displayed instantly\",\n });\n\n return this.iframeElement;\n }\n\n // Fallback to creating a new iframe if no preload is available\n this.logger.debug(\"No preloaded iframe available, creating new iframe\", {\n url: fullAuthUrl,\n });\n\n // Determine the actual display mode for IframeManager first\n const iframeDisplayMode = this.determineIframeDisplayMode();\n\n let container = this.getContainerElement();\n\n // For modal mode, if no container is provided, create one dynamically\n if (iframeDisplayMode === \"modal\" && !container) {\n container = this.createModalContainer();\n }\n\n if (!container) {\n const error = new CivicAuthError(\n \"Target container element not found.\",\n CivicAuthErrorCode.CONTAINER_NOT_FOUND,\n );\n this.logger.error(error.message);\n throw error;\n }\n\n this.logger.debug(\"Creating iframe with modal backdrop\", {\n url: fullAuthUrl,\n containerId: container?.id,\n iframeId: this.config.iframeId,\n origin: window.location.origin,\n iframeDisplayMode,\n containerCreated:\n iframeDisplayMode === \"modal\" && !this.config.targetContainerElement,\n });\n\n this.logger.debug(\n `🎯 CivicAuth: Creating IframeManager with display mode: ${iframeDisplayMode}`,\n );\n\n // Create IframeManager with appropriate display mode\n this.iframeManager = new IframeManager({\n container: container,\n displayMode: iframeDisplayMode,\n iframeId: this.config.iframeId,\n /**\n * Handles iframe closure events initiated by the user.\n * This includes backdrop clicks, close button clicks, or Escape key presses.\n * Emits an error event and cleans up the authentication process.\n */\n onClose: () => {\n this.logger.debug(\n \"Authentication close requested by user (backdrop click, close button, or Escape key)\",\n );\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: \"Authentication cancelled by user\",\n });\n\n const error = new CivicAuthError(\n \"Authentication cancelled by user\",\n CivicAuthErrorCode.USER_CANCELLED,\n );\n\n this.onAuthError(error);\n this.cleanup();\n },\n });\n\n // Create the iframe using IframeManager\n this.iframeElement = this.iframeManager.createIframe(fullAuthUrl);\n\n this.config.events?.emit(AuthEvent.SIGN_IN_STARTED, {\n detail: \"Iframe created with modal backdrop\",\n });\n\n this.setupIframeEventHandlers();\n this.setupIframeNavigationMonitoring();\n\n return this.iframeElement;\n }\n\n public getIframeManager(): IframeManager | undefined {\n return this.iframeManager;\n }\n\n public getIframeElement(): HTMLIFrameElement | undefined {\n return this.iframeElement;\n }\n\n public cleanupIframe(): void {\n this.logger.debug(\"Cleaning up iframe manager\");\n this.iframeManager?.cleanup();\n this.iframeManager = undefined;\n\n if (this.iframeElement) {\n this.iframeElement = undefined;\n }\n\n // Remove early auth success event listener\n if (this.earlyAuthSuccessHandler) {\n window.removeEventListener(\n \"civic-auth-success-early\",\n this.earlyAuthSuccessHandler as EventListener,\n );\n }\n\n // Clean up dynamically created modal containers\n this.cleanupDynamicModalContainer();\n }\n\n private cleanupDynamicModalContainer(): void {\n // Only clean up containers we created dynamically (not user-provided ones)\n if (!this.config.targetContainerElement) {\n const dynamicContainer = document.querySelector(\n `[data-civic-auth-modal=\"true\"]#${this.config.iframeId}-modal-container`,\n );\n\n if (dynamicContainer && dynamicContainer.parentNode) {\n this.logger.debug(\"Removing dynamic modal container\", {\n containerId: dynamicContainer.id,\n });\n dynamicContainer.parentNode.removeChild(dynamicContainer);\n }\n }\n }\n\n private createModalContainer(): HTMLElement {\n const container = document.createElement(\"div\");\n container.id = `${this.config.iframeId}-modal-container`;\n container.setAttribute(\"data-civic-auth-modal\", \"true\");\n\n // Append to body for modal overlay\n document.body.appendChild(container);\n\n this.logger.debug(\"Created dynamic modal container\", {\n containerId: container.id,\n });\n\n return container;\n }\n\n private getContainerElement(): HTMLElement | null {\n if (!this.config.targetContainerElement) {\n return null;\n }\n\n if (typeof this.config.targetContainerElement === \"string\") {\n const element = document.getElementById(\n this.config.targetContainerElement,\n );\n if (!element) {\n this.logger.warn(\n `Container element with ID \"${this.config.targetContainerElement}\" not found`,\n );\n }\n return element;\n }\n return this.config.targetContainerElement;\n }\n\n private determineIframeDisplayMode(): \"modal\" | \"embedded\" {\n // Priority 1: Explicit iframeDisplayMode setting from config\n // This is the most specific instruction for how the iframe itself should be styled.\n if (this.config.iframeDisplayMode) {\n this.logger.debug(\n `Using configured iframeDisplayMode: ${this.config.iframeDisplayMode}`,\n );\n return this.config.iframeDisplayMode;\n }\n\n // Priority 2: If iframeDisplayMode is NOT set, and the overall displayMode is \"iframe\",\n // default the iframe's own rendering style to \"modal\" (user-friendly default).\n // To get an embedded iframe, iframeDisplayMode: \"embedded\" should be set explicitly.\n if (this.config.displayMode === \"iframe\") {\n this.logger.debug(\n \"Overall displayMode is 'iframe' and iframeDisplayMode is not set, defaulting iframe style to 'modal'.\",\n );\n return \"modal\";\n }\n\n // Fallback for unexpected scenarios or if IframeAuthHandler is invoked with other displayModes.\n this.logger.warn(\n `determineIframeDisplayMode called with overall displayMode: '${this.config.displayMode}' ` +\n `and no explicit iframeDisplayMode. Defaulting iframe style to 'modal'.`,\n );\n return \"modal\";\n }\n\n private setupIframeEventHandlers(): void {\n if (!this.iframeElement) return;\n\n this.iframeElement.onload = () => {\n this.logger.info(\"Iframe loaded\", {\n iframeSrc: this.iframeElement?.src,\n currentOrigin: window.location.origin,\n expectedAuthServerOrigin: new URL(this.config.oauthServerBaseUrl)\n .origin,\n });\n\n if (!this.iframeElement?.contentWindow) {\n const errorMsg = \"Iframe content window not available after load.\";\n this.logger.error(errorMsg, {\n iframeSrc: this.iframeElement?.src,\n });\n\n const error = new Error(errorMsg);\n this.onAuthError(error);\n this.cleanup();\n return;\n }\n\n // Set up postMessage listener for cross-origin communication\n window.addEventListener(\"message\", this.messageHandler);\n this.logger.info(\n \"Added cross-origin message event listener for auth server communication\",\n {\n parentOrigin: window.location.origin,\n authServerOrigin: new URL(this.config.oauthServerBaseUrl).origin,\n },\n );\n\n // Hide iframe content if it's not the login app\n this.checkAndHideNonLoginContent();\n\n // Try to detect redirect to our domain\n this.checkIframeRedirect();\n };\n\n this.iframeElement.onerror = (event) => {\n this.logger.error(\"Iframe load error\", {\n event,\n iframeSrc: this.iframeElement?.src,\n currentOrigin: window.location.origin,\n });\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: \"Iframe load error\",\n error: event,\n });\n\n const error = new Error(\"Iframe failed to load.\");\n this.onAuthError(error);\n this.cleanup();\n };\n }\n\n private checkAndHideNonLoginContent(): void {\n try {\n const currentUrl = this.iframeElement?.contentWindow?.location.href;\n if (currentUrl) {\n const currentOrigin = new URL(currentUrl).origin;\n const expectedAuthServerOrigin = this.config.oauthServerBaseUrl\n ? new URL(this.config.oauthServerBaseUrl).origin\n : null;\n const isOnAuthServer = expectedAuthServerOrigin\n ? currentOrigin === expectedAuthServerOrigin\n : false;\n const isCallbackUrl = this.config.redirectUrl\n ? currentUrl.startsWith(this.config.redirectUrl)\n : false;\n\n if (isOnAuthServer && !isCallbackUrl) {\n this.logger.info(\n \"👀 Showing iframe content - confirmed login app on auth server origin\",\n {\n currentUrl,\n isOnAuthServer,\n isCallbackUrl,\n currentOrigin,\n expectedAuthServerOrigin,\n },\n );\n this.iframeManager?.forceHideLoader();\n } else {\n this.logger.info(\n \"🙈 Hiding iframe completely - not login app or on callback URL\",\n {\n currentUrl,\n isOnAuthServer,\n isCallbackUrl,\n currentOrigin,\n expectedAuthServerOrigin,\n reason: !isOnAuthServer\n ? expectedAuthServerOrigin\n ? \"not on auth server (origin mismatch)\"\n : \"auth server origin unknown\"\n : \"on callback URL (or origin mismatch for login page)\",\n },\n );\n\n if (isCallbackUrl) {\n this.iframeManager?.hide();\n } else {\n this.iframeManager?.forceShowLoader();\n }\n }\n }\n } catch (error) {\n this.logger.debug(\n \"Cannot access iframe URL (likely cross-origin) - assuming login app, showing content.\",\n { error: error instanceof Error ? error.message : String(error) },\n );\n this.iframeManager?.forceHideLoader();\n }\n }\n\n private checkIframeRedirect(): void {\n try {\n const currentIframeHref =\n this.iframeElement?.contentWindow?.location.href;\n\n if (currentIframeHref) {\n this.logger.debug(\"Iframe current href accessible\", {\n href: currentIframeHref,\n redirectUrl: this.config.redirectUrl,\n startsWithRedirect: currentIframeHref.startsWith(\n this.config.redirectUrl,\n ),\n });\n\n if (currentIframeHref.startsWith(this.config.redirectUrl)) {\n this.logger.info(\n \"Iframe has navigated to redirectUrl (same-origin). Setting up DOM observer.\",\n );\n\n // Hide content since we're on callback page now\n this.checkAndHideNonLoginContent();\n\n // Set up signal observer for same-origin callback page\n if (\n this.iframeElement?.contentDocument &&\n this.iframeElement.contentDocument.body\n ) {\n this.setupSignalObserver(this.iframeElement.contentDocument);\n } else {\n this.logger.warn(\n \"Iframe content document or body not available for signal observer\",\n );\n }\n }\n }\n } catch (error) {\n this.logger.debug(\n \"Error checking iframe href (expected for cross-origin)\",\n {\n error: error instanceof Error ? error.message : String(error),\n iframeSrc: this.iframeElement?.src,\n },\n );\n // This is expected when the iframe is on the auth server domain\n this.logger.info(\n \"Iframe is on auth server domain - using postMessage for communication\",\n {\n parentOrigin: window.location.origin,\n authServerOrigin: new URL(this.config.oauthServerBaseUrl).origin,\n },\n );\n }\n }\n\n private setupSignalObserver(iframeDoc: Document): void {\n const signalObserver = new SignalObserver(\n {\n textSignals: this.config.textSignals,\n events: this.config.events,\n logger: this.logger,\n },\n this.onAuthSuccess,\n (error?: Error) =>\n this.onAuthError(error || new Error(\"Signal observer error\")),\n () => this.cleanup(),\n );\n\n signalObserver.setup(iframeDoc);\n }\n\n private setupIframeNavigationMonitoring(): void {\n // Monitor iframe navigation to detect when it redirects to our callback URL\n let monitoringInterval: number | undefined = undefined;\n let lastKnownUrl = \"\";\n\n const checkIframeNavigation = () => {\n if (!this.iframeElement?.contentWindow) {\n if (monitoringInterval) {\n clearInterval(monitoringInterval);\n }\n return;\n }\n\n try {\n const currentUrl = this.iframeElement.contentWindow.location.href;\n\n if (currentUrl !== lastKnownUrl) {\n lastKnownUrl = currentUrl;\n this.logger.debug(\"Iframe navigation detected\", {\n newUrl: currentUrl,\n redirectUrl: this.config.redirectUrl,\n isCallbackUrl: currentUrl.startsWith(this.config.redirectUrl),\n });\n\n // Check if iframe has navigated to our callback URL\n if (currentUrl.startsWith(this.config.redirectUrl)) {\n // Hide immediately on callback URL detection\n this.iframeManager?.hide();\n this.logger.info(\n \"Iframe navigated to callback URL - setting up signal observer\",\n );\n\n if (monitoringInterval) {\n clearInterval(monitoringInterval);\n }\n\n // Set up signal observer for same-origin callback page\n if (\n this.iframeElement.contentDocument &&\n this.iframeElement.contentDocument.body\n ) {\n this.setupSignalObserver(this.iframeElement.contentDocument);\n }\n\n // Also check for URL parameters (code, error) in case of direct callback\n this.processCallbackUrl(currentUrl);\n } else {\n // Hide content if not on login app\n this.checkAndHideNonLoginContent();\n }\n }\n } catch {\n // Expected when iframe is on different origin\n // Only log if we haven't seen this before\n if (lastKnownUrl !== \"cross-origin\") {\n lastKnownUrl = \"cross-origin\";\n this.logger.debug(\n \"Iframe on cross-origin domain (expected during auth flow)\",\n );\n }\n }\n };\n\n // Check immediately and then every 100ms for faster detection\n checkIframeNavigation();\n monitoringInterval = window.setInterval(checkIframeNavigation, 100);\n\n // Store cleanup function to clear monitoring\n const originalCleanup = this.cleanup;\n this.cleanup = () => {\n if (monitoringInterval) {\n clearInterval(monitoringInterval);\n }\n originalCleanup();\n };\n }\n\n private processCallbackUrl(currentUrl: string): void {\n const urlParams = new URLSearchParams(new URL(currentUrl).search);\n const code = urlParams.get(\"code\");\n const error = urlParams.get(\"error\");\n\n if (code) {\n this.logger.info(\"Authorization code detected in iframe URL\", {\n code: code.substring(0, 10) + \"...\",\n hasState: !!urlParams.get(\"state\"),\n });\n }\n\n if (error) {\n this.logger.error(\"OAuth error detected in iframe URL\", {\n error,\n errorDescription: urlParams.get(\"error_description\"),\n });\n\n const authError = new CivicAuthError(\n `OAuth error: ${error}`,\n CivicAuthErrorCode.INVALID_MESSAGE,\n );\n\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: authError.message,\n error: urlParams.get(\"error_description\") || error,\n });\n\n this.onAuthError(authError);\n }\n }\n\n public navigateIframe(url: string): void {\n if (!this.iframeElement) {\n this.logger.error(\n \"Cannot navigate iframe, iframeElement is not available.\",\n );\n this.onAuthError(\n new CivicAuthError(\n \"Iframe element not found for navigation.\",\n CivicAuthErrorCode.IFRAME_NOT_FOUND,\n ),\n );\n return;\n }\n if (!this.iframeManager) {\n this.logger.error(\n \"Cannot navigate iframe, iframeManager is not available.\",\n );\n this.onAuthError(\n new CivicAuthError(\n \"Iframe manager not found for navigation.\",\n CivicAuthErrorCode.INTERNAL_ERROR,\n ),\n );\n return;\n }\n this.logger.info(\"Navigating iframe to new URL\", { url });\n this.iframeElement.src = url;\n // After changing src, existing onload/onmessage handlers in IframeManager\n // and navigation monitoring in this class should manage visibility and state.\n }\n\n /**\n * Enable or disable iframe preloading\n */\n public setPreloadEnabled(enabled: boolean): void {\n this.isPreloadEnabled = enabled;\n this.logger.debug(\"Iframe preloading\", { enabled });\n }\n\n /**\n * Check if iframe preloading is enabled\n */\n public getPreloadEnabled(): boolean {\n return this.isPreloadEnabled;\n }\n\n /**\n * Check if an iframe is currently preloaded and ready for instant display\n *\n * This function helps optimize user experience by determining if we can show\n * a preloaded iframe immediately instead of loading a new one. The logic:\n *\n * 1. Returns false if no iframe manager exists (can't have preloaded content)\n * 2. Checks if any iframe is currently preloaded via the iframe manager\n * 3. If no specific URL is provided, returns whether any iframe is preloaded\n * 4. If a URL is provided, ensures both that an iframe is preloaded AND\n * that it contains the exact URL we need\n *\n * This prevents unnecessary iframe reloads when the user triggers auth flows\n * with the same URL that's already loaded and ready to display.\n *\n * @param url - Optional URL to match against the preloaded iframe's URL\n * @returns true if a suitable preloaded iframe exists, false otherwise\n */\n public hasPreloadedIframe(url?: string): boolean {\n if (!this.iframeManager) return false;\n\n const isPreloaded = this.iframeManager.isIframePreloaded();\n if (!url) return isPreloaded;\n\n return isPreloaded && this.iframeManager.getPreloadedUrl() === url;\n }\n\n public forceShowLoader(): void {\n if (this.iframeManager) {\n this.iframeManager.forceShowLoader();\n this.logger.debug(\"Forced iframe loader to show\");\n } else {\n this.logger.warn(\n \"Cannot force show loader, iframe manager not initialized\",\n );\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"IframeAuthHandler.js","sourceRoot":"","sources":["../../../../src/vanillajs/auth/handlers/IframeAuthHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,4CAA4C,EAAE,MAAM,gBAAgB,CAAC;AAW9E,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAA2B;IACjC,MAAM,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC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;;;;;;;OAiBG;IACI,kBAAkB,CAAC,GAAY;QACpC,IAAI,CAAC,IAAI,CAAC,aAAa;YAAE,OAAO,KAAK,CAAC;QAEtC,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,iBAAiB,EAAE,CAAC;QAC3D,IAAI,CAAC,GAAG;YAAE,OAAO,WAAW,CAAC;QAE7B,OAAO,WAAW,IAAI,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,KAAK,GAAG,CAAC;IACrE,CAAC;IAED;;;;;OAKG;IACI,eAAe;QACpB,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;YAC1B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,0DAA0D,CAC3D,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACI,eAAe;QACpB,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,IAAI,CAAC,aAAa,CAAC,eAAe,EAAE,CAAC;YACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACpD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,0DAA0D,CAC3D,CAAC;QACJ,CAAC;IACH,CAAC;CACF","sourcesContent":["import { AuthEvent } from \"../../types/index.js\";\nimport type { AuthResult } from \"../../types/index.js\";\nimport type { ProcessedCivicAuthConfig } from \"../types/AuthTypes.js\";\nimport { CivicAuthError, CivicAuthErrorCode } from \"../types/AuthTypes.js\";\nimport { SignalObserver } from \"../../iframe/SignalObserver.js\";\nimport { IframeManager } from \"../../iframe/IframeManager.js\";\nimport type { createLogger } from \"../../utils/logger.js\";\nimport { createLogger as createLoggerFn } from \"../../utils/logger.js\";\nimport { WAIT_FOR_LOGIN_APP_BROWSER_DETECTION_TIMEOUT } from \"@/constants.js\";\n\nexport interface IframeAuthHandlerConfig {\n config: ProcessedCivicAuthConfig;\n logger: ReturnType<typeof createLogger>;\n onAuthSuccess: (result: AuthResult) => void;\n onAuthError: (error: Error) => void;\n cleanup: () => void;\n messageHandler: (event: MessageEvent) => void;\n}\n\nexport class IframeAuthHandler {\n private config: ProcessedCivicAuthConfig;\n private logger = createLoggerFn(\"iframe-auth\");\n private onAuthSuccess: (result: AuthResult) => void;\n private onAuthError: (error: Error) => void;\n private cleanup: () => void;\n private messageHandler: (event: MessageEvent) => void;\n private iframeManager?: IframeManager;\n private iframeElement?: HTMLIFrameElement;\n private signalObserver?: SignalObserver;\n private earlyAuthSuccessHandler: (event: CustomEvent) => void;\n private isPreloadEnabled: boolean; // Initialized from config\n\n constructor(handlerConfig: IframeAuthHandlerConfig) {\n this.config = handlerConfig.config;\n this.logger = handlerConfig.logger;\n this.onAuthSuccess = handlerConfig.onAuthSuccess;\n this.onAuthError = handlerConfig.onAuthError;\n this.cleanup = handlerConfig.cleanup;\n this.messageHandler = handlerConfig.messageHandler;\n\n // Set preload enabled state from config\n this.isPreloadEnabled = this.config.preloadIframe;\n\n // Listen for early auth success signals from login-app\n this.earlyAuthSuccessHandler = (event: CustomEvent) => {\n this.logger.info(\"Received early auth success signal from login-app\", {\n detail: event.detail,\n });\n\n // Close the modal immediately but keep iframe for callback processing\n if (this.iframeManager) {\n this.logger.info(\"Closing modal early due to auth success signal\");\n this.iframeManager.hide();\n\n // Emit event to notify that modal is closing early\n this.config.events?.emit(AuthEvent.SIGN_IN_STARTED, {\n detail: \"Modal closed early due to auth success signal\",\n });\n }\n };\n\n window.addEventListener(\n \"civic-auth-success-early\",\n this.earlyAuthSuccessHandler as EventListener,\n );\n }\n\n /**\n * Preloads the iframe with the authentication URL for instant display later\n * This creates the iframe in the background but keeps it completely hidden\n */\n public async preloadIframe(fullAuthUrl: string): Promise<void> {\n if (!this.isPreloadEnabled) {\n this.logger.debug(\"Iframe preloading is disabled, skipping preload\");\n return;\n }\n\n this.logger.debug(\"Preloading iframe for instant sign-in\", {\n url: fullAuthUrl,\n });\n\n // Determine the actual display mode for IframeManager first\n const iframeDisplayMode = this.determineIframeDisplayMode();\n\n let container = this.getContainerElement();\n\n // For modal mode, if no container is provided, create one dynamically\n if (iframeDisplayMode === \"modal\" && !container) {\n container = this.createModalContainer();\n }\n\n if (!container) {\n const error = new CivicAuthError(\n \"Target container element not found for preloading.\",\n CivicAuthErrorCode.CONTAINER_NOT_FOUND,\n );\n this.logger.error(error.message);\n throw error;\n }\n\n this.logger.debug(\"Creating IframeManager for preloading\", {\n url: fullAuthUrl,\n containerId: container?.id,\n iframeId: this.config.iframeId,\n origin: window.location.origin,\n iframeDisplayMode,\n });\n\n // Create IframeManager with appropriate display mode\n this.iframeManager = new IframeManager({\n container: container,\n displayMode: iframeDisplayMode,\n iframeId: this.config.iframeId,\n onClose: () => {\n this.logger.debug(\"Authentication close requested during preload\");\n // For preload, we don't want to trigger auth error, just cleanup\n this.cleanupIframe();\n },\n });\n\n // Preload the iframe using IframeManager\n this.iframeElement = this.iframeManager.preloadIframe(fullAuthUrl);\n\n // Set up event handlers for the preloaded iframe\n this.setupIframeEventHandlers();\n this.setupIframeNavigationMonitoring();\n\n this.logger.debug(\"Iframe preloaded successfully\", { url: fullAuthUrl });\n }\n\n public async handleIframeAuth(\n fullAuthUrl: string,\n ): Promise<HTMLIFrameElement> {\n // Check if we have a preloaded iframe that we can show instantly\n // We use the preloaded iframe if available, even if URLs don't exactly match,\n // since PKCE challenges and other parameters may differ between preload and actual auth\n if (this.iframeManager?.isIframePreloaded() && this.iframeElement) {\n const preloadedUrl = this.iframeManager.getPreloadedUrl();\n this.logger.debug(\"Using preloaded iframe for instant sign-in\", {\n preloadedUrl,\n requestedUrl: fullAuthUrl,\n urlsMatch: preloadedUrl === fullAuthUrl,\n });\n\n // Don't change iframe.src for preloaded iframes - use them as-is to avoid reload\n // The preloaded authentication flow will work perfectly without URL changes\n this.logger.debug(\"Using preloaded iframe without reload\", {\n preloadedUrl,\n requestedUrl: fullAuthUrl,\n action: \"skipping_url_change_to_prevent_reload\",\n });\n\n // Update the onClose handler for active authentication\n // During preload, onClose only cleaned up, but during active auth it should emit error events\n this.iframeManager.updateOnCloseHandler(() => {\n this.logger.debug(\n \"Authentication close requested by user (backdrop click, close button, or Escape key)\",\n );\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: \"Authentication cancelled by user\",\n });\n\n const error = new CivicAuthError(\n \"Authentication cancelled by user\",\n CivicAuthErrorCode.USER_CANCELLED,\n );\n\n this.onAuthError(error);\n this.cleanup();\n });\n\n // Show the preloaded iframe instantly\n this.iframeElement = this.iframeManager.createIframe(fullAuthUrl);\n\n this.config.events?.emit(AuthEvent.SIGN_IN_STARTED, {\n detail: \"Preloaded iframe displayed instantly\",\n });\n\n return this.iframeElement;\n }\n\n // Fallback to creating a new iframe if no preload is available\n this.logger.debug(\"No preloaded iframe available, creating new iframe\", {\n url: fullAuthUrl,\n });\n\n // Determine the actual display mode for IframeManager first\n const iframeDisplayMode = this.determineIframeDisplayMode();\n\n let container = this.getContainerElement();\n\n // For modal mode, if no container is provided, create one dynamically\n if (iframeDisplayMode === \"modal\" && !container) {\n container = this.createModalContainer();\n }\n\n if (!container) {\n const error = new CivicAuthError(\n \"Target container element not found.\",\n CivicAuthErrorCode.CONTAINER_NOT_FOUND,\n );\n this.logger.error(error.message);\n throw error;\n }\n\n this.logger.debug(\"Creating iframe with modal backdrop\", {\n url: fullAuthUrl,\n containerId: container?.id,\n iframeId: this.config.iframeId,\n origin: window.location.origin,\n iframeDisplayMode,\n containerCreated:\n iframeDisplayMode === \"modal\" && !this.config.targetContainerElement,\n });\n\n this.logger.debug(\n `🎯 CivicAuth: Creating IframeManager with display mode: ${iframeDisplayMode}`,\n );\n\n // Create IframeManager with appropriate display mode\n this.iframeManager = new IframeManager({\n container: container,\n displayMode: iframeDisplayMode,\n iframeId: this.config.iframeId,\n /**\n * Handles iframe closure events initiated by the user.\n * This includes backdrop clicks, close button clicks, or Escape key presses.\n * Emits an error event and cleans up the authentication process.\n */\n onClose: () => {\n this.logger.debug(\n \"Authentication close requested by user (backdrop click, close button, or Escape key)\",\n );\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: \"Authentication cancelled by user\",\n });\n\n const error = new CivicAuthError(\n \"Authentication cancelled by user\",\n CivicAuthErrorCode.USER_CANCELLED,\n );\n\n this.onAuthError(error);\n this.cleanup();\n },\n });\n\n // Create the iframe using IframeManager\n this.iframeElement = this.iframeManager.createIframe(fullAuthUrl);\n\n this.config.events?.emit(AuthEvent.SIGN_IN_STARTED, {\n detail: \"Iframe created with modal backdrop\",\n });\n\n this.setupIframeEventHandlers();\n this.setupIframeNavigationMonitoring();\n\n return this.iframeElement;\n }\n\n public getIframeManager(): IframeManager | undefined {\n return this.iframeManager;\n }\n\n public getIframeElement(): HTMLIFrameElement | undefined {\n return this.iframeElement;\n }\n\n public cleanupIframe(): void {\n this.logger.debug(\"Cleaning up iframe manager\");\n this.iframeManager?.cleanup();\n this.iframeManager = undefined;\n\n if (this.iframeElement) {\n this.iframeElement = undefined;\n }\n\n // Remove early auth success event listener\n if (this.earlyAuthSuccessHandler) {\n window.removeEventListener(\n \"civic-auth-success-early\",\n this.earlyAuthSuccessHandler as EventListener,\n );\n }\n\n // Clean up dynamically created modal containers\n this.cleanupDynamicModalContainer();\n }\n\n private cleanupDynamicModalContainer(): void {\n // Only clean up containers we created dynamically (not user-provided ones)\n if (!this.config.targetContainerElement) {\n const dynamicContainer = document.querySelector(\n `[data-civic-auth-modal=\"true\"]#${this.config.iframeId}-modal-container`,\n );\n\n if (dynamicContainer && dynamicContainer.parentNode) {\n this.logger.debug(\"Removing dynamic modal container\", {\n containerId: dynamicContainer.id,\n });\n dynamicContainer.parentNode.removeChild(dynamicContainer);\n }\n }\n }\n\n private createModalContainer(): HTMLElement {\n const container = document.createElement(\"div\");\n container.id = `${this.config.iframeId}-modal-container`;\n container.setAttribute(\"data-civic-auth-modal\", \"true\");\n\n // Append to body for modal overlay\n document.body.appendChild(container);\n\n this.logger.debug(\"Created dynamic modal container\", {\n containerId: container.id,\n });\n\n return container;\n }\n\n private getContainerElement(): HTMLElement | null {\n if (!this.config.targetContainerElement) {\n return null;\n }\n\n if (typeof this.config.targetContainerElement === \"string\") {\n const element = document.getElementById(\n this.config.targetContainerElement,\n );\n if (!element) {\n this.logger.warn(\n `Container element with ID \"${this.config.targetContainerElement}\" not found`,\n );\n }\n return element;\n }\n return this.config.targetContainerElement;\n }\n\n private determineIframeDisplayMode(): \"modal\" | \"embedded\" {\n // Priority 1: Explicit iframeDisplayMode setting from config\n // This is the most specific instruction for how the iframe itself should be styled.\n if (this.config.iframeDisplayMode) {\n this.logger.debug(\n `Using configured iframeDisplayMode: ${this.config.iframeDisplayMode}`,\n );\n return this.config.iframeDisplayMode;\n }\n\n // Priority 2: If iframeDisplayMode is NOT set, and the overall displayMode is \"iframe\",\n // default the iframe's own rendering style to \"modal\" (user-friendly default).\n // To get an embedded iframe, iframeDisplayMode: \"embedded\" should be set explicitly.\n if (this.config.displayMode === \"iframe\") {\n this.logger.debug(\n \"Overall displayMode is 'iframe' and iframeDisplayMode is not set, defaulting iframe style to 'modal'.\",\n );\n return \"modal\";\n }\n\n // Fallback for unexpected scenarios or if IframeAuthHandler is invoked with other displayModes.\n this.logger.warn(\n `determineIframeDisplayMode called with overall displayMode: '${this.config.displayMode}' ` +\n `and no explicit iframeDisplayMode. Defaulting iframe style to 'modal'.`,\n );\n return \"modal\";\n }\n\n private setupIframeEventHandlers(): void {\n if (!this.iframeElement) return;\n\n this.iframeElement.onload = () => {\n this.logger.info(\"Iframe loaded\", {\n iframeSrc: this.iframeElement?.src,\n currentOrigin: window.location.origin,\n expectedAuthServerOrigin: new URL(this.config.oauthServerBaseUrl)\n .origin,\n });\n\n if (!this.iframeElement?.contentWindow) {\n const errorMsg = \"Iframe content window not available after load.\";\n this.logger.error(errorMsg, {\n iframeSrc: this.iframeElement?.src,\n });\n\n const error = new Error(errorMsg);\n this.onAuthError(error);\n this.cleanup();\n return;\n }\n\n // Set up postMessage listener for cross-origin communication\n window.addEventListener(\"message\", this.messageHandler);\n this.logger.info(\n \"Added cross-origin message event listener for auth server communication\",\n {\n parentOrigin: window.location.origin,\n authServerOrigin: new URL(this.config.oauthServerBaseUrl).origin,\n },\n );\n\n // Hide iframe content if it's not the login app\n this.checkAndHideNonLoginContent();\n\n // Try to detect redirect to our domain\n this.checkIframeRedirect();\n };\n\n this.iframeElement.onerror = (event) => {\n this.logger.error(\"Iframe load error\", {\n event,\n iframeSrc: this.iframeElement?.src,\n currentOrigin: window.location.origin,\n });\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: \"Iframe load error\",\n error: event,\n });\n\n const error = new Error(\"Iframe failed to load.\");\n this.onAuthError(error);\n this.cleanup();\n };\n }\n\n private checkAndHideNonLoginContent(): void {\n try {\n const currentUrl = this.iframeElement?.contentWindow?.location.href;\n if (currentUrl) {\n const currentOrigin = new URL(currentUrl).origin;\n const expectedAuthServerOrigin = this.config.oauthServerBaseUrl\n ? new URL(this.config.oauthServerBaseUrl).origin\n : null;\n const isOnAuthServer = expectedAuthServerOrigin\n ? currentOrigin === expectedAuthServerOrigin\n : false;\n const isCallbackUrl = this.config.redirectUrl\n ? currentUrl.startsWith(this.config.redirectUrl)\n : false;\n\n if (isOnAuthServer && !isCallbackUrl) {\n this.logger.info(\n \"👀 Showing iframe content - confirmed login app on auth server origin\",\n {\n currentUrl,\n isOnAuthServer,\n isCallbackUrl,\n currentOrigin,\n expectedAuthServerOrigin,\n },\n );\n this.iframeManager?.forceHideLoader();\n } else {\n this.logger.info(\n \"🙈 Hiding iframe completely - not login app or on callback URL\",\n {\n currentUrl,\n isOnAuthServer,\n isCallbackUrl,\n currentOrigin,\n expectedAuthServerOrigin,\n reason: !isOnAuthServer\n ? expectedAuthServerOrigin\n ? \"not on auth server (origin mismatch)\"\n : \"auth server origin unknown\"\n : \"on callback URL (or origin mismatch for login page)\",\n },\n );\n\n if (isCallbackUrl) {\n this.iframeManager?.hide();\n } else {\n this.iframeManager?.forceShowLoader();\n }\n }\n }\n } catch (error) {\n this.logger.debug(\n \"Cannot access iframe URL (likely cross-origin) - assuming login app, showing content.\",\n { error: error instanceof Error ? error.message : String(error) },\n );\n setTimeout(() => {\n // Force hide loader after a short delay to ensure any initial loading is complete\n // to give the login-app time to send any post message signals\n this.iframeManager?.forceHideLoader();\n }, WAIT_FOR_LOGIN_APP_BROWSER_DETECTION_TIMEOUT);\n }\n }\n\n private checkIframeRedirect(): void {\n try {\n const currentIframeHref =\n this.iframeElement?.contentWindow?.location.href;\n\n if (currentIframeHref) {\n this.logger.debug(\"Iframe current href accessible\", {\n href: currentIframeHref,\n redirectUrl: this.config.redirectUrl,\n startsWithRedirect: currentIframeHref.startsWith(\n this.config.redirectUrl,\n ),\n });\n\n if (currentIframeHref.startsWith(this.config.redirectUrl)) {\n this.logger.info(\n \"Iframe has navigated to redirectUrl (same-origin). Setting up DOM observer.\",\n );\n\n // Hide content since we're on callback page now\n this.checkAndHideNonLoginContent();\n\n // Set up signal observer for same-origin callback page\n if (\n this.iframeElement?.contentDocument &&\n this.iframeElement.contentDocument.body\n ) {\n this.setupSignalObserver(this.iframeElement.contentDocument);\n } else {\n this.logger.warn(\n \"Iframe content document or body not available for signal observer\",\n );\n }\n }\n }\n } catch (error) {\n this.logger.debug(\n \"Error checking iframe href (expected for cross-origin)\",\n {\n error: error instanceof Error ? error.message : String(error),\n iframeSrc: this.iframeElement?.src,\n },\n );\n // This is expected when the iframe is on the auth server domain\n this.logger.info(\n \"Iframe is on auth server domain - using postMessage for communication\",\n {\n parentOrigin: window.location.origin,\n authServerOrigin: new URL(this.config.oauthServerBaseUrl).origin,\n },\n );\n }\n }\n\n private setupSignalObserver(iframeDoc: Document): void {\n const signalObserver = new SignalObserver(\n {\n textSignals: this.config.textSignals,\n events: this.config.events,\n logger: this.logger,\n },\n this.onAuthSuccess,\n (error?: Error) =>\n this.onAuthError(error || new Error(\"Signal observer error\")),\n () => this.cleanup(),\n );\n\n signalObserver.setup(iframeDoc);\n }\n\n private setupIframeNavigationMonitoring(): void {\n // Monitor iframe navigation to detect when it redirects to our callback URL\n let monitoringInterval: number | undefined = undefined;\n let lastKnownUrl = \"\";\n\n const checkIframeNavigation = () => {\n if (!this.iframeElement?.contentWindow) {\n if (monitoringInterval) {\n clearInterval(monitoringInterval);\n }\n return;\n }\n\n try {\n const currentUrl = this.iframeElement.contentWindow.location.href;\n\n if (currentUrl !== lastKnownUrl) {\n lastKnownUrl = currentUrl;\n this.logger.debug(\"Iframe navigation detected\", {\n newUrl: currentUrl,\n redirectUrl: this.config.redirectUrl,\n isCallbackUrl: currentUrl.startsWith(this.config.redirectUrl),\n });\n\n // Check if iframe has navigated to our callback URL\n if (currentUrl.startsWith(this.config.redirectUrl)) {\n // Hide immediately on callback URL detection\n this.iframeManager?.hide();\n this.logger.info(\n \"Iframe navigated to callback URL - setting up signal observer\",\n );\n\n if (monitoringInterval) {\n clearInterval(monitoringInterval);\n }\n\n // Set up signal observer for same-origin callback page\n if (\n this.iframeElement.contentDocument &&\n this.iframeElement.contentDocument.body\n ) {\n this.setupSignalObserver(this.iframeElement.contentDocument);\n }\n\n // Also check for URL parameters (code, error) in case of direct callback\n this.processCallbackUrl(currentUrl);\n } else {\n // Hide content if not on login app\n this.checkAndHideNonLoginContent();\n }\n }\n } catch {\n // Expected when iframe is on different origin\n // Only log if we haven't seen this before\n if (lastKnownUrl !== \"cross-origin\") {\n lastKnownUrl = \"cross-origin\";\n this.logger.debug(\n \"Iframe on cross-origin domain (expected during auth flow)\",\n );\n }\n }\n };\n\n // Check immediately and then every 100ms for faster detection\n checkIframeNavigation();\n monitoringInterval = window.setInterval(checkIframeNavigation, 100);\n\n // Store cleanup function to clear monitoring\n const originalCleanup = this.cleanup;\n this.cleanup = () => {\n if (monitoringInterval) {\n clearInterval(monitoringInterval);\n }\n originalCleanup();\n };\n }\n\n private processCallbackUrl(currentUrl: string): void {\n const urlParams = new URLSearchParams(new URL(currentUrl).search);\n const code = urlParams.get(\"code\");\n const error = urlParams.get(\"error\");\n\n if (code) {\n this.logger.info(\"Authorization code detected in iframe URL\", {\n code: code.substring(0, 10) + \"...\",\n hasState: !!urlParams.get(\"state\"),\n });\n }\n\n if (error) {\n this.logger.error(\"OAuth error detected in iframe URL\", {\n error,\n errorDescription: urlParams.get(\"error_description\"),\n });\n\n const authError = new CivicAuthError(\n `OAuth error: ${error}`,\n CivicAuthErrorCode.INVALID_MESSAGE,\n );\n\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: authError.message,\n error: urlParams.get(\"error_description\") || error,\n });\n\n this.onAuthError(authError);\n }\n }\n\n public navigateIframe(url: string): void {\n if (!this.iframeElement) {\n this.logger.error(\n \"Cannot navigate iframe, iframeElement is not available.\",\n );\n this.onAuthError(\n new CivicAuthError(\n \"Iframe element not found for navigation.\",\n CivicAuthErrorCode.IFRAME_NOT_FOUND,\n ),\n );\n return;\n }\n if (!this.iframeManager) {\n this.logger.error(\n \"Cannot navigate iframe, iframeManager is not available.\",\n );\n this.onAuthError(\n new CivicAuthError(\n \"Iframe manager not found for navigation.\",\n CivicAuthErrorCode.INTERNAL_ERROR,\n ),\n );\n return;\n }\n this.logger.info(\"Navigating iframe to new URL\", { url });\n this.iframeElement.src = url;\n // After changing src, existing onload/onmessage handlers in IframeManager\n // and navigation monitoring in this class should manage visibility and state.\n }\n\n /**\n * Enable or disable iframe preloading\n */\n public setPreloadEnabled(enabled: boolean): void {\n this.isPreloadEnabled = enabled;\n this.logger.debug(\"Iframe preloading\", { enabled });\n }\n\n /**\n * Check if iframe preloading is enabled\n */\n public getPreloadEnabled(): boolean {\n return this.isPreloadEnabled;\n }\n\n /**\n * Check if an iframe is currently preloaded and ready for instant display\n *\n * This function helps optimize user experience by determining if we can show\n * a preloaded iframe immediately instead of loading a new one. The logic:\n *\n * 1. Returns false if no iframe manager exists (can't have preloaded content)\n * 2. Checks if any iframe is currently preloaded via the iframe manager\n * 3. If no specific URL is provided, returns whether any iframe is preloaded\n * 4. If a URL is provided, ensures both that an iframe is preloaded AND\n * that it contains the exact URL we need\n *\n * This prevents unnecessary iframe reloads when the user triggers auth flows\n * with the same URL that's already loaded and ready to display.\n *\n * @param url - Optional URL to match against the preloaded iframe's URL\n * @returns true if a suitable preloaded iframe exists, false otherwise\n */\n public hasPreloadedIframe(url?: string): boolean {\n if (!this.iframeManager) return false;\n\n const isPreloaded = this.iframeManager.isIframePreloaded();\n if (!url) return isPreloaded;\n\n return isPreloaded && this.iframeManager.getPreloadedUrl() === url;\n }\n\n /**\n * Force the iframe to hide, even if it is currently showing\n *\n * This is useful for cleanup or when you want to ensure the iframe is not visible\n * regardless of its current state.\n */\n public forceHideIframe(): void {\n if (this.iframeManager) {\n this.iframeManager.hide();\n this.logger.debug(\"Forced iframe to hide\");\n } else {\n this.logger.warn(\n \"Cannot force hide iframe, iframe manager not initialized\",\n );\n }\n }\n\n /**\n * Force the iframe to show the loading indicator\n */\n public forceShowLoader(): void {\n if (this.iframeManager) {\n this.iframeManager.forceShowLoader();\n this.logger.debug(\"Forced iframe loader to show\");\n } else {\n this.logger.warn(\n \"Cannot force show loader, iframe manager not initialized\",\n );\n }\n }\n}\n"]}
|
|
@@ -8,6 +8,7 @@ export interface MessageHandlerConfig {
|
|
|
8
8
|
onAuthSuccess: (result: AuthResult) => void;
|
|
9
9
|
onAuthError: (error: Error) => void;
|
|
10
10
|
onPopupFailure: (failedUrl?: string) => void;
|
|
11
|
+
onBrowserCorsFailsSilently: (failedUrl?: string) => Promise<void>;
|
|
11
12
|
cleanup: () => void;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
@@ -21,6 +22,7 @@ export declare class MessageHandler {
|
|
|
21
22
|
private onAuthSuccess;
|
|
22
23
|
private onAuthError;
|
|
23
24
|
private onPopupFailure;
|
|
25
|
+
private onBrowserCorsFailsSilently;
|
|
24
26
|
private cleanup;
|
|
25
27
|
private customExpectedOrigin?;
|
|
26
28
|
constructor(handlerConfig: MessageHandlerConfig);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageHandler.d.ts","sourceRoot":"","sources":["../../../../src/vanillajs/auth/handlers/MessageHandler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAIV,wBAAwB,EACzB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAI1D,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,wBAAwB,CAAC;IACjC,MAAM,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;IACxC,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,aAAa,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IAC5C,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACpC,cAAc,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,MAAM,CAAqC;IACnD,OAAO,CAAC,aAAa,CAAC,CAAoB;IAC1C,OAAO,CAAC,aAAa,CAA+B;IACpD,OAAO,CAAC,WAAW,CAAyB;IAC5C,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,OAAO,CAAa;IAG5B,OAAO,CAAC,oBAAoB,CAAC,CAAS;gBAE1B,aAAa,EAAE,oBAAoB;
|
|
1
|
+
{"version":3,"file":"MessageHandler.d.ts","sourceRoot":"","sources":["../../../../src/vanillajs/auth/handlers/MessageHandler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,U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;;;;;;OAQG;IACH,OAAO,CAAC,kBAAkB;IAa1B;;;;;;;;;OASG;IACH,OAAO,CAAC,oBAAoB;IAyD5B;;;;;;;OAOG;IACH,OAAO,CAAC,kBAAkB;IAoC1B;;;;;;;;OAQG;IACH,OAAO,CAAC,sBAAsB;IAS9B;;;;;;;;OAQG;IACH,OAAO,CAAC,0BAA0B;IA6DlC;;;;;;;OAOG;IAEH,OAAO,CAAC,sBAAsB;IAc9B;;;;;;;OAOG;IACH,OAAO,CAAC,wBAAwB;IAoBhC;;;;;OAKG;IACH,OAAO,CAAC,8BAA8B;IAkBtC;;;;;;;;OAQG;IACH,OAAO,CAAC,kBAAkB;IA2B1B;;;;;;;OAOG;IACH,OAAO,CAAC,iCAAiC;IAqBzC;;;;;;;;OAQG;IACH,OAAO,CAAC,sBAAsB;IAY9B;;;;;;;OAOG;IACH,OAAO,CAAC,0BAA0B;IAYlC;;;;;;;OAOG;IACH,OAAO,CAAC,yBAAyB;IAmCjC;;;;;;;OAOG;IACH,OAAO,CAAC,iBAAiB;IASzB;;;;;;;OAOG;IACH,OAAO,CAAC,eAAe;CAcxB"}
|
|
@@ -13,6 +13,9 @@ export class MessageHandler {
|
|
|
13
13
|
onAuthSuccess;
|
|
14
14
|
onAuthError;
|
|
15
15
|
onPopupFailure;
|
|
16
|
+
onBrowserCorsFailsSilently = () => {
|
|
17
|
+
return Promise.resolve(); // No-op by default, can be overridden
|
|
18
|
+
};
|
|
16
19
|
cleanup;
|
|
17
20
|
// Backend integration - custom expected origin
|
|
18
21
|
customExpectedOrigin;
|
|
@@ -22,6 +25,7 @@ export class MessageHandler {
|
|
|
22
25
|
this.onAuthSuccess = handlerConfig.onAuthSuccess;
|
|
23
26
|
this.onAuthError = handlerConfig.onAuthError;
|
|
24
27
|
this.onPopupFailure = handlerConfig.onPopupFailure;
|
|
28
|
+
this.onBrowserCorsFailsSilently = handlerConfig.onBrowserCorsFailsSilently;
|
|
25
29
|
this.cleanup = handlerConfig.cleanup;
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
@@ -315,11 +319,14 @@ export class MessageHandler {
|
|
|
315
319
|
this.logger.warn("civicloginApp browser CORS fail silently", {
|
|
316
320
|
failedUrl,
|
|
317
321
|
config: this.config,
|
|
322
|
+
autoRedirect: this.config.autoRedirect,
|
|
318
323
|
});
|
|
319
324
|
if (this.config.displayMode === "iframe" &&
|
|
320
325
|
this.config.iframeDisplayMode === "modal" &&
|
|
326
|
+
this.config.autoRedirect !== false && // Add this check
|
|
321
327
|
failedUrl) {
|
|
322
328
|
IframeManager.handleBrowserCorsFailsSilently(failedUrl);
|
|
329
|
+
this.onBrowserCorsFailsSilently(failedUrl);
|
|
323
330
|
}
|
|
324
331
|
}
|
|
325
332
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageHandler.js","sourceRoot":"","sources":["../../../../src/vanillajs/auth/handlers/MessageHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAQjD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3E,OAAO,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAYpE;;;GAGG;AACH,MAAM,OAAO,cAAc;IACjB,MAAM,CAA2B;IACjC,MAAM,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC;IAC3C,aAAa,CAAqB;IAClC,aAAa,CAA+B;IAC5C,WAAW,CAAyB;IACpC,cAAc,CAA+B;IAC7C,OAAO,CAAa;IAE5B,+CAA+C;IACvC,oBAAoB,CAAU;IAEtC,YAAY,aAAmC;QAC7C,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;QACnC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC,aAAa,CAAC;QACjD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC,aA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AE,uCAAuC;YAC/C,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,IAAI,cAAc,CAC9B,IAAI,EAAE,MAAM,IAAI,uCAAuC,EACvD,kBAAkB,CAAC,eAAe,CACnC,CAAC;QAEF,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACxB,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;CACF","sourcesContent":["import { AuthEvent } from \"../../types/index.js\";\nimport type { AuthResult } from \"../../types/index.js\";\nimport type {\n IframeMessage,\n AuthMessage,\n LoginAppMessage,\n ProcessedCivicAuthConfig,\n} from \"../types/AuthTypes.js\";\nimport { CivicAuthError, CivicAuthErrorCode } from \"../types/AuthTypes.js\";\nimport type { createLogger } from \"../../utils/logger.js\";\nimport { createLogger as createLoggerFn } from \"../../utils/logger.js\";\nimport { IframeManager } from \"@/vanillajs/iframe/IframeManager.js\";\n\nexport interface MessageHandlerConfig {\n config: ProcessedCivicAuthConfig;\n logger: ReturnType<typeof createLogger>;\n iframeElement?: HTMLIFrameElement;\n onAuthSuccess: (result: AuthResult) => void;\n onAuthError: (error: Error) => void;\n onPopupFailure: (failedUrl?: string) => void;\n cleanup: () => void;\n}\n\n/**\n * MessageHandler - Handles postMessage communication and authentication flow logic\n * Processes messages from iframe, validates origins, and manages auth state transitions\n */\nexport class MessageHandler {\n private config: ProcessedCivicAuthConfig;\n private logger = createLoggerFn(\"message-handler\");\n private iframeElement?: HTMLIFrameElement;\n private onAuthSuccess: (result: AuthResult) => void;\n private onAuthError: (error: Error) => void;\n private onPopupFailure: (failedUrl?: string) => void;\n private cleanup: () => void;\n\n // Backend integration - custom expected origin\n private customExpectedOrigin?: string;\n\n constructor(handlerConfig: MessageHandlerConfig) {\n this.config = handlerConfig.config;\n this.iframeElement = handlerConfig.iframeElement;\n this.onAuthSuccess = handlerConfig.onAuthSuccess;\n this.onAuthError = handlerConfig.onAuthError;\n this.onPopupFailure = handlerConfig.onPopupFailure;\n this.cleanup = handlerConfig.cleanup;\n }\n\n /**\n * Updates the iframe element reference used for message validation.\n *\n * This method allows updating the iframe element after the MessageHandler\n * has been instantiated, which is useful when the iframe is created\n * dynamically after the handler setup.\n *\n * @param iframeElement - The new iframe element to associate with this handler\n */\n public updateIframeElement(iframeElement: HTMLIFrameElement): void {\n this.iframeElement = iframeElement;\n }\n\n /**\n * Sets a custom expected origin for backend integration.\n *\n * This allows the MessageHandler to accept messages from a custom backend\n * origin instead of the default OAuth server origin.\n *\n * @param customLoginUrl - The custom login URL to derive the origin from\n */\n public setCustomExpectedOrigin(customLoginUrl: string): void {\n this.customExpectedOrigin = new URL(customLoginUrl).origin;\n this.logger.info(\"🔗 Custom expected origin set for backend integration\", {\n customExpectedOrigin: this.customExpectedOrigin,\n customLoginUrl,\n });\n }\n\n /**\n * Clears the custom expected origin and returns to OAuth server origin.\n */\n public clearCustomExpectedOrigin(): void {\n this.customExpectedOrigin = undefined;\n this.logger.info(\n \"🔗 Custom expected origin cleared, returning to OAuth server origin\",\n );\n }\n\n /**\n * Main message handler for processing postMessage events.\n *\n * Validates message origin and source, then routes valid messages to\n * appropriate handlers. This is the entry point for all iframe communication.\n *\n * @param event - The MessageEvent received from the iframe or other sources\n */\n public handleMessage = (event: MessageEvent): void => {\n // Use custom origin if set (for backend integration), otherwise use OAuth server origin\n const expectedOrigin =\n this.customExpectedOrigin ||\n new URL(this.config.oauthServerBaseUrl).origin;\n this.logIncomingMessage(event, expectedOrigin);\n\n if (!this.isValidMessageSource(event, expectedOrigin)) {\n return;\n }\n\n this.handleValidMessage(event);\n };\n\n /**\n * Logs incoming message details for debugging purposes.\n *\n * Provides comprehensive logging of message properties including origin,\n * source validation, and iframe state for troubleshooting communication issues.\n *\n * @param event - The MessageEvent to log\n * @param expectedOrigin - The expected origin for comparison\n */\n private logIncomingMessage(\n event: MessageEvent,\n expectedOrigin: string,\n ): void {\n this.logger.debug(\"Global window received message:\", {\n data: event.data,\n origin: event.origin,\n sourceProvided: !!event.source,\n iframeContentWindow: this.iframeElement?.contentWindow,\n expectedIframeOrigin: expectedOrigin,\n });\n }\n\n /**\n * Validates that a message comes from the expected origin and source.\n *\n * Performs security checks to ensure messages are only processed from\n * the configured OAuth server origin and the designated iframe element.\n *\n * @param event - The MessageEvent to validate\n * @param expectedOrigin - The expected origin URL for the message\n * @returns True if the message source and origin are valid, false otherwise\n */\n private isValidMessageSource(\n event: MessageEvent,\n expectedOrigin: string,\n ): boolean {\n // Check if message is from the iframe source\n const isValidSource = event.source === this.iframeElement?.contentWindow;\n\n // Build list of allowed origins\n const allowedOrigins = [expectedOrigin];\n\n // Add the actual iframe origin (to handle redirects)\n if (this.iframeElement?.src) {\n try {\n const actualIframeOrigin = new URL(this.iframeElement.src).origin;\n allowedOrigins.push(actualIframeOrigin);\n } catch {\n // ignore URL parsing errors\n }\n }\n\n // Add the client app's own origin (same-origin) for messages sent after token exchange\n // This is needed when the iframe navigates to the client app's callback URL\n const clientOrigin = window.location.origin;\n if (!allowedOrigins.includes(clientOrigin)) {\n allowedOrigins.push(clientOrigin);\n }\n\n // Add common development login app origins for localhost\n const expectedUrl = new URL(expectedOrigin);\n if (expectedUrl.hostname === \"localhost\") {\n // For localhost, also allow common development ports\n allowedOrigins.push(\"http://localhost:3004\"); // default login-app port\n allowedOrigins.push(\"http://localhost:3001\"); // auth server port\n }\n\n const isValidOrigin = allowedOrigins.includes(event.origin);\n\n if (!isValidOrigin) {\n this.logger.warn(\"Ignored message from unexpected origin.\", {\n receivedOrigin: event.origin,\n expectedOrigin,\n allowedOrigins,\n iframeSrc: this.iframeElement?.src,\n });\n }\n\n if (!isValidSource) {\n this.logger.warn(\"Ignored message from unexpected source.\", {\n isSourceProvided: !!event.source,\n isIframeContentWindowAvailable: !!this.iframeElement?.contentWindow,\n iframeSrc: this.iframeElement?.src,\n });\n }\n\n return isValidOrigin && isValidSource;\n }\n\n /**\n * Processes messages that have passed origin and source validation.\n *\n * Routes validated messages to specific handlers based on message type,\n * including civicloginApp messages, iframe resizer messages, and standard auth messages.\n *\n * @param event - The validated MessageEvent to process\n */\n private handleValidMessage(event: MessageEvent): void {\n this.logger.info(\n \"Message from configured iframe source and origin received\",\n {\n data: event.data,\n iframeSrc: this.iframeElement?.src,\n },\n );\n\n const message = event.data as IframeMessage;\n\n this.logger.debug(\"Processing iframe message\", {\n messageType: typeof message,\n hasType: message && typeof message === \"object\" && \"type\" in message,\n hasSource: message && typeof message === \"object\" && \"source\" in message,\n messageKeys:\n message && typeof message === \"object\" ? Object.keys(message) : [],\n rawData: message,\n });\n\n // Handle civicloginApp messages\n if (this.isCivicLoginAppMessage(message)) {\n this.handleCivicLoginAppMessage(message);\n return;\n }\n\n // Handle iframe resizer messages\n if (this.isIframeResizerMessage(message)) {\n this.handleIframeResizerMessage(message);\n return;\n }\n\n // Handle standard auth messages\n this.handleStandardAuthMessage(message);\n }\n\n /**\n * Type guard to identify civicloginApp messages.\n *\n * Checks if a message object has the structure and source property\n * that identifies it as coming from the civicloginApp.\n *\n * @param message - The message object to check\n * @returns True if the message is a LoginAppMessage, false otherwise\n */\n private isCivicLoginAppMessage(message: unknown): message is LoginAppMessage {\n return (\n message !== null &&\n typeof message === \"object\" &&\n \"source\" in message &&\n (message as Record<string, unknown>).source === \"civicloginApp\"\n );\n }\n\n /**\n * Handles messages originating from the civicloginApp.\n *\n * Processes various civicloginApp message types including authentication errors,\n * popup failures, design updates, and other app-specific communications.\n * Validates client ID matches before processing.\n *\n * @param message - The validated civicloginApp message to process\n */\n private handleCivicLoginAppMessage(message: LoginAppMessage): void {\n this.logger.info(\"Received civicloginApp message\", {\n type: message.type,\n clientId: message.clientId,\n data: message.data,\n });\n\n // Validate clientId matches our config\n if (\n message.clientId !== this.config.clientId &&\n this.config.loginUrl === undefined\n ) {\n this.logger.warn(\"civicloginApp message clientId mismatch\", {\n received: message.clientId,\n expected: this.config.clientId,\n });\n return;\n }\n\n switch (message.type) {\n case \"auth_error\":\n case \"auth_error_try_again\":\n this.handleCivicLoginAppError(message);\n break;\n case \"generatePopupFailed\":\n this.handlePopupFailure(message);\n break;\n case \"browserCorsFailsSilently\":\n this.handleBrowserCorsFailsSilently(message);\n break;\n case \"design\":\n this.logger.debug(\"civicloginApp design message\", {\n data: message.data,\n });\n break;\n case \"auth_success_early\":\n this.logger.info(\"civicloginApp auth success early message\", {\n data: message.data,\n });\n this.handleAuthSuccessEarly(message);\n break;\n case \"auth_success\":\n this.logger.info(\"civicloginApp auth success message\", {\n data: message.data,\n });\n\n // Dispatch early auth success event for immediate modal closing\n\n // Still handle auth success normally (for callback processing)\n this.handleAuthSuccess({\n type: \"auth_success\",\n detail: \"Authentication successful\",\n data: message.data,\n });\n break;\n default:\n this.handleUnknownCivicLoginAppMessage(message);\n break;\n }\n }\n\n /**\n * Handles auth success early messages from civicloginApp.\n *\n * Processes auth_success_early messages, emits success events,\n * and triggers the success callback with authentication results.\n *\n * @param message - The civicloginApp auth success early message to process\n */\n\n private handleAuthSuccessEarly(message: LoginAppMessage): void {\n this.logger.info(\"civicloginApp auth success early message\", {\n data: message.data,\n });\n\n const earlySuccessEvent = new CustomEvent(\"civic-auth-success-early\", {\n detail: {\n clientId: message.clientId,\n data: message.data,\n },\n });\n window.dispatchEvent(earlySuccessEvent);\n }\n\n /**\n * Handles authentication error messages from civicloginApp.\n *\n * Processes auth_error and auth_error_try_again messages, creates\n * appropriate error objects, emits error events, and triggers cleanup.\n *\n * @param message - The civicloginApp error message to process\n */\n private handleCivicLoginAppError(message: LoginAppMessage): void {\n this.logger.error(\"civicloginApp authentication error\", {\n type: message.type,\n data: message.data,\n });\n\n const error = new CivicAuthError(\n `Login app error: ${message.type}`,\n CivicAuthErrorCode.INVALID_MESSAGE,\n );\n\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: error.message,\n error: message.data,\n });\n\n this.onAuthError(error);\n this.cleanup();\n }\n\n /**\n * Handle the case where we know in advance that the browser will not prompt the user to open\n * a popup and will fail silently instead. We want to handle this case gracefully by switching to redirect\n * mode if the iframe is in modal display mode. This will be done when the auth flow actually starts\n * @param message\n */\n private handleBrowserCorsFailsSilently(message: LoginAppMessage): void {\n const failedUrl = (message.data as Record<string, unknown> | undefined)\n ?.url as string | undefined;\n this.logger.warn(\"civicloginApp browser CORS fail silently\", {\n failedUrl,\n config: this.config,\n });\n if (\n this.config.displayMode === \"iframe\" &&\n this.config.iframeDisplayMode === \"modal\" &&\n failedUrl\n ) {\n IframeManager.handleBrowserCorsFailsSilently(failedUrl);\n }\n }\n /**\n * Handles popup generation failure messages from civicloginApp.\n *\n * Processes generatePopupFailed messages, extracts the failed URL,\n * emits appropriate events, and triggers the popup failure callback\n * to enable fallback authentication methods.\n *\n * @param message - The civicloginApp popup failure message to process\n */\n private handlePopupFailure(message: LoginAppMessage): void {\n this.logger.warn(\"civicloginApp popup generation failed\", {\n data: message.data,\n });\n\n const failedUrl = (message.data as Record<string, unknown> | undefined)\n ?.url as string | undefined;\n if (failedUrl) {\n this.logger.info(\"Popup failed for URL, considering fallback options\", {\n failedUrl,\n displayMode: this.config.displayMode,\n });\n\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: \"Popup blocked by browser - switching to redirect mode\",\n error: {\n type: \"popup_blocked\",\n failedUrl,\n suggestion:\n \"The browser blocked a popup window. Redirecting to complete authentication in a new page.\",\n },\n });\n }\n\n this.onPopupFailure(failedUrl);\n }\n\n /**\n * Handles unknown or unrecognized civicloginApp message types.\n *\n * Provides fallback handling for unexpected message types, with special\n * logic to detect potential success messages that don't match standard types.\n *\n * @param message - The unrecognized civicloginApp message to process\n */\n private handleUnknownCivicLoginAppMessage(message: LoginAppMessage): void {\n this.logger.debug(\"Unhandled civicloginApp message type\", {\n type: message.type,\n data: message.data,\n });\n\n // Check if this might be a success message with a different type\n if (message.type && message.type.toLowerCase().includes(\"success\")) {\n this.logger.info(\"Potential success message from civicloginApp\", {\n type: message.type,\n data: message.data,\n });\n\n this.handleAuthSuccess({\n type: \"auth_success\",\n detail: `civicloginApp success: ${message.type}`,\n data: message.data,\n });\n }\n }\n\n /**\n * Type guard to identify iframe resizer messages.\n *\n * Checks if a message is related to iframe resizing functionality,\n * including both civic-specific resize messages and iFrameResizerChild messages.\n *\n * @param message - The message object to check\n * @returns True if the message is an iframe resizer message, false otherwise\n */\n private isIframeResizerMessage(message: unknown): boolean {\n return (\n (message !== null &&\n typeof message === \"object\" &&\n \"type\" in message &&\n ((message as Record<string, unknown>).type === \"civic-iframe-resize\" ||\n (message as Record<string, unknown>).type ===\n \"civic-iframe-ready\")) ||\n (typeof message === \"string\" && message.includes(\"iFrameResizerChild\"))\n );\n }\n\n /**\n * Handles iframe resizer messages for dynamic iframe sizing.\n *\n * Processes messages related to iframe resizing, including height adjustments\n * and ready state notifications from the iframe resizer library.\n *\n * @param message - The iframe resizer message to process\n */\n private handleIframeResizerMessage(message: unknown): void {\n if (typeof message === \"string\") {\n this.logger.debug(\"Received iframe resizer child message\", { message });\n } else if (message && typeof message === \"object\" && message !== null) {\n const messageObj = message as Record<string, unknown>;\n this.logger.debug(\"Received iframe resizer message\", {\n type: messageObj.type,\n height: messageObj.height,\n });\n }\n }\n\n /**\n * Handles standard authentication messages.\n *\n * Processes auth_success and auth_error messages that follow the standard\n * authentication message format, routing them to appropriate success or error handlers.\n *\n * @param message - The standard auth message to process\n */\n private handleStandardAuthMessage(message: unknown): void {\n const messageObj =\n message && typeof message === \"object\" && message !== null\n ? (message as Record<string, unknown>)\n : null;\n const messageType = messageObj?.type;\n\n switch (messageType) {\n case \"auth_success\":\n this.handleAuthSuccess(message as AuthMessage);\n break;\n case \"auth_error\":\n this.handleAuthError(message as AuthMessage);\n break;\n default:\n // Check if this is a calculateSubFramePositioning message (expected and harmless)\n if (messageObj?.command === \"calculateSubFramePositioning\") {\n this.logger.debug(\"Received iframe positioning message (expected)\", {\n command: messageObj.command,\n hasSubFrameData: !!messageObj.subFrameData,\n });\n } else {\n this.logger.debug(\n \"Message from iframe did not match expected types (auth_success, auth_error, civicloginApp, iframe-resizer)\",\n {\n data: message,\n messageType: typeof message,\n hasType: messageObj?.type ?? \"none\",\n messageKeys: messageObj ? Object.keys(messageObj) : [],\n },\n );\n }\n }\n }\n\n /**\n * Handles successful authentication completion.\n *\n * Processes authentication success messages, emits success events,\n * triggers the success callback with authentication results, and performs cleanup.\n *\n * @param data - The authentication success message containing result data\n */\n private handleAuthSuccess(data: AuthMessage): void {\n this.config.events?.emit(AuthEvent.SIGN_IN_COMPLETE, {\n detail: \"Success signal received via postMessage\",\n data,\n });\n this.onAuthSuccess((data?.data as AuthResult) || {});\n this.cleanup();\n }\n\n /**\n * Handles authentication errors.\n *\n * Processes authentication error messages, creates appropriate error objects,\n * emits error events, triggers the error callback, and performs cleanup.\n *\n * @param data - The authentication error message containing error details\n */\n private handleAuthError(data: AuthMessage): void {\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: \"Error signal received via postMessage\",\n error: data,\n });\n\n const error = new CivicAuthError(\n data?.detail || \"Error signal received via postMessage\",\n CivicAuthErrorCode.INVALID_MESSAGE,\n );\n\n this.onAuthError(error);\n this.cleanup();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MessageHandler.js","sourceRoot":"","sources":["../../../../src/vanillajs/auth/handlers/MessageHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAQjD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3E,OAAO,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAapE;;;GAGG;AACH,MAAM,OAAO,cAAc;IACjB,MAAM,CAA2B;IACjC,MAAM,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC;IAC3C,aAAa,CAAqB;IAClC,aAAa,CAA+B;IAC5C,WAAW,CAAyB;IACpC,cAAc,CAA+B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C,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE;qBACvD,CACF,CAAC;gBACJ,CAAC;QACL,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,iBAAiB,CAAC,IAAiB;QACzC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE;YACnD,MAAM,EAAE,yCAAyC;YACjD,IAAI;SACL,CAAC,CAAC;QACH,IAAI,CAAC,aAAa,CAAE,IAAI,EAAE,IAAmB,IAAI,EAAE,CAAC,CAAC;QACrD,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED;;;;;;;OAOG;IACK,eAAe,CAAC,IAAiB;QACvC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;YAChD,MAAM,EAAE,uCAAuC;YAC/C,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,IAAI,cAAc,CAC9B,IAAI,EAAE,MAAM,IAAI,uCAAuC,EACvD,kBAAkB,CAAC,eAAe,CACnC,CAAC;QAEF,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QACxB,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;CACF","sourcesContent":["import { AuthEvent } from \"../../types/index.js\";\nimport type { AuthResult } from \"../../types/index.js\";\nimport type {\n IframeMessage,\n AuthMessage,\n LoginAppMessage,\n ProcessedCivicAuthConfig,\n} from \"../types/AuthTypes.js\";\nimport { CivicAuthError, CivicAuthErrorCode } from \"../types/AuthTypes.js\";\nimport type { createLogger } from \"../../utils/logger.js\";\nimport { createLogger as createLoggerFn } from \"../../utils/logger.js\";\nimport { IframeManager } from \"@/vanillajs/iframe/IframeManager.js\";\n\nexport interface MessageHandlerConfig {\n config: ProcessedCivicAuthConfig;\n logger: ReturnType<typeof createLogger>;\n iframeElement?: HTMLIFrameElement;\n onAuthSuccess: (result: AuthResult) => void;\n onAuthError: (error: Error) => void;\n onPopupFailure: (failedUrl?: string) => void;\n onBrowserCorsFailsSilently: (failedUrl?: string) => Promise<void>;\n cleanup: () => void;\n}\n\n/**\n * MessageHandler - Handles postMessage communication and authentication flow logic\n * Processes messages from iframe, validates origins, and manages auth state transitions\n */\nexport class MessageHandler {\n private config: ProcessedCivicAuthConfig;\n private logger = createLoggerFn(\"message-handler\");\n private iframeElement?: HTMLIFrameElement;\n private onAuthSuccess: (result: AuthResult) => void;\n private onAuthError: (error: Error) => void;\n private onPopupFailure: (failedUrl?: string) => void;\n private onBrowserCorsFailsSilently: (failedUrl?: string) => Promise<void> =\n () => {\n return Promise.resolve(); // No-op by default, can be overridden\n };\n private cleanup: () => void;\n\n // Backend integration - custom expected origin\n private customExpectedOrigin?: string;\n\n constructor(handlerConfig: MessageHandlerConfig) {\n this.config = handlerConfig.config;\n this.iframeElement = handlerConfig.iframeElement;\n this.onAuthSuccess = handlerConfig.onAuthSuccess;\n this.onAuthError = handlerConfig.onAuthError;\n this.onPopupFailure = handlerConfig.onPopupFailure;\n this.onBrowserCorsFailsSilently = handlerConfig.onBrowserCorsFailsSilently;\n this.cleanup = handlerConfig.cleanup;\n }\n\n /**\n * Updates the iframe element reference used for message validation.\n *\n * This method allows updating the iframe element after the MessageHandler\n * has been instantiated, which is useful when the iframe is created\n * dynamically after the handler setup.\n *\n * @param iframeElement - The new iframe element to associate with this handler\n */\n public updateIframeElement(iframeElement: HTMLIFrameElement): void {\n this.iframeElement = iframeElement;\n }\n\n /**\n * Sets a custom expected origin for backend integration.\n *\n * This allows the MessageHandler to accept messages from a custom backend\n * origin instead of the default OAuth server origin.\n *\n * @param customLoginUrl - The custom login URL to derive the origin from\n */\n public setCustomExpectedOrigin(customLoginUrl: string): void {\n this.customExpectedOrigin = new URL(customLoginUrl).origin;\n this.logger.info(\"🔗 Custom expected origin set for backend integration\", {\n customExpectedOrigin: this.customExpectedOrigin,\n customLoginUrl,\n });\n }\n\n /**\n * Clears the custom expected origin and returns to OAuth server origin.\n */\n public clearCustomExpectedOrigin(): void {\n this.customExpectedOrigin = undefined;\n this.logger.info(\n \"🔗 Custom expected origin cleared, returning to OAuth server origin\",\n );\n }\n\n /**\n * Main message handler for processing postMessage events.\n *\n * Validates message origin and source, then routes valid messages to\n * appropriate handlers. This is the entry point for all iframe communication.\n *\n * @param event - The MessageEvent received from the iframe or other sources\n */\n public handleMessage = (event: MessageEvent): void => {\n // Use custom origin if set (for backend integration), otherwise use OAuth server origin\n const expectedOrigin =\n this.customExpectedOrigin ||\n new URL(this.config.oauthServerBaseUrl).origin;\n this.logIncomingMessage(event, expectedOrigin);\n\n if (!this.isValidMessageSource(event, expectedOrigin)) {\n return;\n }\n\n this.handleValidMessage(event);\n };\n\n /**\n * Logs incoming message details for debugging purposes.\n *\n * Provides comprehensive logging of message properties including origin,\n * source validation, and iframe state for troubleshooting communication issues.\n *\n * @param event - The MessageEvent to log\n * @param expectedOrigin - The expected origin for comparison\n */\n private logIncomingMessage(\n event: MessageEvent,\n expectedOrigin: string,\n ): void {\n this.logger.debug(\"Global window received message:\", {\n data: event.data,\n origin: event.origin,\n sourceProvided: !!event.source,\n iframeContentWindow: this.iframeElement?.contentWindow,\n expectedIframeOrigin: expectedOrigin,\n });\n }\n\n /**\n * Validates that a message comes from the expected origin and source.\n *\n * Performs security checks to ensure messages are only processed from\n * the configured OAuth server origin and the designated iframe element.\n *\n * @param event - The MessageEvent to validate\n * @param expectedOrigin - The expected origin URL for the message\n * @returns True if the message source and origin are valid, false otherwise\n */\n private isValidMessageSource(\n event: MessageEvent,\n expectedOrigin: string,\n ): boolean {\n // Check if message is from the iframe source\n const isValidSource = event.source === this.iframeElement?.contentWindow;\n\n // Build list of allowed origins\n const allowedOrigins = [expectedOrigin];\n\n // Add the actual iframe origin (to handle redirects)\n if (this.iframeElement?.src) {\n try {\n const actualIframeOrigin = new URL(this.iframeElement.src).origin;\n allowedOrigins.push(actualIframeOrigin);\n } catch {\n // ignore URL parsing errors\n }\n }\n\n // Add the client app's own origin (same-origin) for messages sent after token exchange\n // This is needed when the iframe navigates to the client app's callback URL\n const clientOrigin = window.location.origin;\n if (!allowedOrigins.includes(clientOrigin)) {\n allowedOrigins.push(clientOrigin);\n }\n\n // Add common development login app origins for localhost\n const expectedUrl = new URL(expectedOrigin);\n if (expectedUrl.hostname === \"localhost\") {\n // For localhost, also allow common development ports\n allowedOrigins.push(\"http://localhost:3004\"); // default login-app port\n allowedOrigins.push(\"http://localhost:3001\"); // auth server port\n }\n\n const isValidOrigin = allowedOrigins.includes(event.origin);\n\n if (!isValidOrigin) {\n this.logger.warn(\"Ignored message from unexpected origin.\", {\n receivedOrigin: event.origin,\n expectedOrigin,\n allowedOrigins,\n iframeSrc: this.iframeElement?.src,\n });\n }\n\n if (!isValidSource) {\n this.logger.warn(\"Ignored message from unexpected source.\", {\n isSourceProvided: !!event.source,\n isIframeContentWindowAvailable: !!this.iframeElement?.contentWindow,\n iframeSrc: this.iframeElement?.src,\n });\n }\n\n return isValidOrigin && isValidSource;\n }\n\n /**\n * Processes messages that have passed origin and source validation.\n *\n * Routes validated messages to specific handlers based on message type,\n * including civicloginApp messages, iframe resizer messages, and standard auth messages.\n *\n * @param event - The validated MessageEvent to process\n */\n private handleValidMessage(event: MessageEvent): void {\n this.logger.info(\n \"Message from configured iframe source and origin received\",\n {\n data: event.data,\n iframeSrc: this.iframeElement?.src,\n },\n );\n\n const message = event.data as IframeMessage;\n\n this.logger.debug(\"Processing iframe message\", {\n messageType: typeof message,\n hasType: message && typeof message === \"object\" && \"type\" in message,\n hasSource: message && typeof message === \"object\" && \"source\" in message,\n messageKeys:\n message && typeof message === \"object\" ? Object.keys(message) : [],\n rawData: message,\n });\n\n // Handle civicloginApp messages\n if (this.isCivicLoginAppMessage(message)) {\n this.handleCivicLoginAppMessage(message);\n return;\n }\n\n // Handle iframe resizer messages\n if (this.isIframeResizerMessage(message)) {\n this.handleIframeResizerMessage(message);\n return;\n }\n\n // Handle standard auth messages\n this.handleStandardAuthMessage(message);\n }\n\n /**\n * Type guard to identify civicloginApp messages.\n *\n * Checks if a message object has the structure and source property\n * that identifies it as coming from the civicloginApp.\n *\n * @param message - The message object to check\n * @returns True if the message is a LoginAppMessage, false otherwise\n */\n private isCivicLoginAppMessage(message: unknown): message is LoginAppMessage {\n return (\n message !== null &&\n typeof message === \"object\" &&\n \"source\" in message &&\n (message as Record<string, unknown>).source === \"civicloginApp\"\n );\n }\n\n /**\n * Handles messages originating from the civicloginApp.\n *\n * Processes various civicloginApp message types including authentication errors,\n * popup failures, design updates, and other app-specific communications.\n * Validates client ID matches before processing.\n *\n * @param message - The validated civicloginApp message to process\n */\n private handleCivicLoginAppMessage(message: LoginAppMessage): void {\n this.logger.info(\"Received civicloginApp message\", {\n type: message.type,\n clientId: message.clientId,\n data: message.data,\n });\n\n // Validate clientId matches our config\n if (\n message.clientId !== this.config.clientId &&\n this.config.loginUrl === undefined\n ) {\n this.logger.warn(\"civicloginApp message clientId mismatch\", {\n received: message.clientId,\n expected: this.config.clientId,\n });\n return;\n }\n\n switch (message.type) {\n case \"auth_error\":\n case \"auth_error_try_again\":\n this.handleCivicLoginAppError(message);\n break;\n case \"generatePopupFailed\":\n this.handlePopupFailure(message);\n break;\n case \"browserCorsFailsSilently\":\n this.handleBrowserCorsFailsSilently(message);\n break;\n case \"design\":\n this.logger.debug(\"civicloginApp design message\", {\n data: message.data,\n });\n break;\n case \"auth_success_early\":\n this.logger.info(\"civicloginApp auth success early message\", {\n data: message.data,\n });\n this.handleAuthSuccessEarly(message);\n break;\n case \"auth_success\":\n this.logger.info(\"civicloginApp auth success message\", {\n data: message.data,\n });\n\n // Dispatch early auth success event for immediate modal closing\n\n // Still handle auth success normally (for callback processing)\n this.handleAuthSuccess({\n type: \"auth_success\",\n detail: \"Authentication successful\",\n data: message.data,\n });\n break;\n default:\n this.handleUnknownCivicLoginAppMessage(message);\n break;\n }\n }\n\n /**\n * Handles auth success early messages from civicloginApp.\n *\n * Processes auth_success_early messages, emits success events,\n * and triggers the success callback with authentication results.\n *\n * @param message - The civicloginApp auth success early message to process\n */\n\n private handleAuthSuccessEarly(message: LoginAppMessage): void {\n this.logger.info(\"civicloginApp auth success early message\", {\n data: message.data,\n });\n\n const earlySuccessEvent = new CustomEvent(\"civic-auth-success-early\", {\n detail: {\n clientId: message.clientId,\n data: message.data,\n },\n });\n window.dispatchEvent(earlySuccessEvent);\n }\n\n /**\n * Handles authentication error messages from civicloginApp.\n *\n * Processes auth_error and auth_error_try_again messages, creates\n * appropriate error objects, emits error events, and triggers cleanup.\n *\n * @param message - The civicloginApp error message to process\n */\n private handleCivicLoginAppError(message: LoginAppMessage): void {\n this.logger.error(\"civicloginApp authentication error\", {\n type: message.type,\n data: message.data,\n });\n\n const error = new CivicAuthError(\n `Login app error: ${message.type}`,\n CivicAuthErrorCode.INVALID_MESSAGE,\n );\n\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: error.message,\n error: message.data,\n });\n\n this.onAuthError(error);\n this.cleanup();\n }\n\n /**\n * Handle the case where we know in advance that the browser will not prompt the user to open\n * a popup and will fail silently instead. We want to handle this case gracefully by switching to redirect\n * mode if the iframe is in modal display mode. This will be done when the auth flow actually starts\n * @param message\n */\n private handleBrowserCorsFailsSilently(message: LoginAppMessage): void {\n const failedUrl = (message.data as Record<string, unknown> | undefined)\n ?.url as string | undefined;\n this.logger.warn(\"civicloginApp browser CORS fail silently\", {\n failedUrl,\n config: this.config,\n autoRedirect: this.config.autoRedirect,\n });\n if (\n this.config.displayMode === \"iframe\" &&\n this.config.iframeDisplayMode === \"modal\" &&\n this.config.autoRedirect !== false && // Add this check\n failedUrl\n ) {\n IframeManager.handleBrowserCorsFailsSilently(failedUrl);\n this.onBrowserCorsFailsSilently(failedUrl);\n }\n }\n /**\n * Handles popup generation failure messages from civicloginApp.\n *\n * Processes generatePopupFailed messages, extracts the failed URL,\n * emits appropriate events, and triggers the popup failure callback\n * to enable fallback authentication methods.\n *\n * @param message - The civicloginApp popup failure message to process\n */\n private handlePopupFailure(message: LoginAppMessage): void {\n this.logger.warn(\"civicloginApp popup generation failed\", {\n data: message.data,\n });\n\n const failedUrl = (message.data as Record<string, unknown> | undefined)\n ?.url as string | undefined;\n if (failedUrl) {\n this.logger.info(\"Popup failed for URL, considering fallback options\", {\n failedUrl,\n displayMode: this.config.displayMode,\n });\n\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: \"Popup blocked by browser - switching to redirect mode\",\n error: {\n type: \"popup_blocked\",\n failedUrl,\n suggestion:\n \"The browser blocked a popup window. Redirecting to complete authentication in a new page.\",\n },\n });\n }\n\n this.onPopupFailure(failedUrl);\n }\n\n /**\n * Handles unknown or unrecognized civicloginApp message types.\n *\n * Provides fallback handling for unexpected message types, with special\n * logic to detect potential success messages that don't match standard types.\n *\n * @param message - The unrecognized civicloginApp message to process\n */\n private handleUnknownCivicLoginAppMessage(message: LoginAppMessage): void {\n this.logger.debug(\"Unhandled civicloginApp message type\", {\n type: message.type,\n data: message.data,\n });\n\n // Check if this might be a success message with a different type\n if (message.type && message.type.toLowerCase().includes(\"success\")) {\n this.logger.info(\"Potential success message from civicloginApp\", {\n type: message.type,\n data: message.data,\n });\n\n this.handleAuthSuccess({\n type: \"auth_success\",\n detail: `civicloginApp success: ${message.type}`,\n data: message.data,\n });\n }\n }\n\n /**\n * Type guard to identify iframe resizer messages.\n *\n * Checks if a message is related to iframe resizing functionality,\n * including both civic-specific resize messages and iFrameResizerChild messages.\n *\n * @param message - The message object to check\n * @returns True if the message is an iframe resizer message, false otherwise\n */\n private isIframeResizerMessage(message: unknown): boolean {\n return (\n (message !== null &&\n typeof message === \"object\" &&\n \"type\" in message &&\n ((message as Record<string, unknown>).type === \"civic-iframe-resize\" ||\n (message as Record<string, unknown>).type ===\n \"civic-iframe-ready\")) ||\n (typeof message === \"string\" && message.includes(\"iFrameResizerChild\"))\n );\n }\n\n /**\n * Handles iframe resizer messages for dynamic iframe sizing.\n *\n * Processes messages related to iframe resizing, including height adjustments\n * and ready state notifications from the iframe resizer library.\n *\n * @param message - The iframe resizer message to process\n */\n private handleIframeResizerMessage(message: unknown): void {\n if (typeof message === \"string\") {\n this.logger.debug(\"Received iframe resizer child message\", { message });\n } else if (message && typeof message === \"object\" && message !== null) {\n const messageObj = message as Record<string, unknown>;\n this.logger.debug(\"Received iframe resizer message\", {\n type: messageObj.type,\n height: messageObj.height,\n });\n }\n }\n\n /**\n * Handles standard authentication messages.\n *\n * Processes auth_success and auth_error messages that follow the standard\n * authentication message format, routing them to appropriate success or error handlers.\n *\n * @param message - The standard auth message to process\n */\n private handleStandardAuthMessage(message: unknown): void {\n const messageObj =\n message && typeof message === \"object\" && message !== null\n ? (message as Record<string, unknown>)\n : null;\n const messageType = messageObj?.type;\n\n switch (messageType) {\n case \"auth_success\":\n this.handleAuthSuccess(message as AuthMessage);\n break;\n case \"auth_error\":\n this.handleAuthError(message as AuthMessage);\n break;\n default:\n // Check if this is a calculateSubFramePositioning message (expected and harmless)\n if (messageObj?.command === \"calculateSubFramePositioning\") {\n this.logger.debug(\"Received iframe positioning message (expected)\", {\n command: messageObj.command,\n hasSubFrameData: !!messageObj.subFrameData,\n });\n } else {\n this.logger.debug(\n \"Message from iframe did not match expected types (auth_success, auth_error, civicloginApp, iframe-resizer)\",\n {\n data: message,\n messageType: typeof message,\n hasType: messageObj?.type ?? \"none\",\n messageKeys: messageObj ? Object.keys(messageObj) : [],\n },\n );\n }\n }\n }\n\n /**\n * Handles successful authentication completion.\n *\n * Processes authentication success messages, emits success events,\n * triggers the success callback with authentication results, and performs cleanup.\n *\n * @param data - The authentication success message containing result data\n */\n private handleAuthSuccess(data: AuthMessage): void {\n this.config.events?.emit(AuthEvent.SIGN_IN_COMPLETE, {\n detail: \"Success signal received via postMessage\",\n data,\n });\n this.onAuthSuccess((data?.data as AuthResult) || {});\n this.cleanup();\n }\n\n /**\n * Handles authentication errors.\n *\n * Processes authentication error messages, creates appropriate error objects,\n * emits error events, triggers the error callback, and performs cleanup.\n *\n * @param data - The authentication error message containing error details\n */\n private handleAuthError(data: AuthMessage): void {\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: \"Error signal received via postMessage\",\n error: data,\n });\n\n const error = new CivicAuthError(\n data?.detail || \"Error signal received via postMessage\",\n CivicAuthErrorCode.INVALID_MESSAGE,\n );\n\n this.onAuthError(error);\n this.cleanup();\n }\n}\n"]}
|
|
@@ -125,6 +125,8 @@ export interface CivicAuthClientConfig {
|
|
|
125
125
|
framework?: FrameworkType;
|
|
126
126
|
/** Whether to automatically preload the iframe for instant sign-in (defaults to true) */
|
|
127
127
|
preloadIframe?: boolean;
|
|
128
|
+
/** Whether to automatically switch to redirect mode when browser doesn't support iframe-based auth (defaults to true) */
|
|
129
|
+
autoRedirect?: boolean;
|
|
128
130
|
}
|
|
129
131
|
export interface LoggingConfig {
|
|
130
132
|
enabled: boolean;
|
|
@@ -153,5 +155,6 @@ export type ProcessedCivicAuthConfig = CivicAuthClientConfig & {
|
|
|
153
155
|
loginUrl?: string;
|
|
154
156
|
backendEndpoints?: BackendEndpoints;
|
|
155
157
|
preloadIframe: boolean;
|
|
158
|
+
autoRedirect: boolean;
|
|
156
159
|
};
|
|
157
160
|
//# sourceMappingURL=AuthTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthTypes.d.ts","sourceRoot":"","sources":["../../../../src/vanillajs/auth/types/AuthTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EACV,WAAW,IAAI,eAAe,EAC9B,WAAW,EACX,aAAa,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAElE;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG,UAAU,CAAC;A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5B,yDAAmC,CAAA;IACnC,iDAA2B,CAAA;IAC3B,6EAAuD,CAAA;IACvD,iEAA2C,CAAA;IAC3C,mEAA6C,CAAA;IAC7C,6DAAuC,CAAA;IACvC,qEAA+C,CAAA;IAC/C,yDAAmC,CAAA;IACnC,qDAA+B,CAAA;IAC/B,qDAA+B,CAAA;IAC/B,uDAAiC,CAAA;IACjC,iEAA2C,CAAA;IAC3C,mEAA6C,CAAA;IAC7C,6DAAuC,CAAA;IACvC,qDAA+B,CAAA;IAC/B,2DAAqC,CAAA;IACrC,uDAAiC,CAAA;AACnC,CAAC,EAlBW,kBAAkB,KAAlB,kBAAkB,QAkB7B;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,iBAAiB,EAAE,mBAAmB;IACtC,4BAA4B,EAAE,KAAK,EAAE,aAAa;IAClD,iBAAiB,EAAE,2BAA2B;IAC9C,eAAe,EAAE,yBAAyB;CAClC,CAAC;AAgCX,MAAM,OAAO,cAAe,SAAQ,KAAK;IAGrB;IAFlB,YACE,OAAe,EACC,IAAwB;QAExC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,SAAI,GAAJ,IAAI,CAAoB;QAGxC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF","sourcesContent":["import type { AuthenticationEvents } from \"../AuthenticationEvents.js\";\nimport type {\n DisplayMode as BaseDisplayMode,\n AuthStorage,\n FrameworkType,\n} from \"../../../types.js\";\nimport type { BackendEndpoints } from \"../../../server/config.js\";\n\n/**\n * Extended DisplayMode for VanillaJS that includes \"embedded\" option\n * This provides a cleaner API where users can simply use displayMode: \"embedded\"\n * instead of displayMode: \"iframe\" + iframeDisplayMode: \"embedded\"\n */\nexport type VanillaJSDisplayMode = BaseDisplayMode | \"embedded\";\n\n/**\n * Error codes for CivicAuth errors\n */\nexport enum CivicAuthErrorCode {\n CONFIG_REQUIRED = \"CONFIG_REQUIRED\",\n INIT_FAILED = \"INIT_FAILED\",\n ENDPOINTS_NOT_INITIALIZED = \"ENDPOINTS_NOT_INITIALIZED\",\n CONTAINER_NOT_FOUND = \"CONTAINER_NOT_FOUND\",\n AUTH_PROCESS_TIMEOUT = \"AUTH_PROCESS_TIMEOUT\",\n IFRAME_LOAD_ERROR = \"IFRAME_LOAD_ERROR\",\n IFRAME_PRELOAD_FAILED = \"IFRAME_PRELOAD_FAILED\",\n INVALID_MESSAGE = \"INVALID_MESSAGE\",\n LOGOUT_FAILED = \"LOGOUT_FAILED\",\n POPUP_BLOCKED = \"popup_blocked\",\n USER_CANCELLED = \"user_cancelled\",\n CONFIGURATION_ERROR = \"configuration_error\",\n TOKEN_REFRESH_FAILED = \"token_refresh_failed\",\n SESSION_NOT_FOUND = \"session_not_found\",\n STORAGE_ERROR = \"storage_error\",\n IFRAME_NOT_FOUND = \"iframe_not_found\",\n INTERNAL_ERROR = \"internal_error\",\n}\n\n/**\n * Constants for the auth client\n */\nexport const CIVIC_AUTH_CONSTANTS = {\n DEFAULT_IFRAME_ID: \"civic-auth-iframe\",\n DEFAULT_AUTH_PROCESS_TIMEOUT: 60000, // 60 seconds\n SUCCESS_SIGNAL_ID: \"civic-auth-success-signal\",\n ERROR_SIGNAL_ID: \"civic-auth-error-signal\",\n} as const;\n\n/**\n * Message types for postMessage communication\n */\nexport type AuthMessageType = \"auth_success\" | \"auth_error\";\n\nexport interface AuthMessage {\n type: AuthMessageType;\n detail?: string;\n data?: unknown;\n error?: unknown;\n}\n\n/**\n * Login app message types for postMessage communication\n */\nexport interface LoginAppMessage {\n source: \"civicloginApp\";\n type: \"design\" | \"generatePopupFailed\" | \"auth_success\" | string;\n clientId: string;\n data?: unknown;\n}\n\n/**\n * Combined message type for all iframe communications\n */\nexport type IframeMessage =\n | AuthMessage\n | LoginAppMessage\n | Record<string, unknown>;\n\nexport class CivicAuthError extends Error {\n constructor(\n message: string,\n public readonly code: CivicAuthErrorCode,\n ) {\n super(message);\n this.name = \"CivicAuthError\";\n }\n}\n\n/**\n * Configuration options for the CivicAuth client\n */\nexport interface CivicAuthClientConfig {\n /** OAuth client ID */\n clientId: string;\n /** URL to redirect to after authentication */\n redirectUrl?: string;\n /** URL to redirect to after logout - if not provided, will use redirectUrl */\n logoutRedirectUrl?: string;\n /** Base URL of the OAuth server */\n oauthServerBaseUrl?: string;\n /** Array of OAuth scopes to request */\n scopes?: string[];\n /** HTML element or element ID where the auth iframe will be mounted (required for embedded iframe mode) */\n targetContainerElement?: HTMLElement | string;\n /** Text signals for success and error states */\n textSignals?: {\n /** Text to display on successful authentication */\n success: string;\n /** Optional text to display on authentication error */\n error?: string;\n };\n /** Display mode for the authentication UI - VanillaJS supports \"embedded\" for simplified API */\n displayMode?: VanillaJSDisplayMode;\n /** Display mode for iframe rendering - modal (full-screen overlay) or embedded (within container) */\n iframeDisplayMode?: \"modal\" | \"embedded\";\n /**\n * Timeout duration in milliseconds for the entire authentication process.\n * If the authentication process takes longer than this duration, it will be cancelled\n * and an error will be thrown.\n * Note: This timeout is not applied to embedded iframe mode, where the iframe remains persistent.\n */\n authProcessTimeout?: number;\n /** Event handlers for authentication events */\n events?: AuthenticationEvents;\n /** Custom ID for the auth iframe */\n iframeId?: string;\n /** Custom storage adapter for auth state - uses shared AuthStorage interface */\n storageAdapter?: AuthStorage;\n /** OAuth nonce parameter for security */\n nonce?: string;\n /** Initial state for OAuth flow */\n initialState?: string;\n /** Logging configuration */\n logging?: LoggingConfig;\n /**\n * Custom login URL for backend integration (e.g., \"http://example.com/custom-backendurl\")\n * When provided, automatically uses BrowserCookieStorage for session sharing with backend\n */\n loginUrl?: string;\n /**\n * Custom backend endpoints configuration for backend integration\n * Only used when loginUrl is provided. Allows overriding default endpoints.\n */\n backendEndpoints?: BackendEndpoints;\n /** Framework being used (for analytics) - internal use only */\n framework?: FrameworkType;\n /** Whether to automatically preload the iframe for instant sign-in (defaults to true) */\n preloadIframe?: boolean;\n}\n\nexport interface LoggingConfig {\n enabled: boolean;\n namespace?: string;\n level?: \"debug\" | \"info\" | \"warn\" | \"error\";\n}\n\n/**\n * Internal configuration with all optional properties resolved to required ones.\n */\nexport type ProcessedCivicAuthConfig = CivicAuthClientConfig & {\n redirectUrl: string;\n logoutRedirectUrl: string;\n oauthServerBaseUrl: string;\n scopes: string[];\n textSignals: {\n success: string;\n error?: string;\n };\n storageAdapter: AuthStorage;\n logging: LoggingConfig;\n displayMode: BaseDisplayMode; // Internal config uses base DisplayMode after processing\n authProcessTimeout: number;\n iframeId: string;\n prompt: string;\n nonce?: string;\n loginUrl?: string;\n backendEndpoints?: BackendEndpoints;\n preloadIframe: boolean;\n // targetContainerElement remains optional as it's not needed for all display modes\n};\n"]}
|
|
1
|
+
{"version":3,"file":"AuthTypes.js","sourceRoot":"","sources":["../../../../src/vanillajs/auth/types/AuthTypes.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,CAAN,IAAY,kBAkBX;AAlBD,WAAY,kBAAkB;IAC5B,yDAAmC,CAAA;IACnC,iDAA2B,CAAA;IAC3B,6EAAuD,CAAA;IACvD,iEAA2C,CAAA;IAC3C,mEAA6C,CAAA;IAC7C,6DAAuC,CAAA;IACvC,qEAA+C,CAAA;IAC/C,yDAAmC,CAAA;IACnC,qDAA+B,CAAA;IAC/B,qDAA+B,CAAA;IAC/B,uDAAiC,CAAA;IACjC,iEAA2C,CAAA;IAC3C,mEAA6C,CAAA;IAC7C,6DAAuC,CAAA;IACvC,qDAA+B,CAAA;IAC/B,2DAAqC,CAAA;IACrC,uDAAiC,CAAA;AACnC,CAAC,EAlBW,kBAAkB,KAAlB,kBAAkB,QAkB7B;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,iBAAiB,EAAE,mBAAmB;IACtC,4BAA4B,EAAE,KAAK,EAAE,aAAa;IAClD,iBAAiB,EAAE,2BAA2B;IAC9C,eAAe,EAAE,yBAAyB;CAClC,CAAC;AAgCX,MAAM,OAAO,cAAe,SAAQ,KAAK;IAGrB;IAFlB,YACE,OAAe,EACC,IAAwB;QAExC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,SAAI,GAAJ,IAAI,CAAoB;QAGxC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF","sourcesContent":["import type { AuthenticationEvents } from \"../AuthenticationEvents.js\";\nimport type {\n DisplayMode as BaseDisplayMode,\n AuthStorage,\n FrameworkType,\n} from \"../../../types.js\";\nimport type { BackendEndpoints } from \"../../../server/config.js\";\n\n/**\n * Extended DisplayMode for VanillaJS that includes \"embedded\" option\n * This provides a cleaner API where users can simply use displayMode: \"embedded\"\n * instead of displayMode: \"iframe\" + iframeDisplayMode: \"embedded\"\n */\nexport type VanillaJSDisplayMode = BaseDisplayMode | \"embedded\";\n\n/**\n * Error codes for CivicAuth errors\n */\nexport enum CivicAuthErrorCode {\n CONFIG_REQUIRED = \"CONFIG_REQUIRED\",\n INIT_FAILED = \"INIT_FAILED\",\n ENDPOINTS_NOT_INITIALIZED = \"ENDPOINTS_NOT_INITIALIZED\",\n CONTAINER_NOT_FOUND = \"CONTAINER_NOT_FOUND\",\n AUTH_PROCESS_TIMEOUT = \"AUTH_PROCESS_TIMEOUT\",\n IFRAME_LOAD_ERROR = \"IFRAME_LOAD_ERROR\",\n IFRAME_PRELOAD_FAILED = \"IFRAME_PRELOAD_FAILED\",\n INVALID_MESSAGE = \"INVALID_MESSAGE\",\n LOGOUT_FAILED = \"LOGOUT_FAILED\",\n POPUP_BLOCKED = \"popup_blocked\",\n USER_CANCELLED = \"user_cancelled\",\n CONFIGURATION_ERROR = \"configuration_error\",\n TOKEN_REFRESH_FAILED = \"token_refresh_failed\",\n SESSION_NOT_FOUND = \"session_not_found\",\n STORAGE_ERROR = \"storage_error\",\n IFRAME_NOT_FOUND = \"iframe_not_found\",\n INTERNAL_ERROR = \"internal_error\",\n}\n\n/**\n * Constants for the auth client\n */\nexport const CIVIC_AUTH_CONSTANTS = {\n DEFAULT_IFRAME_ID: \"civic-auth-iframe\",\n DEFAULT_AUTH_PROCESS_TIMEOUT: 60000, // 60 seconds\n SUCCESS_SIGNAL_ID: \"civic-auth-success-signal\",\n ERROR_SIGNAL_ID: \"civic-auth-error-signal\",\n} as const;\n\n/**\n * Message types for postMessage communication\n */\nexport type AuthMessageType = \"auth_success\" | \"auth_error\";\n\nexport interface AuthMessage {\n type: AuthMessageType;\n detail?: string;\n data?: unknown;\n error?: unknown;\n}\n\n/**\n * Login app message types for postMessage communication\n */\nexport interface LoginAppMessage {\n source: \"civicloginApp\";\n type: \"design\" | \"generatePopupFailed\" | \"auth_success\" | string;\n clientId: string;\n data?: unknown;\n}\n\n/**\n * Combined message type for all iframe communications\n */\nexport type IframeMessage =\n | AuthMessage\n | LoginAppMessage\n | Record<string, unknown>;\n\nexport class CivicAuthError extends Error {\n constructor(\n message: string,\n public readonly code: CivicAuthErrorCode,\n ) {\n super(message);\n this.name = \"CivicAuthError\";\n }\n}\n\n/**\n * Configuration options for the CivicAuth client\n */\nexport interface CivicAuthClientConfig {\n /** OAuth client ID */\n clientId: string;\n /** URL to redirect to after authentication */\n redirectUrl?: string;\n /** URL to redirect to after logout - if not provided, will use redirectUrl */\n logoutRedirectUrl?: string;\n /** Base URL of the OAuth server */\n oauthServerBaseUrl?: string;\n /** Array of OAuth scopes to request */\n scopes?: string[];\n /** HTML element or element ID where the auth iframe will be mounted (required for embedded iframe mode) */\n targetContainerElement?: HTMLElement | string;\n /** Text signals for success and error states */\n textSignals?: {\n /** Text to display on successful authentication */\n success: string;\n /** Optional text to display on authentication error */\n error?: string;\n };\n /** Display mode for the authentication UI - VanillaJS supports \"embedded\" for simplified API */\n displayMode?: VanillaJSDisplayMode;\n /** Display mode for iframe rendering - modal (full-screen overlay) or embedded (within container) */\n iframeDisplayMode?: \"modal\" | \"embedded\";\n /**\n * Timeout duration in milliseconds for the entire authentication process.\n * If the authentication process takes longer than this duration, it will be cancelled\n * and an error will be thrown.\n * Note: This timeout is not applied to embedded iframe mode, where the iframe remains persistent.\n */\n authProcessTimeout?: number;\n /** Event handlers for authentication events */\n events?: AuthenticationEvents;\n /** Custom ID for the auth iframe */\n iframeId?: string;\n /** Custom storage adapter for auth state - uses shared AuthStorage interface */\n storageAdapter?: AuthStorage;\n /** OAuth nonce parameter for security */\n nonce?: string;\n /** Initial state for OAuth flow */\n initialState?: string;\n /** Logging configuration */\n logging?: LoggingConfig;\n /**\n * Custom login URL for backend integration (e.g., \"http://example.com/custom-backendurl\")\n * When provided, automatically uses BrowserCookieStorage for session sharing with backend\n */\n loginUrl?: string;\n /**\n * Custom backend endpoints configuration for backend integration\n * Only used when loginUrl is provided. Allows overriding default endpoints.\n */\n backendEndpoints?: BackendEndpoints;\n /** Framework being used (for analytics) - internal use only */\n framework?: FrameworkType;\n /** Whether to automatically preload the iframe for instant sign-in (defaults to true) */\n preloadIframe?: boolean;\n /** Whether to automatically switch to redirect mode when browser doesn't support iframe-based auth (defaults to true) */\n autoRedirect?: boolean;\n}\n\nexport interface LoggingConfig {\n enabled: boolean;\n namespace?: string;\n level?: \"debug\" | \"info\" | \"warn\" | \"error\";\n}\n\n/**\n * Internal configuration with all optional properties resolved to required ones.\n */\nexport type ProcessedCivicAuthConfig = CivicAuthClientConfig & {\n redirectUrl: string;\n logoutRedirectUrl: string;\n oauthServerBaseUrl: string;\n scopes: string[];\n textSignals: {\n success: string;\n error?: string;\n };\n storageAdapter: AuthStorage;\n logging: LoggingConfig;\n displayMode: BaseDisplayMode; // Internal config uses base DisplayMode after processing\n authProcessTimeout: number;\n iframeId: string;\n prompt: string;\n nonce?: string;\n loginUrl?: string;\n backendEndpoints?: BackendEndpoints;\n preloadIframe: boolean;\n autoRedirect: boolean;\n // targetContainerElement remains optional as it's not needed for all display modes\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IframeManager.d.ts","sourceRoot":"","sources":["../../../src/vanillajs/iframe/IframeManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IframeManager.d.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