@civic/auth 0.6.0 → 0.6.1-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/dist/shared/components/CivicAuthIframeContainer.js +1 -1
- package/dist/shared/components/CivicAuthIframeContainer.js.map +1 -1
- package/dist/shared/lib/BrowserAuthenticationRefresher.d.ts +7 -1
- package/dist/shared/lib/BrowserAuthenticationRefresher.d.ts.map +1 -1
- package/dist/shared/lib/BrowserAuthenticationRefresher.js +15 -2
- package/dist/shared/lib/BrowserAuthenticationRefresher.js.map +1 -1
- package/dist/shared/lib/util.d.ts +1 -1
- package/dist/shared/lib/util.d.ts.map +1 -1
- package/dist/shared/lib/util.js +6 -1
- package/dist/shared/lib/util.js.map +1 -1
- package/dist/shared/version.d.ts +1 -1
- package/dist/shared/version.d.ts.map +1 -1
- package/dist/shared/version.js +1 -1
- package/dist/shared/version.js.map +1 -1
- package/dist/vanillajs/auth/CivicAuth.d.ts +63 -5
- package/dist/vanillajs/auth/CivicAuth.d.ts.map +1 -1
- package/dist/vanillajs/auth/CivicAuth.js +202 -26
- package/dist/vanillajs/auth/CivicAuth.js.map +1 -1
- package/dist/vanillajs/auth/OAuthCallbackHandler.d.ts +90 -0
- package/dist/vanillajs/auth/OAuthCallbackHandler.d.ts.map +1 -0
- package/dist/vanillajs/auth/OAuthCallbackHandler.js +143 -0
- package/dist/vanillajs/auth/OAuthCallbackHandler.js.map +1 -0
- package/dist/vanillajs/auth/SessionManager.d.ts +40 -9
- package/dist/vanillajs/auth/SessionManager.d.ts.map +1 -1
- package/dist/vanillajs/auth/SessionManager.js +96 -61
- package/dist/vanillajs/auth/SessionManager.js.map +1 -1
- package/dist/vanillajs/auth/TokenRefresher.d.ts +54 -0
- package/dist/vanillajs/auth/TokenRefresher.d.ts.map +1 -0
- package/dist/vanillajs/auth/TokenRefresher.js +166 -0
- package/dist/vanillajs/auth/TokenRefresher.js.map +1 -0
- package/dist/vanillajs/iframe/IframeManager.d.ts +82 -0
- package/dist/vanillajs/iframe/IframeManager.d.ts.map +1 -0
- package/dist/vanillajs/iframe/IframeManager.js +487 -0
- package/dist/vanillajs/iframe/IframeManager.js.map +1 -0
- package/dist/vanillajs/iframe/IframeResizer.d.ts +15 -0
- package/dist/vanillajs/iframe/IframeResizer.d.ts.map +1 -0
- package/dist/vanillajs/iframe/IframeResizer.js +127 -0
- package/dist/vanillajs/iframe/IframeResizer.js.map +1 -0
- package/dist/vanillajs/index.d.ts +8 -7
- package/dist/vanillajs/index.d.ts.map +1 -1
- package/dist/vanillajs/index.js +10 -7
- package/dist/vanillajs/index.js.map +1 -1
- package/dist/vanillajs/types/index.d.ts +2 -2
- package/dist/vanillajs/types/index.d.ts.map +1 -1
- package/dist/vanillajs/types/index.js.map +1 -1
- package/dist/vanillajs/ui/LoadingComponents.d.ts +51 -0
- package/dist/vanillajs/ui/LoadingComponents.d.ts.map +1 -0
- package/dist/vanillajs/ui/LoadingComponents.js +363 -0
- package/dist/vanillajs/ui/LoadingComponents.js.map +1 -0
- package/package.json +1 -1
- package/dist/vanillajs/iframe/domUtils.d.ts +0 -4
- package/dist/vanillajs/iframe/domUtils.d.ts.map +0 -1
- package/dist/vanillajs/iframe/domUtils.js +0 -25
- package/dist/vanillajs/iframe/domUtils.js.map +0 -1
- package/dist/vanillajs/storage/BrowserCookieStorageAdapter.d.ts +0 -19
- package/dist/vanillajs/storage/BrowserCookieStorageAdapter.d.ts.map +0 -1
- package/dist/vanillajs/storage/BrowserCookieStorageAdapter.js +0 -101
- package/dist/vanillajs/storage/BrowserCookieStorageAdapter.js.map +0 -1
- package/dist/vanillajs/storage/BrowserLocalStorageAdapter.d.ts +0 -9
- package/dist/vanillajs/storage/BrowserLocalStorageAdapter.d.ts.map +0 -1
- package/dist/vanillajs/storage/BrowserLocalStorageAdapter.js +0 -36
- package/dist/vanillajs/storage/BrowserLocalStorageAdapter.js.map +0 -1
- package/dist/vanillajs/storage/InMemoryStorageAdapter.d.ts +0 -9
- package/dist/vanillajs/storage/InMemoryStorageAdapter.d.ts.map +0 -1
- package/dist/vanillajs/storage/InMemoryStorageAdapter.js +0 -16
- package/dist/vanillajs/storage/InMemoryStorageAdapter.js.map +0 -1
- package/dist/vanillajs/storage/StorageAdapter.d.ts +0 -15
- package/dist/vanillajs/storage/StorageAdapter.d.ts.map +0 -1
- package/dist/vanillajs/storage/StorageAdapter.js +0 -16
- package/dist/vanillajs/storage/StorageAdapter.js.map +0 -1
- package/dist/vanillajs/utils/page-handlers.d.ts +0 -29
- package/dist/vanillajs/utils/page-handlers.d.ts.map +0 -1
- package/dist/vanillajs/utils/page-handlers.js +0 -165
- package/dist/vanillajs/utils/page-handlers.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { createIframe, removeIframe } from "../iframe/domUtils.js";
|
|
2
1
|
import { AuthEvent } from "../types/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { handleOAuthRedirectPage } from "../utils/page-handlers.js";
|
|
2
|
+
import { LocalStorageAdapter } from "../../browser/storage.js";
|
|
3
|
+
import { handleOAuthRedirectPage } from "./OAuthCallbackHandler.js";
|
|
6
4
|
import { buildAuthUrl } from "../utils/auth-utils.js";
|
|
7
5
|
import { createLogger, configureLogging, setCurrentLogger, } from "../utils/logger.js";
|
|
8
6
|
import { SignalObserver } from "../iframe/SignalObserver.js";
|
|
9
7
|
import { GenericPublicClientPKCEProducer } from "../../services/PKCE.js";
|
|
10
8
|
import { generateState } from "../../lib/oauth.js";
|
|
9
|
+
import { SessionManager } from "./SessionManager.js";
|
|
10
|
+
import { IframeManager } from "../iframe/IframeManager.js";
|
|
11
11
|
/**
|
|
12
12
|
* Error codes for CivicAuth errors
|
|
13
13
|
*/
|
|
@@ -38,10 +38,36 @@ class CivicAuthError extends Error {
|
|
|
38
38
|
this.name = "CivicAuthError";
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Process the configuration with defaults
|
|
43
|
+
*/
|
|
44
|
+
function processConfigWithDefaults(config) {
|
|
45
|
+
const loggingConfig = {
|
|
46
|
+
enabled: true,
|
|
47
|
+
namespace: "iframe",
|
|
48
|
+
level: "debug",
|
|
49
|
+
...config.logging,
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
...config,
|
|
53
|
+
displayMode: config.displayMode || "iframe",
|
|
54
|
+
authProcessTimeout: config.authProcessTimeout || CONSTANTS.DEFAULT_AUTH_PROCESS_TIMEOUT,
|
|
55
|
+
iframeId: config.iframeId || CONSTANTS.DEFAULT_IFRAME_ID,
|
|
56
|
+
logging: loggingConfig,
|
|
57
|
+
storageAdapter: config.storageAdapter || new LocalStorageAdapter(),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
41
60
|
/**
|
|
42
61
|
* CivicAuth client for handling OAuth authentication
|
|
43
62
|
*/
|
|
44
63
|
export class CivicAuth {
|
|
64
|
+
/**
|
|
65
|
+
* Internal configuration with all optional properties resolved to required ones.
|
|
66
|
+
*
|
|
67
|
+
* We extend CivicAuthClientConfig rather than making these properties required
|
|
68
|
+
* in the public interface to maintain better DX (optional properties) while
|
|
69
|
+
* ensuring type safety internally after defaults are applied.
|
|
70
|
+
*/
|
|
45
71
|
config;
|
|
46
72
|
iframeElement;
|
|
47
73
|
observer;
|
|
@@ -53,6 +79,8 @@ export class CivicAuth {
|
|
|
53
79
|
storage;
|
|
54
80
|
endpoints;
|
|
55
81
|
logger;
|
|
82
|
+
sessionManager;
|
|
83
|
+
iframeManager;
|
|
56
84
|
/**
|
|
57
85
|
* Private constructor for CivicAuth.
|
|
58
86
|
* Use {@link CivicAuth.create} to create a new instance.
|
|
@@ -61,21 +89,10 @@ export class CivicAuth {
|
|
|
61
89
|
* @private
|
|
62
90
|
*/
|
|
63
91
|
constructor(config) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
namespace: "iframe",
|
|
67
|
-
level: "debug",
|
|
68
|
-
...config.logging,
|
|
69
|
-
};
|
|
70
|
-
this.config = {
|
|
71
|
-
displayMode: "iframe",
|
|
72
|
-
authProcessTimeout: config.authProcessTimeout || CONSTANTS.DEFAULT_AUTH_PROCESS_TIMEOUT,
|
|
73
|
-
iframeId: config.iframeId || CONSTANTS.DEFAULT_IFRAME_ID,
|
|
74
|
-
logging: loggingConfig,
|
|
75
|
-
...config,
|
|
76
|
-
};
|
|
92
|
+
// Process config with defaults
|
|
93
|
+
this.config = processConfigWithDefaults(config);
|
|
77
94
|
// Configure logging based on config
|
|
78
|
-
configureLogging(
|
|
95
|
+
configureLogging(this.config.logging);
|
|
79
96
|
// Initialize logger based on config
|
|
80
97
|
if (this.config.logging?.enabled) {
|
|
81
98
|
const namespace = this.config.logging.namespace || "iframe";
|
|
@@ -92,7 +109,12 @@ export class CivicAuth {
|
|
|
92
109
|
}
|
|
93
110
|
// Set this logger as the current logger
|
|
94
111
|
setCurrentLogger(this.logger);
|
|
95
|
-
|
|
112
|
+
// Use the storage adapter from processed config (guaranteed to be present)
|
|
113
|
+
this.storage = this.config.storageAdapter;
|
|
114
|
+
// Initialize SessionManager if events are provided
|
|
115
|
+
if (config.events) {
|
|
116
|
+
this.sessionManager = new SessionManager(this.storage, config.events);
|
|
117
|
+
}
|
|
96
118
|
// Validate required configuration
|
|
97
119
|
const requiredConfigs = [
|
|
98
120
|
{ key: "clientId", value: config.clientId },
|
|
@@ -147,6 +169,17 @@ export class CivicAuth {
|
|
|
147
169
|
userinfo: `${this.config.oauthServerBaseUrl}userinfo`,
|
|
148
170
|
endsession: `${this.config.oauthServerBaseUrl}endsession`,
|
|
149
171
|
};
|
|
172
|
+
// Initialize SessionManager with auth config for token refresh
|
|
173
|
+
if (this.sessionManager) {
|
|
174
|
+
const authConfig = {
|
|
175
|
+
clientId: this.config.clientId,
|
|
176
|
+
redirectUrl: this.config.redirectUrl,
|
|
177
|
+
oauthServer: this.config.oauthServerBaseUrl,
|
|
178
|
+
scopes: this.config.scopes,
|
|
179
|
+
endpoints: this.endpoints,
|
|
180
|
+
};
|
|
181
|
+
await this.sessionManager.initializeWithAuthConfig(authConfig);
|
|
182
|
+
}
|
|
150
183
|
// Check if we're on the callback page
|
|
151
184
|
if (window.location.href.startsWith(this.config.redirectUrl)) {
|
|
152
185
|
await this.handleCallback();
|
|
@@ -177,6 +210,59 @@ export class CivicAuth {
|
|
|
177
210
|
}
|
|
178
211
|
return this.config.targetContainerElement;
|
|
179
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Determines the appropriate iframe display mode based on container characteristics
|
|
215
|
+
* @param container The HTML element that will contain the iframe
|
|
216
|
+
* @returns "modal" for full-screen overlay or "embedded" for in-container display
|
|
217
|
+
*/
|
|
218
|
+
determineIframeDisplayMode(container) {
|
|
219
|
+
// Use explicit config if provided
|
|
220
|
+
if (this.config.iframeDisplayMode) {
|
|
221
|
+
this.logger.debug(`Using configured iframe display mode: ${this.config.iframeDisplayMode}`);
|
|
222
|
+
return this.config.iframeDisplayMode;
|
|
223
|
+
}
|
|
224
|
+
// Analyze container characteristics to determine best display mode
|
|
225
|
+
const containerRect = container.getBoundingClientRect();
|
|
226
|
+
const containerStyles = window.getComputedStyle(container);
|
|
227
|
+
// Get container dimensions
|
|
228
|
+
const containerWidth = containerRect.width;
|
|
229
|
+
const containerHeight = containerRect.height;
|
|
230
|
+
// Check if container is positioned in a way that suggests it's meant for modal display
|
|
231
|
+
const isFullScreenContainer = containerStyles.position === "fixed" &&
|
|
232
|
+
(containerWidth >= window.innerWidth * 0.9 ||
|
|
233
|
+
containerHeight >= window.innerHeight * 0.9);
|
|
234
|
+
// Modal mode thresholds - if container is too small, use modal for better UX
|
|
235
|
+
const MIN_EMBEDDED_WIDTH = 320; // Same as modal content wrapper width
|
|
236
|
+
const MIN_EMBEDDED_HEIGHT = 400; // Reasonable minimum for embedded auth flow
|
|
237
|
+
// Determine mode based on container characteristics
|
|
238
|
+
if (isFullScreenContainer) {
|
|
239
|
+
this.logger.debug("Container appears to be full-screen positioned, using modal mode", { containerWidth, containerHeight, position: containerStyles.position });
|
|
240
|
+
return "modal";
|
|
241
|
+
}
|
|
242
|
+
if (containerWidth < MIN_EMBEDDED_WIDTH ||
|
|
243
|
+
containerHeight < MIN_EMBEDDED_HEIGHT) {
|
|
244
|
+
this.logger.debug(`Container too small for embedded mode (${containerWidth}x${containerHeight}), using modal mode`, {
|
|
245
|
+
containerWidth,
|
|
246
|
+
containerHeight,
|
|
247
|
+
MIN_EMBEDDED_WIDTH,
|
|
248
|
+
MIN_EMBEDDED_HEIGHT,
|
|
249
|
+
});
|
|
250
|
+
return "modal";
|
|
251
|
+
}
|
|
252
|
+
// Check if container has sufficient space and is properly positioned for embedding
|
|
253
|
+
const hasAdequateSpace = containerWidth >= MIN_EMBEDDED_WIDTH &&
|
|
254
|
+
containerHeight >= MIN_EMBEDDED_HEIGHT;
|
|
255
|
+
const isEmbeddablePosition = containerStyles.position === "relative" ||
|
|
256
|
+
containerStyles.position === "static" ||
|
|
257
|
+
containerStyles.position === "";
|
|
258
|
+
if (hasAdequateSpace && isEmbeddablePosition) {
|
|
259
|
+
this.logger.debug("Container has adequate space and positioning for embedded mode", { containerWidth, containerHeight, position: containerStyles.position });
|
|
260
|
+
return "embedded";
|
|
261
|
+
}
|
|
262
|
+
// Default to modal mode if container characteristics are unclear
|
|
263
|
+
this.logger.debug("Container characteristics unclear, defaulting to modal mode for better UX", { containerWidth, containerHeight, position: containerStyles.position });
|
|
264
|
+
return "modal";
|
|
265
|
+
}
|
|
180
266
|
/**
|
|
181
267
|
* Builds the authentication URL with PKCE challenge
|
|
182
268
|
* @returns The complete authentication URL
|
|
@@ -186,8 +272,8 @@ export class CivicAuth {
|
|
|
186
272
|
if (!this.endpoints) {
|
|
187
273
|
throw new CivicAuthError("OAuth endpoints not initialized. Please wait for initialization to complete.", CivicAuthErrorCode.ENDPOINTS_NOT_INITIALIZED);
|
|
188
274
|
}
|
|
189
|
-
|
|
190
|
-
const pkceProducer = new GenericPublicClientPKCEProducer(
|
|
275
|
+
// Use storage directly since it's now AuthStorage
|
|
276
|
+
const pkceProducer = new GenericPublicClientPKCEProducer(this.storage);
|
|
191
277
|
const codeChallenge = await pkceProducer.getCodeChallenge();
|
|
192
278
|
const state = this.config.initialState ||
|
|
193
279
|
generateState({
|
|
@@ -299,15 +385,34 @@ export class CivicAuth {
|
|
|
299
385
|
reject(error);
|
|
300
386
|
return;
|
|
301
387
|
}
|
|
302
|
-
this.logger.debug("Creating iframe", {
|
|
388
|
+
this.logger.debug("Creating iframe with modal backdrop", {
|
|
303
389
|
url: fullAuthUrl,
|
|
304
390
|
containerId: container?.id,
|
|
305
391
|
iframeId: this.config.iframeId,
|
|
306
392
|
origin: window.location.origin,
|
|
307
393
|
});
|
|
308
|
-
|
|
394
|
+
// Determine the actual display mode for IframeManager
|
|
395
|
+
// For iframe displayMode, we need to decide between modal and embedded based on container
|
|
396
|
+
const iframeDisplayMode = this.determineIframeDisplayMode(container);
|
|
397
|
+
this.logger.debug(`🎯 CivicAuth: Creating IframeManager with display mode: ${iframeDisplayMode}`);
|
|
398
|
+
// Create IframeManager with appropriate display mode
|
|
399
|
+
this.iframeManager = new IframeManager({
|
|
400
|
+
container: container,
|
|
401
|
+
displayMode: iframeDisplayMode,
|
|
402
|
+
iframeId: this.config.iframeId,
|
|
403
|
+
onClose: () => {
|
|
404
|
+
this.logger.debug("Authentication close requested by user (backdrop click, close button, or Escape key)");
|
|
405
|
+
this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {
|
|
406
|
+
detail: "Authentication cancelled by user",
|
|
407
|
+
});
|
|
408
|
+
reject(new CivicAuthError("Authentication cancelled by user", CivicAuthErrorCode.AUTH_PROCESS_TIMEOUT));
|
|
409
|
+
this.cleanup();
|
|
410
|
+
},
|
|
411
|
+
});
|
|
412
|
+
// Create the iframe using IframeManager
|
|
413
|
+
this.iframeElement = this.iframeManager.createIframe(fullAuthUrl);
|
|
309
414
|
this.config.events?.emit(AuthEvent.SIGN_IN_STARTED, {
|
|
310
|
-
detail: "Iframe created",
|
|
415
|
+
detail: "Iframe created with modal backdrop",
|
|
311
416
|
});
|
|
312
417
|
this.iframeElement.onload = () => {
|
|
313
418
|
this.logger.info("Iframe loaded", {
|
|
@@ -449,9 +554,13 @@ export class CivicAuth {
|
|
|
449
554
|
window.removeEventListener("message", this.messageEventHandler);
|
|
450
555
|
this.logger.debug("Removed 'message' event listener from window.");
|
|
451
556
|
}
|
|
557
|
+
if (this.iframeManager) {
|
|
558
|
+
this.logger.debug("Cleaning up iframe manager");
|
|
559
|
+
this.iframeManager.cleanup();
|
|
560
|
+
this.iframeManager = undefined;
|
|
561
|
+
}
|
|
562
|
+
// Reset iframe element reference (actual removal handled by IframeManager)
|
|
452
563
|
if (this.iframeElement) {
|
|
453
|
-
this.logger.debug("Removing iframe element");
|
|
454
|
-
removeIframe(this.iframeElement);
|
|
455
564
|
this.iframeElement = undefined;
|
|
456
565
|
}
|
|
457
566
|
if (this.authProcessTimeoutHandle) {
|
|
@@ -474,6 +583,7 @@ export class CivicAuth {
|
|
|
474
583
|
success: this.config.textSignals.success,
|
|
475
584
|
error: this.config.textSignals.error || "Authentication failed",
|
|
476
585
|
},
|
|
586
|
+
storageAdapter: this.storage,
|
|
477
587
|
});
|
|
478
588
|
if (callbackHandled) {
|
|
479
589
|
const successSignal = document.getElementById(CONSTANTS.SUCCESS_SIGNAL_ID);
|
|
@@ -509,5 +619,71 @@ export class CivicAuth {
|
|
|
509
619
|
});
|
|
510
620
|
}
|
|
511
621
|
}
|
|
622
|
+
/**
|
|
623
|
+
* Get the current session
|
|
624
|
+
*/
|
|
625
|
+
async getCurrentSession() {
|
|
626
|
+
return this.sessionManager?.getCurrentSession() || null;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Check if user is authenticated
|
|
630
|
+
*/
|
|
631
|
+
async isAuthenticated() {
|
|
632
|
+
return this.sessionManager?.isAuthenticated() || false;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Get the current user
|
|
636
|
+
*/
|
|
637
|
+
async getCurrentUser() {
|
|
638
|
+
return this.sessionManager?.getCurrentUser() || null;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Clear the current session
|
|
642
|
+
*/
|
|
643
|
+
async clearSession() {
|
|
644
|
+
if (!this.sessionManager) {
|
|
645
|
+
throw new Error("SessionManager not initialized. Provide events in config.");
|
|
646
|
+
}
|
|
647
|
+
return this.sessionManager.clearSession();
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Manually refresh tokens
|
|
651
|
+
*/
|
|
652
|
+
async refreshTokens() {
|
|
653
|
+
if (!this.sessionManager) {
|
|
654
|
+
throw new Error("SessionManager not initialized. Provide events in config.");
|
|
655
|
+
}
|
|
656
|
+
return this.sessionManager.refreshTokens();
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Get token refresher state for debugging
|
|
660
|
+
*/
|
|
661
|
+
getTokenRefresherState() {
|
|
662
|
+
return this.sessionManager?.getTokenRefresherState() || null;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Update the iframe display mode
|
|
666
|
+
* @param mode - The display mode to use for the iframe
|
|
667
|
+
*/
|
|
668
|
+
setIframeDisplayMode(mode) {
|
|
669
|
+
this.config.iframeDisplayMode = mode;
|
|
670
|
+
this.logger.debug(`Iframe display mode updated to: ${mode}`);
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Get the current iframe display mode
|
|
674
|
+
* @returns The current iframe display mode
|
|
675
|
+
*/
|
|
676
|
+
getIframeDisplayMode() {
|
|
677
|
+
return this.config.iframeDisplayMode;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Destroy the auth client and clean up all resources
|
|
681
|
+
*/
|
|
682
|
+
async destroy() {
|
|
683
|
+
this.cleanup();
|
|
684
|
+
await this.sessionManager?.destroy();
|
|
685
|
+
this.sessionManager = undefined;
|
|
686
|
+
this.logger.info("CivicAuth destroyed");
|
|
687
|
+
}
|
|
512
688
|
}
|
|
513
689
|
//# sourceMappingURL=CivicAuth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CivicAuth.js","sourceRoot":"","sources":["../../../src/vanillajs/auth/CivicAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EACL,2BAA2B,GAE5B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAN,IAAY,kBAQX;AARD,WAAY,kBAAkB;IAC5B,yDAAmC,CAAA;IACnC,iDAA2B,CAAA;IAC3B,6EAAuD,CAAA;IACvD,iEAA2C,CAAA;IAC3C,mEAA6C,CAAA;IAC7C,6DAAuC,CAAA;IACvC,yDAAmC,CAAA;AACrC,CAAC,EARW,kBAAkB,KAAlB,kBAAkB,QAQ7B;AAED;;GAEG;AACH,MAAM,SAAS,GAAG;IAChB,iBAAiB,EAAE,mBAAmB;IACtC,4BAA4B,EAAE,KAAK,EAAE,aAAa;IAClD,iBAAiB,EAAE,2BAA2B;IAC9C,eAAe,EAAE,yBAAyB;CAClC,CAAC;AAcX,MAAM,cAAe,SAAQ,KAAK;IAGd;IAFlB,YACE,OAAe,EACC,IAAwB;QAExC,KA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;oBACD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,gBAAgB,EAAE;wBACnD,MAAM,EAAE,iCAAiC;wBACzC,IAAI,EAAE,QAAQ;qBACf,CAAC,CAAC;gBACL,CAAC;qBAAM,IAAI,WAAW,EAAE,CAAC;oBACvB,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;wBAChD,MAAM,EAAE,WAAW,CAAC,WAAW,IAAI,+BAA+B;qBACnE,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;gBAChD,MAAM,EACJ,KAAK,YAAY,KAAK;oBACpB,CAAC,CAAC,KAAK,CAAC,OAAO;oBACf,CAAC,CAAC,+BAA+B;aACtC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import { createIframe, removeIframe } from \"../iframe/domUtils.js\";\nimport { AuthEvent } from \"../types/index.js\";\nimport type { AuthenticationEvents } from \"./AuthenticationEvents.js\";\nimport {\n StorageAdapterToAuthStorage,\n type StorageAdapter,\n} from \"../storage/StorageAdapter.js\";\nimport { BrowserCookieStorageAdapter } from \"../storage/BrowserCookieStorageAdapter.js\";\nimport { handleOAuthRedirectPage } from \"../utils/page-handlers.js\";\nimport type { Endpoints, DisplayMode } from \"../../types.js\";\nimport { buildAuthUrl } from \"../utils/auth-utils.js\";\nimport type { AuthResult } from \"../types/index.js\";\nimport {\n createLogger,\n configureLogging,\n setCurrentLogger,\n} from \"../utils/logger.js\";\nimport { SignalObserver } from \"../iframe/SignalObserver.js\";\nimport { GenericPublicClientPKCEProducer } from \"../../services/PKCE.js\";\nimport { generateState } from \"../../lib/oauth.js\";\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 INVALID_MESSAGE = \"INVALID_MESSAGE\",\n}\n\n/**\n * Constants for the auth client\n */\nconst 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 */\ntype AuthMessageType = \"auth_success\" | \"auth_error\";\n\ninterface AuthMessage {\n type: AuthMessageType;\n detail?: string;\n data?: unknown;\n error?: unknown;\n}\n\nclass 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 /** 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 */\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 */\n displayMode?: DisplayMode;\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 */\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 */\n storageAdapter?: StorageAdapter;\n /** OAuth prompt parameter */\n prompt?: string;\n /** Initial state for OAuth flow */\n initialState?: string;\n /** Logging configuration */\n logging?: LoggingConfig;\n}\n\nexport interface LoggingConfig {\n enabled: boolean;\n namespace?: string;\n level?: \"debug\" | \"info\" | \"warn\" | \"error\";\n}\n\n/**\n * CivicAuth client for handling OAuth authentication\n */\nexport class CivicAuth {\n private config: CivicAuthClientConfig;\n private iframeElement?: HTMLIFrameElement;\n private observer?: MutationObserver;\n private authPromise?: Promise<AuthResult>;\n private authPromiseResolve?: (value: AuthResult) => void;\n private authPromiseReject?: (reason?: Error) => void;\n private authProcessTimeoutHandle?: number;\n private messageEventHandler?: (event: MessageEvent) => void;\n private storage: StorageAdapter;\n private endpoints?: Endpoints;\n private logger: ReturnType<typeof createLogger>;\n\n /**\n * Private constructor for CivicAuth.\n * Use {@link CivicAuth.create} to create a new instance.\n * @param config - Configuration options for the auth client\n * @throws {CivicAuthError} If required configuration is missing\n * @private\n */\n private constructor(config: CivicAuthClientConfig) {\n const loggingConfig = {\n enabled: true,\n namespace: \"iframe\",\n level: \"debug\" as const,\n ...config.logging,\n };\n\n this.config = {\n displayMode: \"iframe\",\n authProcessTimeout:\n config.authProcessTimeout || CONSTANTS.DEFAULT_AUTH_PROCESS_TIMEOUT,\n iframeId: config.iframeId || CONSTANTS.DEFAULT_IFRAME_ID,\n logging: loggingConfig,\n ...config,\n };\n\n // Configure logging based on config\n configureLogging(loggingConfig);\n\n // Initialize logger based on config\n if (this.config.logging?.enabled) {\n const namespace = this.config.logging.namespace || \"iframe\";\n this.logger = createLogger(namespace);\n } else {\n // Create a no-op logger when logging is disabled\n this.logger = {\n debug: () => {},\n info: () => {},\n warn: () => {},\n error: () => {},\n };\n }\n\n // Set this logger as the current logger\n setCurrentLogger(this.logger);\n\n this.storage = config.storageAdapter || new BrowserCookieStorageAdapter();\n\n // Validate required configuration\n const requiredConfigs = [\n { key: \"clientId\", value: config.clientId },\n { key: \"targetContainerElement\", value: config.targetContainerElement },\n { key: \"textSignals.success\", value: config.textSignals?.success },\n ];\n\n for (const { key, value } of requiredConfigs) {\n if (!value) {\n throw new CivicAuthError(\n `CivicAuth: ${key} is required.`,\n CivicAuthErrorCode.CONFIG_REQUIRED,\n );\n }\n }\n\n this.messageEventHandler = this.handleIframeMessage.bind(this);\n }\n\n /**\n * Creates and initializes a new instance of CivicAuth.\n * This is the recommended way to create a CivicAuth instance.\n *\n * @param config - Configuration options for the auth client\n * @returns A promise that resolves with the initialized CivicAuth instance\n * @throws {CivicAuthError} If initialization fails or required configuration is missing\n *\n * @example\n * ```typescript\n * const auth = await CivicAuth.create({\n * clientId: \"your-client-id\",\n * redirectUrl: \"https://your-app.com/callback\",\n * oauthServerBaseUrl: \"https://auth-server.com/\",\n * scopes: [\"openid\", \"profile\"],\n * targetContainerElement: \"auth-container\",\n * textSignals: {\n * success: \"Authentication successful!\"\n * }\n * });\n * ```\n */\n public static async create(\n config: CivicAuthClientConfig,\n ): Promise<CivicAuth> {\n const instance = new CivicAuth(config);\n await instance.init();\n return instance;\n }\n\n /**\n * Initializes the auth client and checks for callback handling\n * @throws {CivicAuthError} If initialization fails\n */\n private async init(): Promise<void> {\n try {\n // Get OAuth endpoints from well-known configuration\n this.endpoints = {\n auth: `${this.config.oauthServerBaseUrl}auth`,\n token: `${this.config.oauthServerBaseUrl}token`,\n jwks: `${this.config.oauthServerBaseUrl}jwks`,\n userinfo: `${this.config.oauthServerBaseUrl}userinfo`,\n endsession: `${this.config.oauthServerBaseUrl}endsession`,\n };\n\n // Check if we're on the callback page\n if (window.location.href.startsWith(this.config.redirectUrl)) {\n await this.handleCallback();\n }\n } catch (error) {\n const errorMessage =\n error instanceof Error\n ? error.message\n : \"Failed to initialize authentication\";\n this.logger.error(\"Failed to initialize CivicAuth:\", { error });\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: errorMessage,\n });\n throw new CivicAuthError(errorMessage, CivicAuthErrorCode.INIT_FAILED);\n }\n }\n\n /**\n * Gets the container element for the auth iframe\n * @returns The container element or null if not found\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 return this.config.targetContainerElement;\n }\n\n /**\n * Builds the authentication URL with PKCE challenge\n * @returns The complete authentication URL\n * @throws {CivicAuthError} If endpoints are not initialized\n */\n private async buildAuthUrl(): Promise<string> {\n if (!this.endpoints) {\n throw new CivicAuthError(\n \"OAuth endpoints not initialized. Please wait for initialization to complete.\",\n CivicAuthErrorCode.ENDPOINTS_NOT_INITIALIZED,\n );\n }\n\n const authStorage = new StorageAdapterToAuthStorage(this.storage);\n const pkceProducer = new GenericPublicClientPKCEProducer(authStorage);\n const codeChallenge = await pkceProducer.getCodeChallenge();\n const state =\n this.config.initialState ||\n generateState({\n displayMode: this.config.displayMode || \"iframe\",\n });\n\n return buildAuthUrl({\n endpoints: this.endpoints,\n clientId: this.config.clientId,\n redirectUrl: this.config.redirectUrl,\n scopes: this.config.scopes,\n codeChallenge,\n state,\n prompt: this.config.prompt,\n });\n }\n\n private handleIframeMessage(event: MessageEvent): void {\n const expectedOrigin = 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 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 private isValidMessageSource(\n event: MessageEvent,\n expectedOrigin: string,\n ): boolean {\n const isValidOrigin = event.origin === expectedOrigin;\n const isValidSource = event.source === this.iframeElement?.contentWindow;\n\n if (!isValidOrigin) {\n this.logger.warn(\"Ignored message from unexpected origin.\", {\n receivedOrigin: event.origin,\n expectedOrigin,\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 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 AuthMessage;\n const messageType = message?.type;\n\n switch (messageType) {\n case \"auth_success\":\n this.handleAuthSuccess(message);\n break;\n case \"auth_error\":\n this.handleAuthError(message);\n break;\n default:\n this.logger.debug(\n \"Message from iframe did not match expected types (auth_success, auth_error)\",\n { data: event.data },\n );\n }\n }\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.authPromiseResolve?.((data?.data as AuthResult) || {});\n this.cleanup();\n }\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 this.authPromiseReject?.(\n new CivicAuthError(\n data?.detail || \"Error signal received via postMessage\",\n CivicAuthErrorCode.INVALID_MESSAGE,\n ),\n );\n this.cleanup();\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.authPromiseResolve,\n this.authPromiseReject,\n () => this.cleanup(),\n );\n\n signalObserver.setup(iframeDoc);\n }\n\n private async handleNewTabAuth(\n fullAuthUrl: string,\n reject: (error: Error) => void,\n ): Promise<void> {\n const popupWindow = window.open(fullAuthUrl, \"_blank\");\n if (!popupWindow) {\n const error = new CivicAuthError(\n \"Failed to open popup window. Please check your browser's popup settings.\",\n CivicAuthErrorCode.INIT_FAILED,\n );\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: error.message,\n });\n reject(error);\n }\n }\n\n private async handleIframeAuth(\n fullAuthUrl: string,\n reject: (error: Error) => void,\n ): Promise<void> {\n const container = this.getContainerElement();\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 reject(error);\n return;\n }\n\n this.logger.debug(\"Creating iframe\", {\n url: fullAuthUrl,\n containerId: container?.id,\n iframeId: this.config.iframeId,\n origin: window.location.origin,\n });\n\n this.iframeElement = createIframe(\n fullAuthUrl,\n container,\n this.config.iframeId,\n );\n this.config.events?.emit(AuthEvent.SIGN_IN_STARTED, {\n detail: \"Iframe created\",\n });\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 reject(new Error(errorMsg));\n this.cleanup();\n return;\n }\n\n // Set up postMessage listener for cross-origin communication\n if (this.messageEventHandler) {\n window.addEventListener(\"message\", this.messageEventHandler);\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 } else {\n this.logger.error(\n \"messageEventHandler was not defined when trying to add listener.\",\n );\n }\n\n // Try to detect redirect to our domain\n try {\n const currentIframeHref =\n this.iframeElement.contentWindow.location.href;\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 if (\n this.iframeElement.contentDocument &&\n this.iframeElement.contentDocument.body\n ) {\n this.setupSignalObserver(this.iframeElement.contentDocument);\n }\n }\n } catch (error) {\n this.logger.error(\"Error checking iframe href\", {\n error,\n iframeSrc: this.iframeElement?.src,\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 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 reject(new Error(\"Iframe failed to load.\"));\n this.cleanup();\n };\n }\n\n /**\n * Starts the authentication process\n * @returns A promise that resolves with the authentication result\n * @throws {CivicAuthError} If authentication fails or times out\n */\n async startAuthentication(): Promise<AuthResult> {\n if (!this.endpoints) {\n const error = new CivicAuthError(\n \"OAuth endpoints not initialized. Please wait for initialization to complete.\",\n CivicAuthErrorCode.ENDPOINTS_NOT_INITIALIZED,\n );\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: error.message,\n });\n throw error;\n }\n\n if (this.authPromise) {\n this.logger.info(\n \"Authentication already in progress, returning existing promise\",\n );\n return this.authPromise;\n }\n\n const fullAuthUrl = await this.buildAuthUrl();\n\n this.logger.info(\"Starting authentication process\", {\n constructedIframeUrl: fullAuthUrl,\n displayMode: this.config.displayMode,\n authProcessTimeout: this.config.authProcessTimeout,\n });\n\n this.authPromise = new Promise<AuthResult>((resolve, reject) => {\n this.authPromiseResolve = resolve;\n this.authPromiseReject = reject;\n\n // Handle different display modes\n switch (this.config.displayMode) {\n case \"redirect\":\n // For redirect mode, just navigate to the auth URL\n window.location.href = fullAuthUrl;\n break;\n\n case \"new_tab\":\n this.handleNewTabAuth(fullAuthUrl, reject);\n break;\n\n case \"iframe\":\n default:\n this.handleIframeAuth(fullAuthUrl, reject);\n break;\n }\n\n // Set up timeout for all display modes\n if (\n this.config.authProcessTimeout &&\n this.config.authProcessTimeout > 0\n ) {\n this.logger.debug(\"Setting up authentication timeout\", {\n authProcessTimeout: this.config.authProcessTimeout,\n displayMode: this.config.displayMode,\n });\n this.authProcessTimeoutHandle = window.setTimeout(() => {\n this.logger.warn(\"Authentication timed out\", {\n displayMode: this.config.displayMode,\n currentOrigin: window.location.origin,\n });\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: \"Authentication timed out\",\n });\n reject(new Error(\"Authentication timed out.\"));\n this.cleanup();\n }, this.config.authProcessTimeout);\n }\n });\n\n return this.authPromise;\n }\n\n /**\n * Cleans up resources and event listeners\n */\n public cleanup(): void {\n this.logger.info(\"Cleaning up iframe authentication client\");\n\n if (this.observer) {\n this.logger.debug(\"Disconnecting mutation observer\");\n this.observer.disconnect();\n this.observer = undefined;\n }\n\n if (this.messageEventHandler) {\n window.removeEventListener(\"message\", this.messageEventHandler);\n this.logger.debug(\"Removed 'message' event listener from window.\");\n }\n\n if (this.iframeElement) {\n this.logger.debug(\"Removing iframe element\");\n removeIframe(this.iframeElement);\n this.iframeElement = undefined;\n }\n\n if (this.authProcessTimeoutHandle) {\n this.logger.debug(\"Clearing authentication process timeout\");\n window.clearTimeout(this.authProcessTimeoutHandle);\n this.authProcessTimeoutHandle = undefined;\n }\n\n this.logger.debug(\"Resetting promise state\");\n this.authPromise = undefined;\n this.authPromiseResolve = undefined;\n this.authPromiseReject = undefined;\n }\n\n private async handleCallback(): Promise<void> {\n try {\n const callbackHandled = await handleOAuthRedirectPage({\n clientId: this.config.clientId,\n oauthServer: this.config.oauthServerBaseUrl,\n redirectUrl: this.config.redirectUrl,\n textSignals: {\n success: this.config.textSignals.success,\n error: this.config.textSignals.error || \"Authentication failed\",\n },\n });\n\n if (callbackHandled) {\n const successSignal = document.getElementById(\n CONSTANTS.SUCCESS_SIGNAL_ID,\n );\n const errorSignal = document.getElementById(CONSTANTS.ERROR_SIGNAL_ID);\n\n if (successSignal) {\n let userInfo = null;\n const userInfoAttr = successSignal.getAttribute(\"data-user-info\");\n if (userInfoAttr) {\n try {\n userInfo = JSON.parse(userInfoAttr);\n } catch (error) {\n this.logger.error(\"Failed to parse user info:\", { error });\n }\n }\n this.config.events?.emit(AuthEvent.SIGN_IN_COMPLETE, {\n detail: \"Callback processed successfully\",\n user: userInfo,\n });\n } else if (errorSignal) {\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: errorSignal.textContent || \"Unknown error during callback\",\n });\n }\n }\n } catch (error) {\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail:\n error instanceof Error\n ? error.message\n : \"Unknown error during callback\",\n });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CivicAuth.js","sourceRoot":"","sources":["../../../src/vanillajs/auth/CivicAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEtD,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D;;GAEG;AACH,MAAM,CAAN,IAAY,kBA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index.js\";\nimport type { AuthenticationEvents } from \"./AuthenticationEvents.js\";\nimport { LocalStorageAdapter } from \"../../browser/storage.js\";\nimport { handleOAuthRedirectPage } from \"./OAuthCallbackHandler.js\";\nimport type { Endpoints, DisplayMode, AuthStorage } from \"../../types.js\";\nimport { buildAuthUrl } from \"../utils/auth-utils.js\";\nimport type { AuthResult, Session } from \"../types/index.js\";\nimport {\n createLogger,\n configureLogging,\n setCurrentLogger,\n} from \"../utils/logger.js\";\nimport { SignalObserver } from \"../iframe/SignalObserver.js\";\nimport { GenericPublicClientPKCEProducer } from \"../../services/PKCE.js\";\nimport { generateState } from \"../../lib/oauth.js\";\nimport { SessionManager } from \"./SessionManager.js\";\nimport { IframeManager } from \"../iframe/IframeManager.js\";\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 INVALID_MESSAGE = \"INVALID_MESSAGE\",\n}\n\n/**\n * Constants for the auth client\n */\nconst 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 */\ntype AuthMessageType = \"auth_success\" | \"auth_error\";\n\ninterface AuthMessage {\n type: AuthMessageType;\n detail?: string;\n data?: unknown;\n error?: unknown;\n}\n\nclass 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 /** 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 */\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 */\n displayMode?: DisplayMode;\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 */\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 prompt parameter */\n prompt?: string;\n /** Initial state for OAuth flow */\n initialState?: string;\n /** Logging configuration */\n logging?: LoggingConfig;\n}\n\nexport interface LoggingConfig {\n enabled: boolean;\n namespace?: string;\n level?: \"debug\" | \"info\" | \"warn\" | \"error\";\n}\n\n/**\n * Process the configuration with defaults\n */\nfunction processConfigWithDefaults(\n config: CivicAuthClientConfig,\n): CivicAuthClientConfig & {\n storageAdapter: AuthStorage;\n logging: LoggingConfig;\n displayMode: DisplayMode;\n authProcessTimeout: number;\n iframeId: string;\n} {\n const loggingConfig: LoggingConfig = {\n enabled: true,\n namespace: \"iframe\",\n level: \"debug\" as const,\n ...config.logging,\n };\n\n return {\n ...config,\n displayMode: config.displayMode || \"iframe\",\n authProcessTimeout:\n config.authProcessTimeout || CONSTANTS.DEFAULT_AUTH_PROCESS_TIMEOUT,\n iframeId: config.iframeId || CONSTANTS.DEFAULT_IFRAME_ID,\n logging: loggingConfig,\n storageAdapter: config.storageAdapter || new LocalStorageAdapter(),\n };\n}\n\n/**\n * CivicAuth client for handling OAuth authentication\n */\nexport class CivicAuth {\n /**\n * Internal configuration with all optional properties resolved to required ones.\n *\n * We extend CivicAuthClientConfig rather than making these properties required\n * in the public interface to maintain better DX (optional properties) while\n * ensuring type safety internally after defaults are applied.\n */\n private config: CivicAuthClientConfig & {\n storageAdapter: AuthStorage;\n logging: LoggingConfig;\n displayMode: DisplayMode;\n authProcessTimeout: number;\n iframeId: string;\n };\n private iframeElement?: HTMLIFrameElement;\n private observer?: MutationObserver;\n private authPromise?: Promise<AuthResult>;\n private authPromiseResolve?: (value: AuthResult) => void;\n private authPromiseReject?: (reason?: Error) => void;\n private authProcessTimeoutHandle?: number;\n private messageEventHandler?: (event: MessageEvent) => void;\n private storage: AuthStorage;\n private endpoints?: Endpoints;\n private logger: ReturnType<typeof createLogger>;\n private sessionManager?: SessionManager;\n private iframeManager?: IframeManager;\n\n /**\n * Private constructor for CivicAuth.\n * Use {@link CivicAuth.create} to create a new instance.\n * @param config - Configuration options for the auth client\n * @throws {CivicAuthError} If required configuration is missing\n * @private\n */\n private constructor(config: CivicAuthClientConfig) {\n // Process config with defaults\n this.config = processConfigWithDefaults(config);\n\n // Configure logging based on config\n configureLogging(this.config.logging);\n\n // Initialize logger based on config\n if (this.config.logging?.enabled) {\n const namespace = this.config.logging.namespace || \"iframe\";\n this.logger = createLogger(namespace);\n } else {\n // Create a no-op logger when logging is disabled\n this.logger = {\n debug: () => {},\n info: () => {},\n warn: () => {},\n error: () => {},\n };\n }\n\n // Set this logger as the current logger\n setCurrentLogger(this.logger);\n\n // Use the storage adapter from processed config (guaranteed to be present)\n this.storage = this.config.storageAdapter;\n\n // Initialize SessionManager if events are provided\n if (config.events) {\n this.sessionManager = new SessionManager(this.storage, config.events);\n }\n\n // Validate required configuration\n const requiredConfigs = [\n { key: \"clientId\", value: config.clientId },\n { key: \"targetContainerElement\", value: config.targetContainerElement },\n { key: \"textSignals.success\", value: config.textSignals?.success },\n ];\n\n for (const { key, value } of requiredConfigs) {\n if (!value) {\n throw new CivicAuthError(\n `CivicAuth: ${key} is required.`,\n CivicAuthErrorCode.CONFIG_REQUIRED,\n );\n }\n }\n\n this.messageEventHandler = this.handleIframeMessage.bind(this);\n }\n\n /**\n * Creates and initializes a new instance of CivicAuth.\n * This is the recommended way to create a CivicAuth instance.\n *\n * @param config - Configuration options for the auth client\n * @returns A promise that resolves with the initialized CivicAuth instance\n * @throws {CivicAuthError} If initialization fails or required configuration is missing\n *\n * @example\n * ```typescript\n * const auth = await CivicAuth.create({\n * clientId: \"your-client-id\",\n * redirectUrl: \"https://your-app.com/callback\",\n * oauthServerBaseUrl: \"https://auth-server.com/\",\n * scopes: [\"openid\", \"profile\"],\n * targetContainerElement: \"auth-container\",\n * textSignals: {\n * success: \"Authentication successful!\"\n * }\n * });\n * ```\n */\n public static async create(\n config: CivicAuthClientConfig,\n ): Promise<CivicAuth> {\n const instance = new CivicAuth(config);\n await instance.init();\n return instance;\n }\n\n /**\n * Initializes the auth client and checks for callback handling\n * @throws {CivicAuthError} If initialization fails\n */\n private async init(): Promise<void> {\n try {\n // Get OAuth endpoints from well-known configuration\n this.endpoints = {\n auth: `${this.config.oauthServerBaseUrl}auth`,\n token: `${this.config.oauthServerBaseUrl}token`,\n jwks: `${this.config.oauthServerBaseUrl}jwks`,\n userinfo: `${this.config.oauthServerBaseUrl}userinfo`,\n endsession: `${this.config.oauthServerBaseUrl}endsession`,\n };\n\n // Initialize SessionManager with auth config for token refresh\n if (this.sessionManager) {\n const authConfig = {\n clientId: this.config.clientId,\n redirectUrl: this.config.redirectUrl,\n oauthServer: this.config.oauthServerBaseUrl,\n scopes: this.config.scopes,\n endpoints: this.endpoints,\n };\n await this.sessionManager.initializeWithAuthConfig(authConfig);\n }\n\n // Check if we're on the callback page\n if (window.location.href.startsWith(this.config.redirectUrl)) {\n await this.handleCallback();\n }\n } catch (error) {\n const errorMessage =\n error instanceof Error\n ? error.message\n : \"Failed to initialize authentication\";\n this.logger.error(\"Failed to initialize CivicAuth:\", { error });\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: errorMessage,\n });\n throw new CivicAuthError(errorMessage, CivicAuthErrorCode.INIT_FAILED);\n }\n }\n\n /**\n * Gets the container element for the auth iframe\n * @returns The container element or null if not found\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 return this.config.targetContainerElement;\n }\n\n /**\n * Determines the appropriate iframe display mode based on container characteristics\n * @param container The HTML element that will contain the iframe\n * @returns \"modal\" for full-screen overlay or \"embedded\" for in-container display\n */\n private determineIframeDisplayMode(\n container: HTMLElement,\n ): \"modal\" | \"embedded\" {\n // Use explicit config if provided\n if (this.config.iframeDisplayMode) {\n this.logger.debug(\n `Using configured iframe display mode: ${this.config.iframeDisplayMode}`,\n );\n return this.config.iframeDisplayMode;\n }\n\n // Analyze container characteristics to determine best display mode\n const containerRect = container.getBoundingClientRect();\n const containerStyles = window.getComputedStyle(container);\n\n // Get container dimensions\n const containerWidth = containerRect.width;\n const containerHeight = containerRect.height;\n\n // Check if container is positioned in a way that suggests it's meant for modal display\n const isFullScreenContainer =\n containerStyles.position === \"fixed\" &&\n (containerWidth >= window.innerWidth * 0.9 ||\n containerHeight >= window.innerHeight * 0.9);\n\n // Modal mode thresholds - if container is too small, use modal for better UX\n const MIN_EMBEDDED_WIDTH = 320; // Same as modal content wrapper width\n const MIN_EMBEDDED_HEIGHT = 400; // Reasonable minimum for embedded auth flow\n\n // Determine mode based on container characteristics\n if (isFullScreenContainer) {\n this.logger.debug(\n \"Container appears to be full-screen positioned, using modal mode\",\n { containerWidth, containerHeight, position: containerStyles.position },\n );\n return \"modal\";\n }\n\n if (\n containerWidth < MIN_EMBEDDED_WIDTH ||\n containerHeight < MIN_EMBEDDED_HEIGHT\n ) {\n this.logger.debug(\n `Container too small for embedded mode (${containerWidth}x${containerHeight}), using modal mode`,\n {\n containerWidth,\n containerHeight,\n MIN_EMBEDDED_WIDTH,\n MIN_EMBEDDED_HEIGHT,\n },\n );\n return \"modal\";\n }\n\n // Check if container has sufficient space and is properly positioned for embedding\n const hasAdequateSpace =\n containerWidth >= MIN_EMBEDDED_WIDTH &&\n containerHeight >= MIN_EMBEDDED_HEIGHT;\n const isEmbeddablePosition =\n containerStyles.position === \"relative\" ||\n containerStyles.position === \"static\" ||\n containerStyles.position === \"\";\n\n if (hasAdequateSpace && isEmbeddablePosition) {\n this.logger.debug(\n \"Container has adequate space and positioning for embedded mode\",\n { containerWidth, containerHeight, position: containerStyles.position },\n );\n return \"embedded\";\n }\n\n // Default to modal mode if container characteristics are unclear\n this.logger.debug(\n \"Container characteristics unclear, defaulting to modal mode for better UX\",\n { containerWidth, containerHeight, position: containerStyles.position },\n );\n return \"modal\";\n }\n\n /**\n * Builds the authentication URL with PKCE challenge\n * @returns The complete authentication URL\n * @throws {CivicAuthError} If endpoints are not initialized\n */\n private async buildAuthUrl(): Promise<string> {\n if (!this.endpoints) {\n throw new CivicAuthError(\n \"OAuth endpoints not initialized. Please wait for initialization to complete.\",\n CivicAuthErrorCode.ENDPOINTS_NOT_INITIALIZED,\n );\n }\n\n // Use storage directly since it's now AuthStorage\n const pkceProducer = new GenericPublicClientPKCEProducer(this.storage);\n const codeChallenge = await pkceProducer.getCodeChallenge();\n const state =\n this.config.initialState ||\n generateState({\n displayMode: this.config.displayMode || \"iframe\",\n });\n\n return buildAuthUrl({\n endpoints: this.endpoints,\n clientId: this.config.clientId,\n redirectUrl: this.config.redirectUrl,\n scopes: this.config.scopes,\n codeChallenge,\n state,\n prompt: this.config.prompt,\n });\n }\n\n private handleIframeMessage(event: MessageEvent): void {\n const expectedOrigin = 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 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 private isValidMessageSource(\n event: MessageEvent,\n expectedOrigin: string,\n ): boolean {\n const isValidOrigin = event.origin === expectedOrigin;\n const isValidSource = event.source === this.iframeElement?.contentWindow;\n\n if (!isValidOrigin) {\n this.logger.warn(\"Ignored message from unexpected origin.\", {\n receivedOrigin: event.origin,\n expectedOrigin,\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 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 AuthMessage;\n const messageType = message?.type;\n\n switch (messageType) {\n case \"auth_success\":\n this.handleAuthSuccess(message);\n break;\n case \"auth_error\":\n this.handleAuthError(message);\n break;\n default:\n this.logger.debug(\n \"Message from iframe did not match expected types (auth_success, auth_error)\",\n { data: event.data },\n );\n }\n }\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.authPromiseResolve?.((data?.data as AuthResult) || {});\n this.cleanup();\n }\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 this.authPromiseReject?.(\n new CivicAuthError(\n data?.detail || \"Error signal received via postMessage\",\n CivicAuthErrorCode.INVALID_MESSAGE,\n ),\n );\n this.cleanup();\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.authPromiseResolve,\n this.authPromiseReject,\n () => this.cleanup(),\n );\n\n signalObserver.setup(iframeDoc);\n }\n\n private async handleNewTabAuth(\n fullAuthUrl: string,\n reject: (error: Error) => void,\n ): Promise<void> {\n const popupWindow = window.open(fullAuthUrl, \"_blank\");\n if (!popupWindow) {\n const error = new CivicAuthError(\n \"Failed to open popup window. Please check your browser's popup settings.\",\n CivicAuthErrorCode.INIT_FAILED,\n );\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: error.message,\n });\n reject(error);\n }\n }\n\n private async handleIframeAuth(\n fullAuthUrl: string,\n reject: (error: Error) => void,\n ): Promise<void> {\n const container = this.getContainerElement();\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 reject(error);\n return;\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 });\n\n // Determine the actual display mode for IframeManager\n // For iframe displayMode, we need to decide between modal and embedded based on container\n const iframeDisplayMode = this.determineIframeDisplayMode(container);\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 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 reject(\n new CivicAuthError(\n \"Authentication cancelled by user\",\n CivicAuthErrorCode.AUTH_PROCESS_TIMEOUT,\n ),\n );\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.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 reject(new Error(errorMsg));\n this.cleanup();\n return;\n }\n\n // Set up postMessage listener for cross-origin communication\n if (this.messageEventHandler) {\n window.addEventListener(\"message\", this.messageEventHandler);\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 } else {\n this.logger.error(\n \"messageEventHandler was not defined when trying to add listener.\",\n );\n }\n\n // Try to detect redirect to our domain\n try {\n const currentIframeHref =\n this.iframeElement.contentWindow.location.href;\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 if (\n this.iframeElement.contentDocument &&\n this.iframeElement.contentDocument.body\n ) {\n this.setupSignalObserver(this.iframeElement.contentDocument);\n }\n }\n } catch (error) {\n this.logger.error(\"Error checking iframe href\", {\n error,\n iframeSrc: this.iframeElement?.src,\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 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 reject(new Error(\"Iframe failed to load.\"));\n this.cleanup();\n };\n }\n\n /**\n * Starts the authentication process\n * @returns A promise that resolves with the authentication result\n * @throws {CivicAuthError} If authentication fails or times out\n */\n async startAuthentication(): Promise<AuthResult> {\n if (!this.endpoints) {\n const error = new CivicAuthError(\n \"OAuth endpoints not initialized. Please wait for initialization to complete.\",\n CivicAuthErrorCode.ENDPOINTS_NOT_INITIALIZED,\n );\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: error.message,\n });\n throw error;\n }\n\n if (this.authPromise) {\n this.logger.info(\n \"Authentication already in progress, returning existing promise\",\n );\n return this.authPromise;\n }\n\n const fullAuthUrl = await this.buildAuthUrl();\n\n this.logger.info(\"Starting authentication process\", {\n constructedIframeUrl: fullAuthUrl,\n displayMode: this.config.displayMode,\n authProcessTimeout: this.config.authProcessTimeout,\n });\n\n this.authPromise = new Promise<AuthResult>((resolve, reject) => {\n this.authPromiseResolve = resolve;\n this.authPromiseReject = reject;\n\n // Handle different display modes\n switch (this.config.displayMode) {\n case \"redirect\":\n // For redirect mode, just navigate to the auth URL\n window.location.href = fullAuthUrl;\n break;\n\n case \"new_tab\":\n this.handleNewTabAuth(fullAuthUrl, reject);\n break;\n\n case \"iframe\":\n default:\n this.handleIframeAuth(fullAuthUrl, reject);\n break;\n }\n\n // Set up timeout for all display modes\n if (\n this.config.authProcessTimeout &&\n this.config.authProcessTimeout > 0\n ) {\n this.logger.debug(\"Setting up authentication timeout\", {\n authProcessTimeout: this.config.authProcessTimeout,\n displayMode: this.config.displayMode,\n });\n this.authProcessTimeoutHandle = window.setTimeout(() => {\n this.logger.warn(\"Authentication timed out\", {\n displayMode: this.config.displayMode,\n currentOrigin: window.location.origin,\n });\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: \"Authentication timed out\",\n });\n reject(new Error(\"Authentication timed out.\"));\n this.cleanup();\n }, this.config.authProcessTimeout);\n }\n });\n\n return this.authPromise;\n }\n\n /**\n * Cleans up resources and event listeners\n */\n public cleanup(): void {\n this.logger.info(\"Cleaning up iframe authentication client\");\n\n if (this.observer) {\n this.logger.debug(\"Disconnecting mutation observer\");\n this.observer.disconnect();\n this.observer = undefined;\n }\n\n if (this.messageEventHandler) {\n window.removeEventListener(\"message\", this.messageEventHandler);\n this.logger.debug(\"Removed 'message' event listener from window.\");\n }\n\n if (this.iframeManager) {\n this.logger.debug(\"Cleaning up iframe manager\");\n this.iframeManager.cleanup();\n this.iframeManager = undefined;\n }\n\n // Reset iframe element reference (actual removal handled by IframeManager)\n if (this.iframeElement) {\n this.iframeElement = undefined;\n }\n\n if (this.authProcessTimeoutHandle) {\n this.logger.debug(\"Clearing authentication process timeout\");\n window.clearTimeout(this.authProcessTimeoutHandle);\n this.authProcessTimeoutHandle = undefined;\n }\n\n this.logger.debug(\"Resetting promise state\");\n this.authPromise = undefined;\n this.authPromiseResolve = undefined;\n this.authPromiseReject = undefined;\n }\n\n private async handleCallback(): Promise<void> {\n try {\n const callbackHandled = await handleOAuthRedirectPage({\n clientId: this.config.clientId,\n oauthServer: this.config.oauthServerBaseUrl,\n redirectUrl: this.config.redirectUrl,\n textSignals: {\n success: this.config.textSignals.success,\n error: this.config.textSignals.error || \"Authentication failed\",\n },\n storageAdapter: this.storage,\n });\n\n if (callbackHandled) {\n const successSignal = document.getElementById(\n CONSTANTS.SUCCESS_SIGNAL_ID,\n );\n const errorSignal = document.getElementById(CONSTANTS.ERROR_SIGNAL_ID);\n\n if (successSignal) {\n let userInfo = null;\n const userInfoAttr = successSignal.getAttribute(\"data-user-info\");\n if (userInfoAttr) {\n try {\n userInfo = JSON.parse(userInfoAttr);\n } catch (error) {\n this.logger.error(\"Failed to parse user info:\", { error });\n }\n }\n this.config.events?.emit(AuthEvent.SIGN_IN_COMPLETE, {\n detail: \"Callback processed successfully\",\n user: userInfo,\n });\n } else if (errorSignal) {\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail: errorSignal.textContent || \"Unknown error during callback\",\n });\n }\n }\n } catch (error) {\n this.config.events?.emit(AuthEvent.SIGN_IN_ERROR, {\n detail:\n error instanceof Error\n ? error.message\n : \"Unknown error during callback\",\n });\n }\n }\n\n /**\n * Get the current session\n */\n public async getCurrentSession(): Promise<Session | null> {\n return this.sessionManager?.getCurrentSession() || null;\n }\n\n /**\n * Check if user is authenticated\n */\n public async isAuthenticated(): Promise<boolean> {\n return this.sessionManager?.isAuthenticated() || false;\n }\n\n /**\n * Get the current user\n */\n public async getCurrentUser() {\n return this.sessionManager?.getCurrentUser() || null;\n }\n\n /**\n * Clear the current session\n */\n public async clearSession(): Promise<void> {\n if (!this.sessionManager) {\n throw new Error(\n \"SessionManager not initialized. Provide events in config.\",\n );\n }\n return this.sessionManager.clearSession();\n }\n\n /**\n * Manually refresh tokens\n */\n public async refreshTokens(): Promise<void> {\n if (!this.sessionManager) {\n throw new Error(\n \"SessionManager not initialized. Provide events in config.\",\n );\n }\n return this.sessionManager.refreshTokens();\n }\n\n /**\n * Get token refresher state for debugging\n */\n public getTokenRefresherState() {\n return this.sessionManager?.getTokenRefresherState() || null;\n }\n\n /**\n * Update the iframe display mode\n * @param mode - The display mode to use for the iframe\n */\n public setIframeDisplayMode(mode: \"modal\" | \"embedded\"): void {\n this.config.iframeDisplayMode = mode;\n this.logger.debug(`Iframe display mode updated to: ${mode}`);\n }\n\n /**\n * Get the current iframe display mode\n * @returns The current iframe display mode\n */\n public getIframeDisplayMode(): \"modal\" | \"embedded\" | undefined {\n return this.config.iframeDisplayMode;\n }\n\n /**\n * Destroy the auth client and clean up all resources\n */\n public async destroy(): Promise<void> {\n this.cleanup();\n await this.sessionManager?.destroy();\n this.sessionManager = undefined;\n this.logger.info(\"CivicAuth destroyed\");\n }\n}\n"]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth Callback Handler for Vanilla JavaScript Applications
|
|
3
|
+
*
|
|
4
|
+
* This module provides functionality for handling OAuth redirect/callback pages in vanilla JavaScript
|
|
5
|
+
* applications using the Civic Auth system. It processes the OAuth authorization code flow completion
|
|
6
|
+
* by exchanging authorization codes for access tokens and managing the authentication state.
|
|
7
|
+
*
|
|
8
|
+
* Key responsibilities:
|
|
9
|
+
* - Process OAuth callback URL parameters (code, state)
|
|
10
|
+
* - Exchange authorization codes for access tokens using PKCE
|
|
11
|
+
* - Store tokens and user session data using shared utilities
|
|
12
|
+
* - Create DOM signals for iframe-based authentication flows
|
|
13
|
+
* - Handle error states and cleanup during the OAuth flow
|
|
14
|
+
*
|
|
15
|
+
* This module works in conjunction with:
|
|
16
|
+
* - CivicAuth class for initiating OAuth flows
|
|
17
|
+
* - SignalObserver for detecting authentication completion in iframes
|
|
18
|
+
* - Shared token storage utilities for consistent state management
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // In an OAuth callback page
|
|
23
|
+
* import { handleOAuthRedirectPage, LocalStorageAdapter } from '@civic/auth/vanillajs';
|
|
24
|
+
*
|
|
25
|
+
* const handled = await handleOAuthRedirectPage({
|
|
26
|
+
* clientId: 'your-client-id',
|
|
27
|
+
* redirectUrl: 'https://your-app.com/callback',
|
|
28
|
+
* oauthServer: 'https://auth.civic.com/oauth/',
|
|
29
|
+
* textSignals: {
|
|
30
|
+
* success: 'Authentication successful!',
|
|
31
|
+
* error: 'Authentication failed!'
|
|
32
|
+
* },
|
|
33
|
+
* storageAdapter: new LocalStorageAdapter()
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
import { getCurrentLogger } from "../utils/logger.js";
|
|
38
|
+
import type { AuthStorage, OIDCTokenResponseBody } from "../../types.js";
|
|
39
|
+
/**
|
|
40
|
+
* Store tokens using the shared utilities from /shared/lib
|
|
41
|
+
* This ensures consistency with the React implementation and also handles user session storage
|
|
42
|
+
*/
|
|
43
|
+
export declare function storeTokens(tokens: OIDCTokenResponseBody, storageAdapter: AuthStorage, loggerInstance?: {
|
|
44
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
45
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
46
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
47
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
48
|
+
}): Promise<object | null>;
|
|
49
|
+
export interface HandleOAuthRedirectConfig {
|
|
50
|
+
clientId: string;
|
|
51
|
+
redirectUrl: string;
|
|
52
|
+
oauthServer: string;
|
|
53
|
+
textSignals: {
|
|
54
|
+
success: string;
|
|
55
|
+
error: string;
|
|
56
|
+
};
|
|
57
|
+
storageAdapter: AuthStorage;
|
|
58
|
+
logger?: ReturnType<typeof getCurrentLogger>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Handle OAuth redirect page processing for vanilla JavaScript applications.
|
|
62
|
+
* This function processes the OAuth callback URL parameters and exchanges the authorization code for tokens.
|
|
63
|
+
*
|
|
64
|
+
* @param config - Configuration object for handling the OAuth redirect
|
|
65
|
+
* @param config.clientId - OAuth client ID
|
|
66
|
+
* @param config.redirectUrl - URL to redirect to after authentication
|
|
67
|
+
* @param config.oauthServer - OAuth server base URL
|
|
68
|
+
* @param config.textSignals - Text signals for success and error states
|
|
69
|
+
* @param config.storageAdapter - Storage adapter for persisting auth state (required)
|
|
70
|
+
* @param config.logger - Optional logger instance
|
|
71
|
+
* @returns Promise<boolean> - Returns true if callback was handled, false otherwise
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* import { handleOAuthRedirectPage, LocalStorageAdapter } from '@civic/auth/vanillajs';
|
|
76
|
+
*
|
|
77
|
+
* const handled = await handleOAuthRedirectPage({
|
|
78
|
+
* clientId: 'your-client-id',
|
|
79
|
+
* redirectUrl: 'https://your-app.com/callback',
|
|
80
|
+
* oauthServer: 'https://auth.civic.com/oauth/',
|
|
81
|
+
* textSignals: {
|
|
82
|
+
* success: 'Authentication successful!',
|
|
83
|
+
* error: 'Authentication failed!'
|
|
84
|
+
* },
|
|
85
|
+
* storageAdapter: new LocalStorageAdapter()
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function handleOAuthRedirectPage(config: HandleOAuthRedirectConfig): Promise<boolean>;
|
|
90
|
+
//# sourceMappingURL=OAuthCallbackHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OAuthCallbackHandler.d.ts","sourceRoot":"","sources":["../../../src/vanillajs/auth/OAuthCallbackHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAWH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEzE;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,qBAAqB,EAC7B,cAAc,EAAE,WAAW,EAC3B,cAAc;;;;;CAAqB,GAClC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAyBxB;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,cAAc,EAAE,WAAW,CAAC;IAC5B,MAAM,CAAC,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,OAAO,CAAC,CAmElB"}
|