@civic/auth 0.10.0-beta.1 → 0.10.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/handlers/IframeAuthHandler.d.ts.map +1 -1
- package/dist/vanillajs/auth/handlers/IframeAuthHandler.js +18 -0
- package/dist/vanillajs/auth/handlers/IframeAuthHandler.js.map +1 -1
- package/package.json +1 -1
package/dist/shared/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "@civic/auth:0.10.0-beta.
|
|
1
|
+
export declare const VERSION = "@civic/auth:0.10.0-beta.2";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/shared/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAG,2BAA2B,CAAC","sourcesContent":["// This is an auto-generated file. Do not edit.\n\nexport const VERSION = \"@civic/auth:0.10.0-beta.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/shared/version.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,MAAM,CAAC,MAAM,OAAO,GAAG,2BAA2B,CAAC","sourcesContent":["// This is an auto-generated file. Do not edit.\n\nexport const VERSION = \"@civic/auth:0.10.0-beta.2\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IframeAuthHandler.d.ts","sourceRoot":"","sources":["../../../../src/vanillajs/auth/handlers/IframeAuthHandler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAA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WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA4DjD,gBAAgB,CAC3B,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,iBAAiB,CAAC;IAiItB,gBAAgB,IAAI,aAAa,GAAG,SAAS;IAI7C,gBAAgB,IAAI,iBAAiB,GAAG,SAAS;IAIjD,aAAa,IAAI,IAAI;IA0C5B,OAAO,CAAC,4BAA4B;IAgBpC,OAAO,CAAC,oBAAoB;IAe5B,OAAO,CAAC,mBAAmB;IA+B3B,OAAO,CAAC,0BAA0B;IA4BlC,OAAO,CAAC,wBAAwB;IAsDhC,OAAO,CAAC,2BAA2B;IAgEnC,OAAO,CAAC,mBAAmB;IA6E3B,OAAO,CAAC,mBAAmB;IAiC3B,OAAO,CAAC,+BAA+B;IAmGvC,OAAO,CAAC,kBAAkB;IAgCnB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IA+BxC;;OAEG;IACI,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAKhD;;OAEG;IACI,iBAAiB,IAAI,OAAO;IAInC;;;;;;;;;;;;;;;;;OAiBG;IACI,kBAAkB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO;IAShD;;;;;OAKG;IACI,eAAe,IAAI,IAAI;IAW9B;;OAEG;IACI,eAAe,IAAI,IAAI;CAU/B"}
|
|
@@ -381,12 +381,30 @@ export class IframeAuthHandler {
|
|
|
381
381
|
checkIframeRedirect() {
|
|
382
382
|
try {
|
|
383
383
|
const currentIframeHref = this.iframeElement?.contentWindow?.location.href;
|
|
384
|
+
const currentIframeOrigin = this.iframeElement?.contentWindow?.location.origin;
|
|
385
|
+
const currentIframePath = this.iframeElement?.contentWindow?.location.pathname;
|
|
384
386
|
if (currentIframeHref) {
|
|
385
387
|
this.logger.debug("Iframe current href accessible", {
|
|
386
388
|
href: currentIframeHref,
|
|
387
389
|
redirectUrl: this.config.redirectUrl,
|
|
388
390
|
startsWithRedirect: currentIframeHref.startsWith(this.config.redirectUrl),
|
|
389
391
|
});
|
|
392
|
+
// In Safari, the iframe manager may not catch the previous URL changes
|
|
393
|
+
// and we only get the current URL after the redirect to the successful login
|
|
394
|
+
// in this case we want to reload the page as we should have a valid session
|
|
395
|
+
if (!(currentIframePath === "/login" &&
|
|
396
|
+
currentIframeOrigin?.endsWith("civic.com")) && // special case for civic same-domain portal/login-app
|
|
397
|
+
currentIframeOrigin === new URL(this.config.redirectUrl).origin &&
|
|
398
|
+
!currentIframeHref.startsWith(this.config.redirectUrl) // we don't want to reload if we're on the redirect as we need to handle callback
|
|
399
|
+
) {
|
|
400
|
+
this.logger.info("Iframe has navigated to the success URL, reloading the page to reflect the new state.");
|
|
401
|
+
this.config.events?.emit(AuthEvent.URL_CHANGE, {
|
|
402
|
+
url: currentIframeHref,
|
|
403
|
+
source: "login", // this means the page will do a 'hard' reload which is required for the UserButton etc. to take state changes into account
|
|
404
|
+
});
|
|
405
|
+
this.iframeManager?.hide();
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
390
408
|
if (currentIframeHref.startsWith(this.config.redirectUrl)) {
|
|
391
409
|
this.logger.info("Iframe has navigated to redirectUrl (same-origin). Setting up DOM observer.");
|
|
392
410
|
// Hide content since we're on callback page now
|
|
@@ -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;AACvE,OAAO,EAAE,4CAA4C,EAAE,MAAM,gBAAg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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 // Set up postMessage listener for cross-origin communication\n window.addEventListener(\"message\", this.messageHandler);\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 \"For embedded iframe mode, provide a targetContainerElement or ensure an element with id 'civic-login-container' exists.\",\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 \"For embedded iframe mode, provide a targetContainerElement or ensure an element with class id 'civic-login-container' exists.\",\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\n // Check if we're in embedded mode - if so, preserve the iframe completely\n const isEmbeddedMode = this.iframeManager?.getDisplayMode() === \"embedded\";\n\n if (isEmbeddedMode) {\n // For embedded mode, do NOT cleanup anything - keep iframe visible in its current state\n this.logger.debug(\n \"Embedded mode detected - preserving iframe in its current state, no cleanup\",\n );\n // Only clean up event listeners but keep iframe and all DOM structure intact\n if (this.earlyAuthSuccessHandler) {\n window.removeEventListener(\n \"civic-auth-success-early\",\n this.earlyAuthSuccessHandler as EventListener,\n );\n }\n // Keep iframe element reference for embedded mode\n return;\n }\n\n // For modal mode, do full cleanup as before\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 (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\n if (this.config.targetContainerElement) {\n return this.config.targetContainerElement;\n }\n\n // Fallback: Look for element with id \"civic-login-container\"\n const fallbackContainer = document.getElementById(\n \"civic-login-container\",\n ) as HTMLElement;\n if (fallbackContainer) {\n this.logger.debug(\n 'Using fallback container with id \"civic-login-container\"',\n );\n return fallbackContainer;\n }\n\n return null;\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 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 this.logger.info(\"📝 Setting up SignalObserver\", {\n documentURL: iframeDoc.URL,\n documentTitle: iframeDoc.title,\n bodyExists: !!iframeDoc.body,\n textSignals: this.config.textSignals,\n hasEvents: !!this.config.events,\n });\n\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 this.signalObserver = signalObserver; // Store reference\n\n try {\n signalObserver.setup(iframeDoc);\n this.logger.info(\"✅ SignalObserver setup completed successfully\");\n } catch (error) {\n this.logger.error(\"❌ SignalObserver setup failed\", {\n error: error instanceof Error ? error.message : String(error),\n });\n }\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.info(\"🔍 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 callbackUrl: currentUrl,\n hasContentDocument: !!this.iframeElement.contentDocument,\n hasBody: !!this.iframeElement.contentDocument?.body,\n },\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.logger.info(\n \"✅ Setting up SignalObserver for callback page\",\n {\n documentReady: !!this.iframeElement.contentDocument,\n bodyReady: !!this.iframeElement.contentDocument.body,\n documentURL: this.iframeElement.contentDocument.URL,\n },\n );\n this.setupSignalObserver(this.iframeElement.contentDocument);\n } else {\n this.logger.warn(\n \"❌ Cannot set up SignalObserver - iframe document not accessible\",\n {\n hasContentDocument: !!this.iframeElement.contentDocument,\n hasBody: !!this.iframeElement.contentDocument?.body,\n iframeReady: !!this.iframeElement,\n },\n );\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"]}
|
|
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;IACvC,aAAa,CAA+B;IAC5C,WAAW,CAAyB;IACpC,OAAO,CAAa;IACpB,cAAc,CAAg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AAC;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 // Set up postMessage listener for cross-origin communication\n window.addEventListener(\"message\", this.messageHandler);\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 \"For embedded iframe mode, provide a targetContainerElement or ensure an element with id 'civic-login-container' exists.\",\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 \"For embedded iframe mode, provide a targetContainerElement or ensure an element with class id 'civic-login-container' exists.\",\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\n // Check if we're in embedded mode - if so, preserve the iframe completely\n const isEmbeddedMode = this.iframeManager?.getDisplayMode() === \"embedded\";\n\n if (isEmbeddedMode) {\n // For embedded mode, do NOT cleanup anything - keep iframe visible in its current state\n this.logger.debug(\n \"Embedded mode detected - preserving iframe in its current state, no cleanup\",\n );\n // Only clean up event listeners but keep iframe and all DOM structure intact\n if (this.earlyAuthSuccessHandler) {\n window.removeEventListener(\n \"civic-auth-success-early\",\n this.earlyAuthSuccessHandler as EventListener,\n );\n }\n // Keep iframe element reference for embedded mode\n return;\n }\n\n // For modal mode, do full cleanup as before\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 (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\n if (this.config.targetContainerElement) {\n return this.config.targetContainerElement;\n }\n\n // Fallback: Look for element with id \"civic-login-container\"\n const fallbackContainer = document.getElementById(\n \"civic-login-container\",\n ) as HTMLElement;\n if (fallbackContainer) {\n this.logger.debug(\n 'Using fallback container with id \"civic-login-container\"',\n );\n return fallbackContainer;\n }\n\n return null;\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 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 const currentIframeOrigin =\n this.iframeElement?.contentWindow?.location.origin;\n const currentIframePath =\n this.iframeElement?.contentWindow?.location.pathname;\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 // In Safari, the iframe manager may not catch the previous URL changes\n // and we only get the current URL after the redirect to the successful login\n // in this case we want to reload the page as we should have a valid session\n if (\n !(\n currentIframePath === \"/login\" &&\n currentIframeOrigin?.endsWith(\"civic.com\")\n ) && // special case for civic same-domain portal/login-app\n currentIframeOrigin === new URL(this.config.redirectUrl).origin &&\n !currentIframeHref.startsWith(this.config.redirectUrl) // we don't want to reload if we're on the redirect as we need to handle callback\n ) {\n this.logger.info(\n \"Iframe has navigated to the success URL, reloading the page to reflect the new state.\",\n );\n this.config.events?.emit(AuthEvent.URL_CHANGE, {\n url: currentIframeHref,\n source: \"login\", // this means the page will do a 'hard' reload which is required for the UserButton etc. to take state changes into account\n });\n this.iframeManager?.hide();\n return;\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 this.logger.info(\"📝 Setting up SignalObserver\", {\n documentURL: iframeDoc.URL,\n documentTitle: iframeDoc.title,\n bodyExists: !!iframeDoc.body,\n textSignals: this.config.textSignals,\n hasEvents: !!this.config.events,\n });\n\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 this.signalObserver = signalObserver; // Store reference\n\n try {\n signalObserver.setup(iframeDoc);\n this.logger.info(\"✅ SignalObserver setup completed successfully\");\n } catch (error) {\n this.logger.error(\"❌ SignalObserver setup failed\", {\n error: error instanceof Error ? error.message : String(error),\n });\n }\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.info(\"🔍 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 callbackUrl: currentUrl,\n hasContentDocument: !!this.iframeElement.contentDocument,\n hasBody: !!this.iframeElement.contentDocument?.body,\n },\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.logger.info(\n \"✅ Setting up SignalObserver for callback page\",\n {\n documentReady: !!this.iframeElement.contentDocument,\n bodyReady: !!this.iframeElement.contentDocument.body,\n documentURL: this.iframeElement.contentDocument.URL,\n },\n );\n this.setupSignalObserver(this.iframeElement.contentDocument);\n } else {\n this.logger.warn(\n \"❌ Cannot set up SignalObserver - iframe document not accessible\",\n {\n hasContentDocument: !!this.iframeElement.contentDocument,\n hasBody: !!this.iframeElement.contentDocument?.body,\n iframeReady: !!this.iframeElement,\n },\n );\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"]}
|