@civic/auth 0.13.0 → 0.13.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +102 -1
  3. package/dist/lib/analytics.d.ts.map +1 -1
  4. package/dist/lib/jwt.d.ts.map +1 -1
  5. package/dist/lib/logger.d.ts.map +1 -1
  6. package/dist/lib/oauth.d.ts +12 -1
  7. package/dist/lib/oauth.d.ts.map +1 -1
  8. package/dist/lib/oauth.js +29 -1
  9. package/dist/lib/oauth.js.map +1 -1
  10. package/dist/lib/obj.d.ts.map +1 -1
  11. package/dist/lib/postMessage.d.ts.map +1 -1
  12. package/dist/lib/windowUtil.d.ts.map +1 -1
  13. package/dist/nextjs/config.d.ts +2 -11
  14. package/dist/nextjs/config.d.ts.map +1 -1
  15. package/dist/nextjs/config.js.map +1 -1
  16. package/dist/nextjs/cookies.d.ts.map +1 -1
  17. package/dist/nextjs/cookies.js +11 -10
  18. package/dist/nextjs/cookies.js.map +1 -1
  19. package/dist/nextjs/hooks/useInitialAuthConfig.d.ts.map +1 -1
  20. package/dist/nextjs/index.d.ts.map +1 -1
  21. package/dist/nextjs/middleware.d.ts.map +1 -1
  22. package/dist/nextjs/middleware.js +18 -3
  23. package/dist/nextjs/middleware.js.map +1 -1
  24. package/dist/nextjs/providers/NextAuthProviderClient.d.ts.map +1 -1
  25. package/dist/nextjs/routeHandler.d.ts.map +1 -1
  26. package/dist/nextjs/routeHandler.js +21 -92
  27. package/dist/nextjs/routeHandler.js.map +1 -1
  28. package/dist/nextjs/utils.d.ts +9 -3
  29. package/dist/nextjs/utils.d.ts.map +1 -1
  30. package/dist/nextjs/utils.js +20 -61
  31. package/dist/nextjs/utils.js.map +1 -1
  32. package/dist/react-router-7/routeHandler.d.ts.map +1 -1
  33. package/dist/reactjs/components/ButtonContentOrLoader.d.ts.map +1 -1
  34. package/dist/reactjs/components/SignInButton.d.ts.map +1 -1
  35. package/dist/reactjs/components/SignOutButton.d.ts.map +1 -1
  36. package/dist/reactjs/components/UserButton.d.ts.map +1 -1
  37. package/dist/reactjs/components/utils.d.ts.map +1 -1
  38. package/dist/reactjs/hooks/useToken.d.ts.map +1 -1
  39. package/dist/reactjs/hooks/useUser.d.ts.map +1 -1
  40. package/dist/reactjs/styles/colors.d.ts.map +1 -1
  41. package/dist/server/config.d.ts +23 -0
  42. package/dist/server/config.d.ts.map +1 -1
  43. package/dist/server/config.js.map +1 -1
  44. package/dist/server/session.d.ts +57 -0
  45. package/dist/server/session.d.ts.map +1 -1
  46. package/dist/server/session.js +222 -9
  47. package/dist/server/session.js.map +1 -1
  48. package/dist/shared/components/LoadingIcon.d.ts.map +1 -1
  49. package/dist/shared/lib/cookieConfig.d.ts.map +1 -1
  50. package/dist/shared/lib/cookieConfig.js +6 -1
  51. package/dist/shared/lib/cookieConfig.js.map +1 -1
  52. package/dist/shared/lib/iframeUtils.d.ts.map +1 -1
  53. package/dist/shared/lib/session.d.ts.map +1 -1
  54. package/dist/shared/lib/types.d.ts +5 -1
  55. package/dist/shared/lib/types.d.ts.map +1 -1
  56. package/dist/shared/lib/types.js +4 -0
  57. package/dist/shared/lib/types.js.map +1 -1
  58. package/dist/shared/lib/util.d.ts +38 -1
  59. package/dist/shared/lib/util.d.ts.map +1 -1
  60. package/dist/shared/lib/util.js +104 -0
  61. package/dist/shared/lib/util.js.map +1 -1
  62. package/dist/shared/version.d.ts +1 -1
  63. package/dist/shared/version.d.ts.map +1 -1
  64. package/dist/shared/version.js +1 -1
  65. package/dist/shared/version.js.map +1 -1
  66. package/dist/utils.d.ts.map +1 -1
  67. package/dist/vanillajs/auth/handlers/MessageHandler.d.ts.map +1 -1
  68. package/dist/vanillajs/utils/logger.d.ts.map +1 -1
  69. package/package.json +1 -1
@@ -9,10 +9,10 @@ import { refreshTokens } from "../server/refresh.js";
9
9
  import { getVersion } from "../shared/index.js";
10
10
  import { ServerAuthenticationResolver } from "../server/ServerAuthenticationResolver.js";
11
11
  import { DEFAULT_AUTH_SERVER, JWT_PAYLOAD_KNOWN_CLAIM_KEYS, } from "../constants.js";
12
- import { displayModeFromState, loginSuccessUrlFromState } from "../lib/oauth.js";
12
+ import { displayModeFromState, injectLoginSuccessUrlIntoState, loginSuccessUrlFromState, } from "../lib/oauth.js";
13
13
  import { decodeJwt } from "jose";
14
- import { generateOauthLogoutUrl, getBackendEndpoints, resolveEndpointUrl, sanitizeReturnUrl, } from "../shared/lib/util.js";
15
- import { CodeVerifier } from "../shared/lib/types.js";
14
+ import { computeDeepLinkDestination, generateOauthLogoutUrl, getBackendEndpoints, prependBasePath, resolveEndpointUrl, sanitizeReturnUrl, } from "../shared/lib/util.js";
15
+ import { AUTH_REDIRECT_MARKER_MAX_AGE, AuthFlowCookie, CodeVerifier, } from "../shared/lib/types.js";
16
16
  import { loggers } from "../lib/logger.js";
17
17
  // Function to omit keys from an object
18
18
  const omitKeys = (keys, obj) => {
@@ -141,10 +141,29 @@ export class CivicAuth {
141
141
  * @returns The login URL
142
142
  */
143
143
  async buildLoginUrl(options) {
144
+ const logger = loggers.server;
145
+ let finalState = options?.state;
146
+ // If deep linking is enabled, read the return URL cookie and inject into state
147
+ if (this.authConfig.deepLinkHandling !== "disabled") {
148
+ try {
149
+ const returnUrl = await this.storage.get(AuthFlowCookie.RETURN_URL);
150
+ if (returnUrl) {
151
+ logger.debug("[buildLoginUrl] Found RETURN_URL cookie, injecting into state", { returnUrl });
152
+ // Inject the return URL into state, preserving any existing state
153
+ finalState = injectLoginSuccessUrlIntoState(finalState ?? null, returnUrl);
154
+ }
155
+ }
156
+ catch (error) {
157
+ logger.warn("[buildLoginUrl] Failed to read RETURN_URL cookie", {
158
+ error,
159
+ });
160
+ // Continue without the cookie - don't block login
161
+ }
162
+ }
144
163
  return buildLoginUrl({
145
164
  ...this.authConfig,
146
165
  scopes: options?.scopes,
147
- state: options?.state,
166
+ state: finalState,
148
167
  nonce: options?.nonce,
149
168
  framework: "server",
150
169
  sdkVersion: getVersion(),
@@ -220,6 +239,161 @@ export class CivicAuth {
220
239
  async clearTokens() {
221
240
  return clearTokensUtil(this.storage);
222
241
  }
242
+ /**
243
+ * Handles deep linking by computing the return URL and setting it as a cookie.
244
+ * This method encapsulates the deep-linking logic for use by middleware in any framework.
245
+ *
246
+ * The method automatically detects whether the user is at the login URL or a protected route
247
+ * and applies the appropriate logic:
248
+ *
249
+ * **At login URL:**
250
+ * - Auth redirect (marker present): Preserve existing deep link cookie
251
+ * - Fresh navigation with query params: Set cookie with query params
252
+ * - Fresh navigation without params: Clear stale cookie
253
+ *
254
+ * **At protected route:**
255
+ * - Always set the cookie to capture the deep link destination
256
+ *
257
+ * @param requestUrl - The full URL of the request being made (the page the user tried to access)
258
+ * @param originUrl - The origin URL of the application (e.g., "https://myapp.com")
259
+ * @returns The computed deep link destination, or null if deep linking is disabled or the URL is invalid
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * // In middleware for any framework
264
+ * if (!session.authenticated) {
265
+ * await civicAuth.handleDeepLinking(requestUrl, originUrl);
266
+ * }
267
+ * ```
268
+ */
269
+ async handleDeepLinking(requestUrl, originUrl) {
270
+ const logger = loggers.server;
271
+ const deepLinkHandling = this.authConfig.deepLinkHandling ?? "queryParamsOnly";
272
+ if (deepLinkHandling === "disabled") {
273
+ return null;
274
+ }
275
+ // Parse the request URL to extract path, search, and hash
276
+ let parsedUrl;
277
+ try {
278
+ parsedUrl = new URL(requestUrl, originUrl);
279
+ }
280
+ catch (error) {
281
+ logger.warn("[handleDeepLinking] Failed to parse request URL:", {
282
+ requestUrl,
283
+ originUrl,
284
+ error,
285
+ });
286
+ return null;
287
+ }
288
+ // Determine if we're at the login URL
289
+ const loginUrl = this.authConfig.loginUrl || "/";
290
+ const loginPathWithoutBasePath = loginUrl.startsWith("/")
291
+ ? loginUrl
292
+ : new URL(loginUrl, originUrl).pathname;
293
+ const isAtLoginUrl = parsedUrl.pathname === loginPathWithoutBasePath;
294
+ logger.debug("[handleDeepLinking]:", {
295
+ pathname: parsedUrl.pathname,
296
+ isAtLoginUrl,
297
+ loginUrl: loginPathWithoutBasePath,
298
+ });
299
+ if (isAtLoginUrl) {
300
+ // At login URL - use the updateDeepLinkCookie logic
301
+ return this.handleDeepLinkingAtLoginUrl(parsedUrl, originUrl);
302
+ }
303
+ // At protected route - set the deep link cookie
304
+ return this.handleDeepLinkingAtProtectedRoute(parsedUrl, originUrl);
305
+ }
306
+ /**
307
+ * Internal: Handles deep linking when at a protected route.
308
+ * Sets the cookie to capture the user's intended destination and the auth redirect marker.
309
+ */
310
+ async handleDeepLinkingAtProtectedRoute(parsedUrl, originUrl) {
311
+ const logger = loggers.server;
312
+ const deepLinkHandling = this.authConfig.deepLinkHandling ?? "queryParamsOnly";
313
+ const returnTo = computeDeepLinkDestination(parsedUrl.pathname, parsedUrl.search, parsedUrl.hash, originUrl, deepLinkHandling, this.authConfig.loginSuccessUrl);
314
+ if (!returnTo) {
315
+ logger.debug("[handleDeepLinking] No deep link destination computed (disabled or invalid URL)");
316
+ return null;
317
+ }
318
+ // Set the cookie with the computed return URL
319
+ await this.storage.set(AuthFlowCookie.RETURN_URL, returnTo, {});
320
+ logger.debug("[handleDeepLinking] Set RETURN_URL cookie", { returnTo });
321
+ // Also set the auth redirect marker since we're at a protected route
322
+ // and the user will be redirected to login
323
+ await this.storage.set(AuthFlowCookie.AUTH_REDIRECT_MARKER, "1", {
324
+ maxAge: AUTH_REDIRECT_MARKER_MAX_AGE,
325
+ });
326
+ logger.debug("[handleDeepLinking] Set auth redirect marker");
327
+ return returnTo;
328
+ }
329
+ /**
330
+ * Internal: Handles deep linking when at the login URL.
331
+ * Checks the auth redirect marker and handles appropriately.
332
+ */
333
+ async handleDeepLinkingAtLoginUrl(parsedUrl, originUrl) {
334
+ const logger = loggers.server;
335
+ const deepLinkHandling = this.authConfig.deepLinkHandling ?? "queryParamsOnly";
336
+ const hasQueryParams = parsedUrl.searchParams.size > 0;
337
+ // Check and clean up the auth redirect marker cookie
338
+ const isAuthRedirect = await this.storage.get(AuthFlowCookie.AUTH_REDIRECT_MARKER);
339
+ await this.storage.delete(AuthFlowCookie.AUTH_REDIRECT_MARKER);
340
+ // Get existing cookie to determine if we need to clear stale data
341
+ const existingCookie = await this.storage.get(AuthFlowCookie.RETURN_URL);
342
+ logger.debug("[handleDeepLinking] At login URL:", {
343
+ hasQueryParams,
344
+ isAuthRedirect: !!isAuthRedirect,
345
+ existingCookie,
346
+ });
347
+ if (isAuthRedirect) {
348
+ // This is a redirect from auth middleware - preserve the existing cookie
349
+ logger.debug("[handleDeepLinking] Auth redirect detected - preserving existing cookie");
350
+ return existingCookie;
351
+ }
352
+ // Fresh navigation
353
+ if (hasQueryParams) {
354
+ // User visited with query params - capture them
355
+ const returnTo = computeDeepLinkDestination(parsedUrl.pathname, parsedUrl.search, parsedUrl.hash, originUrl, deepLinkHandling, this.authConfig.loginSuccessUrl);
356
+ if (returnTo) {
357
+ // Set the cookie with the computed return URL
358
+ await this.storage.set(AuthFlowCookie.RETURN_URL, returnTo, {});
359
+ logger.debug(`[handleDeepLinking] Fresh visit with params - setting cookie to "${returnTo}"`);
360
+ return returnTo;
361
+ }
362
+ }
363
+ // Don't clear existing cookies on fresh visits - the user may be interacting
364
+ // with the login page (e.g., clicking radio buttons) which triggers new requests.
365
+ // The cookie has a limited lifetime and will expire naturally.
366
+ return null;
367
+ }
368
+ /**
369
+ * Sets the auth redirect marker cookie. This marker helps distinguish auth redirects
370
+ * from fresh navigations to the login page, preventing the deep link cookie from being
371
+ * incorrectly overwritten.
372
+ *
373
+ * **Note:** This method is automatically called by `handleDeepLinking` when the user is
374
+ * at a protected route. You typically do NOT need to call this method manually unless
375
+ * you have a specific use case where you're not using `handleDeepLinking`.
376
+ *
377
+ * @example
378
+ * ```typescript
379
+ * // In most cases, just call handleDeepLinking - it sets the marker automatically:
380
+ * if (!isAuthenticated) {
381
+ * await req.civicAuth.handleDeepLinking(requestUrl, originUrl);
382
+ * return res.redirect('/login');
383
+ * }
384
+ * ```
385
+ */
386
+ async setAuthRedirectMarker() {
387
+ const logger = loggers.server;
388
+ const deepLinkHandling = this.authConfig.deepLinkHandling ?? "queryParamsOnly";
389
+ if (deepLinkHandling === "disabled") {
390
+ return;
391
+ }
392
+ await this.storage.set(AuthFlowCookie.AUTH_REDIRECT_MARKER, "1", {
393
+ maxAge: AUTH_REDIRECT_MARKER_MAX_AGE,
394
+ });
395
+ logger.debug("[setAuthRedirectMarker] Set auth redirect marker cookie");
396
+ }
223
397
  /**
224
398
  * Framework-agnostic URL detection and resolution helpers
225
399
  * These methods handle proxy environments and can be used by any framework
@@ -342,6 +516,20 @@ export class CivicAuth {
342
516
  * ```
343
517
  */
344
518
  async handleCallback({ code, state, req }, options) {
519
+ const logger = loggers.server;
520
+ // Helper to clear the deep link cookie after successful auth.
521
+ // This is centralized here so all framework implementations benefit.
522
+ const clearReturnUrlCookie = async () => {
523
+ try {
524
+ await this.storage.delete(AuthFlowCookie.RETURN_URL);
525
+ logger.debug("[handleCallback] Cleared deep link cookie after successful auth");
526
+ }
527
+ catch (error) {
528
+ logger.warn("[handleCallback] Failed to clear deep link cookie", {
529
+ error,
530
+ });
531
+ }
532
+ };
345
533
  // Handle same-domain callback for iframe workaround
346
534
  if (isSameDomainCallback(req)) {
347
535
  try {
@@ -373,7 +561,13 @@ export class CivicAuth {
373
561
  newSearchParams.delete("loginSuccessUrl");
374
562
  // Use preserved deep link if available and valid, otherwise fall back to loginSuccessUrl or "/"
375
563
  // Note: Do NOT fall back to currentUrl.pathname as that's the callback URL, which would cause a loop
376
- const redirectUrl = loginSuccessUrl || this.authConfig.loginSuccessUrl || "/";
564
+ let redirectUrl = loginSuccessUrl || this.authConfig.loginSuccessUrl || "/";
565
+ // Apply basePath if configured
566
+ if (this.authConfig.basePath) {
567
+ redirectUrl = prependBasePath(redirectUrl, this.authConfig.basePath);
568
+ }
569
+ // Clear the deep link cookie after successful same-domain callback
570
+ await clearReturnUrlCookie();
377
571
  return {
378
572
  content: {
379
573
  success: true,
@@ -392,6 +586,8 @@ export class CivicAuth {
392
586
  try {
393
587
  tokens = await this.resolveOAuthAccessCode(code, state);
394
588
  user = getUserFromTokens(tokens);
589
+ // Clear the deep link cookie after successful token exchange
590
+ await clearReturnUrlCookie();
395
591
  }
396
592
  catch (error) {
397
593
  // Check if this is a code verifier error and we're in iframe mode
@@ -405,9 +601,13 @@ export class CivicAuth {
405
601
  // "User already authenticated, skipping iframe workaround",
406
602
  const user = await this.getUser();
407
603
  const loginSuccessUrlFromStateValue = loginSuccessUrlFromState(state);
408
- const frontendUrl = options?.frontendUrl ||
604
+ let frontendUrl = options?.frontendUrl ||
409
605
  loginSuccessUrlFromStateValue ||
410
606
  this.authConfig.loginSuccessUrl;
607
+ // Apply basePath to frontendUrl if configured
608
+ if (frontendUrl && this.authConfig.basePath) {
609
+ frontendUrl = prependBasePath(frontendUrl, this.authConfig.basePath);
610
+ }
411
611
  // Check if this is an iframe context - if so, generate iframe completion HTML
412
612
  const stateDisplayMode = displayModeFromState(state, undefined);
413
613
  const isConfiguredForIframe = stateDisplayMode === "iframe";
@@ -440,9 +640,13 @@ export class CivicAuth {
440
640
  if (isConfiguredForIframe && !this.authConfig.disableIframeDetection) {
441
641
  // Generate HTML that will trigger same-domain callback
442
642
  const loginSuccessUrlFromStateValue = loginSuccessUrlFromState(state);
443
- const frontendUrl = options?.frontendUrl ||
643
+ let frontendUrl = options?.frontendUrl ||
444
644
  loginSuccessUrlFromStateValue ||
445
645
  this.authConfig.loginSuccessUrl;
646
+ // Apply basePath to frontendUrl if configured
647
+ if (frontendUrl && this.authConfig.basePath) {
648
+ frontendUrl = prependBasePath(frontendUrl, this.authConfig.basePath);
649
+ }
446
650
  const callbackUrl = req.url || "";
447
651
  const sameDomainHtml = this.generateSameDomainCallbackHtml(callbackUrl, frontendUrl);
448
652
  return { content: sameDomainHtml };
@@ -458,9 +662,13 @@ export class CivicAuth {
458
662
  // Extract loginSuccessUrl from state if present
459
663
  const loginSuccessUrlFromStateValue = loginSuccessUrlFromState(state);
460
664
  // Priority: options.frontendUrl > loginSuccessUrl from state > config loginSuccessUrl
461
- const frontendUrl = options?.frontendUrl ||
665
+ let frontendUrl = options?.frontendUrl ||
462
666
  loginSuccessUrlFromStateValue ||
463
667
  this.authConfig.loginSuccessUrl;
668
+ // Apply basePath to frontendUrl if configured
669
+ if (frontendUrl && this.authConfig.basePath) {
670
+ frontendUrl = prependBasePath(frontendUrl, this.authConfig.basePath);
671
+ }
464
672
  // Priority 1: Check state for display mode configuration
465
673
  const stateDisplayMode = displayModeFromState(state, undefined);
466
674
  const isConfiguredForIframe = stateDisplayMode === "iframe";
@@ -525,7 +733,12 @@ export class CivicAuth {
525
733
  }
526
734
  // Absolute fallback: redirect to loginSuccessUrl or "/"
527
735
  // Never return JSON for browser navigation - that would display raw JSON to the user
528
- return { redirectTo: this.authConfig.loginSuccessUrl || "/" };
736
+ const fallbackUrl = this.authConfig.loginSuccessUrl || "/";
737
+ return {
738
+ redirectTo: this.authConfig.basePath
739
+ ? prependBasePath(fallbackUrl, this.authConfig.basePath)
740
+ : fallbackUrl,
741
+ };
529
742
  }
530
743
  /**
531
744
  * Generate HTML content for iframe completion that sends postMessage to parent
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/server/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,OAAO,IAAI,iBAAiB,EAC5B,SAAS,IAAI,mBAAmB,GACjC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EACL,2BAA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,SAAS,CAAC,WAAW,CAAC;;;;;;;;;;;;;;;mCAezB,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;;;;;;;KAOzD,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,8BAA8B,GAAG,CACvC,WAAmB,EACnB,WAAoB,EACZ,EAAE;QACV,MAAM,mBAAmB,GAAG,WAAW;YACrC,CAAC,CAAC,oBAAoB,kBAAkB,CAAC,WAAW,CAAC,EAAE;YACvD,CAAC,CAAC,EAAE,CAAC;QAEP,OAAO;;;;;;;;;;;2BAWgB,WAAW,qEAAqE,mBAAmB;;;;;;;;;;;;;;CAc7H,CAAC;IACA,CAAC,CAAC;CACH","sourcesContent":["import {\n type OAuthTokens,\n type User,\n type EmptyObject,\n type UnknownObject,\n type OIDCTokenResponseBody,\n tokenKeys,\n} from \"@/types.js\";\nimport type { AuthConfig } from \"@/server/config.js\";\nimport {\n getUser as getUserFromShared,\n getTokens as getTokensFromShared,\n} from \"@/shared/lib/session.js\";\nimport { clearTokens as clearTokensUtil } from \"@/shared/lib/util.js\";\nimport { resolveOAuthAccessCode } from \"@/server/login.js\";\nimport { buildLoginUrl } from \"@/server/login.js\";\nimport { buildLogoutRedirectUrl } from \"@/server/logout.js\";\nimport {\n TOKEN_EXCHANGE_SUCCESS_TEXT,\n TOKEN_EXCHANGE_TRIGGER_TEXT,\n} from \"@/constants.js\";\nimport { refreshTokens } from \"@/server/refresh.js\";\nimport { getVersion } from \"@/shared/index.js\";\nimport { ServerAuthenticationResolver } from \"@/server/ServerAuthenticationResolver.js\";\nimport {\n DEFAULT_AUTH_SERVER,\n JWT_PAYLOAD_KNOWN_CLAIM_KEYS,\n} from \"@/constants.js\";\nimport type { AuthenticationResolver } from \"@/services/types.js\";\nimport { displayModeFromState, loginSuccessUrlFromState } from \"@/lib/oauth.js\";\nimport { decodeJwt, type JWTPayload } from \"jose\";\nimport {\n generateOauthLogoutUrl,\n getBackendEndpoints,\n resolveEndpointUrl,\n sanitizeReturnUrl,\n} from \"@/shared/lib/util.js\";\nimport { CodeVerifier } from \"@/shared/lib/types.js\";\nimport type { CookieStorage } from \"./index.js\";\nimport { loggers } from \"@/lib/logger.js\";\n\n// Generic request interface for framework-agnostic URL detection\nexport type UrlDetectionRequest = {\n url: string;\n headers: Record<string, string | string[] | undefined>;\n searchParams: {\n get(name: string): string | null;\n };\n cookies: {\n get(name: string): { value: string } | undefined;\n };\n};\n\nexport type HandleCallbackRequest = {\n headers: {\n [key: string]: string | string[] | undefined;\n referer?: string;\n origin?: string;\n \"user-agent\"?: string;\n accept?: string;\n \"sec-fetch-dest\"?: string;\n };\n url?: string;\n};\n\nexport type HandleCallbackParams = {\n code: string;\n state: string;\n req: HandleCallbackRequest;\n};\n\n// Function to omit keys from an object\nconst omitKeys = <K extends keyof T, T extends Record<string, unknown>>(\n keys: K[],\n obj: T,\n): Omit<T, K> => {\n const result = { ...obj };\n keys.forEach((key) => {\n delete result[key];\n });\n return result;\n};\n\n/**\n * Helper to detect if this is a same-domain callback request (for iframe workaround)\n */\nconst isSameDomainCallback = (req: HandleCallbackRequest): boolean => {\n if (!req.url) return false;\n return req.url.includes(\"sameDomainCallback=true\");\n};\n\n/**\n * Extract user information directly from OIDC tokens\n * @param tokens The OIDC tokens response\n * @returns The user object or null if no valid ID token\n */\nfunction getUserFromTokens<T extends UnknownObject = EmptyObject>(\n tokens: OIDCTokenResponseBody,\n): User<T> | null {\n if (!tokens.id_token) return null;\n\n const parsedToken = decodeJwt(tokens.id_token) as JWTPayload & T;\n if (!parsedToken.sub) return null;\n\n // set the user ID from the token sub\n const userWithAdditionalTokenFields = {\n ...(parsedToken as T),\n id: parsedToken.sub,\n };\n\n // Remove the token keys from the user object to stop it getting too large\n return omitKeys(\n [...JWT_PAYLOAD_KNOWN_CLAIM_KEYS, ...tokenKeys],\n userWithAdditionalTokenFields,\n ) as User<T>;\n}\n\n/**\n * CivicAuth is the main entry point for server-side authentication operations.\n * It provides a unified interface to all the authentication functions.\n */\nexport class CivicAuth {\n _authResolver: AuthenticationResolver | null = null;\n constructor(\n readonly storage: CookieStorage,\n readonly authConfig: AuthConfig,\n ) {}\n\n get oauthServer(): string {\n return this.authConfig.oauthServer || DEFAULT_AUTH_SERVER;\n }\n\n async getAuthResolver(): Promise<AuthenticationResolver> {\n if (this._authResolver) {\n loggers.server.debug(\"Reusing existing auth resolver\", this.authConfig);\n return Promise.resolve(this._authResolver);\n }\n loggers.server.debug(\"Creating new auth resolver\", this.authConfig);\n this._authResolver = await ServerAuthenticationResolver.build(\n {\n ...this.authConfig,\n oauthServer: this.oauthServer,\n },\n this.storage,\n );\n return this._authResolver;\n }\n /**\n * Gets the authenticated user with token validation\n * @returns The user object if authenticated, null otherwise\n */\n async getUser<\n T extends UnknownObject = EmptyObject,\n >(): Promise<User<T> | null> {\n const resolver = await this.getAuthResolver();\n\n try {\n // Validate the session before returning the user\n const session = await resolver.validateExistingSession();\n if (!session?.authenticated) {\n return null;\n }\n\n // If session is valid, use the shared implementation to get the user\n return getUserFromShared<T>(this.storage);\n } catch (error) {\n console.error(\"Token validation failed during getUser\", error);\n return null;\n }\n }\n\n /**\n * Gets the authentication tokens with token validation\n * @returns The tokens if authenticated, null otherwise\n */\n async getTokens(): Promise<OAuthTokens | null> {\n const resolver = await this.getAuthResolver();\n\n try {\n // Validate the session before returning the tokens\n const session = await resolver.validateExistingSession();\n\n if (!session?.authenticated) {\n return null;\n }\n\n // If session is valid, use the shared implementation to get the tokens\n const tokens = await getTokensFromShared(this.storage);\n return tokens;\n } catch (error) {\n console.error(\"❌ Token validation failed during getTokens\", error);\n return null;\n }\n }\n\n /**\n * Resolve an OAuth access code to a set of OIDC tokens\n * @param code The access code from the query parameter\n * @param state The OAuth state parameter\n * @returns OIDC tokens\n */\n async resolveOAuthAccessCode(\n code: string,\n state: string,\n ): Promise<OIDCTokenResponseBody> {\n return resolveOAuthAccessCode(code, state, this.storage, this.authConfig);\n }\n\n /**\n * Check if the user is currently logged in\n * @returns true if logged in, false otherwise\n */\n async isLoggedIn(): Promise<boolean> {\n const resolver = await this.getAuthResolver();\n const session = await resolver.validateExistingSession();\n return session?.authenticated ?? false;\n }\n\n /**\n * Build a login URL to redirect the user to\n * @param options Additional options for building the login URL\n * @returns The login URL\n */\n async buildLoginUrl(options?: {\n scopes?: string[];\n state?: string;\n nonce?: string;\n }): Promise<URL> {\n return buildLoginUrl(\n {\n ...this.authConfig,\n scopes: options?.scopes,\n state: options?.state,\n nonce: options?.nonce,\n framework: \"server\",\n sdkVersion: getVersion(),\n },\n this.storage,\n );\n }\n\n /**\n * Build a logout URL to redirect the user to\n * @param options Additional options for building the logout URL\n * @returns The logout URL\n */\n async buildLogoutRedirectUrl(options?: {\n scopes?: string[];\n state?: string;\n }): Promise<URL> {\n // Check if this is backend integration mode (loginUrl provided)\n if (this.authConfig.loginUrl) {\n // Backend integration mode: redirect to backend logout endpoint\n // This matches the vanilla client's logout logic for backend integration\n const backendUrl = new URL(this.authConfig.loginUrl).origin;\n const endpoints = getBackendEndpoints(this.authConfig.backendEndpoints);\n const backendLogoutUrl = resolveEndpointUrl(backendUrl, endpoints.logout);\n\n const logoutUrl = new URL(backendLogoutUrl);\n\n // Include logoutRedirectUrl as query parameter if configured\n if (this.authConfig.postLogoutRedirectUrl) {\n logoutUrl.searchParams.set(\n \"logoutRedirectUrl\",\n this.authConfig.postLogoutRedirectUrl,\n );\n }\n\n // Include state if provided\n if (options?.state) {\n logoutUrl.searchParams.set(\"state\", options.state);\n }\n\n return logoutUrl;\n }\n\n // Standard OAuth flow - redirect to OAuth provider's logout endpoint\n try {\n // Use the shared getTokens function directly - this bypasses session validation\n // since for logout we just need the raw ID token, not validated tokens\n const tokens = await getTokensFromShared(this.storage);\n\n if (tokens?.idToken) {\n // Ensure clientId is present for OAuth operations\n if (!this.authConfig.clientId) {\n throw new Error(\"clientId is required for OAuth logout operations\");\n }\n\n // We have access to the ID token from HTTP-only cookies\n // Build the logout URL manually using the shared utility\n\n const logoutUrl = await generateOauthLogoutUrl({\n clientId: this.authConfig.clientId,\n redirectUrl: this.authConfig.postLogoutRedirectUrl || \"/\",\n idToken: tokens.idToken,\n state: options?.state ?? Math.random().toString(36).substring(2),\n oauthServer: this.oauthServer,\n });\n\n return logoutUrl;\n }\n } catch (error) {\n // If direct token access fails, fall back to the generic function\n console.warn(\n \"❌ Could not get tokens directly from storage, falling back to generic logout method:\",\n error,\n );\n }\n\n // Fallback to the generic function for other storage types or when tokens aren't accessible\n return buildLogoutRedirectUrl(\n {\n ...this.authConfig,\n scopes: options?.scopes,\n state: options?.state,\n },\n this.storage,\n );\n }\n\n /**\n * Refresh the current set of OIDC tokens\n * @returns The refreshed tokens or null for backend flows where tokens are managed in HTTP-only cookies\n */\n async refreshTokens(): Promise<OIDCTokenResponseBody | null> {\n return refreshTokens(this.storage, this.authConfig);\n }\n\n /**\n * Clear all authentication tokens from storage\n */\n async clearTokens(): Promise<void> {\n return clearTokensUtil(this.storage);\n }\n\n /**\n * Framework-agnostic URL detection and resolution helpers\n * These methods handle proxy environments and can be used by any framework\n */\n\n /**\n * Try to URI decode a value, returning the original value on error\n */\n static tryUriDecode(value: string): string {\n try {\n return decodeURIComponent(value);\n } catch (e) {\n console.error(\"Error decoding URI component:\", e);\n return value;\n }\n }\n\n /**\n * Get decoded query parameter from request\n */\n static getDecodedQueryParam(\n request: UrlDetectionRequest,\n paramName: string,\n ): string | null {\n const queryParam = request.searchParams.get(paramName);\n if (queryParam) {\n return CivicAuth.tryUriDecode(queryParam);\n }\n return null;\n }\n\n /**\n * Get value from cookie or query parameter (cookie takes precedence)\n */\n static getCookieOrQueryParam(\n request: UrlDetectionRequest,\n cookieName: string,\n queryName: string,\n ): string | null {\n // First check the cookie as it might have the full path with base directory\n const cookieValue = request.cookies.get(cookieName)?.value;\n if (cookieValue) {\n return CivicAuth.tryUriDecode(cookieValue);\n }\n\n // Fallback to query parameter\n return CivicAuth.getDecodedQueryParam(request, queryName);\n }\n\n /**\n * Get app URL from request (for proxy environment support)\n * Checks cookies first, then query parameters\n */\n static getAppUrl(request: UrlDetectionRequest): string | null {\n return CivicAuth.getCookieOrQueryParam(\n request,\n CodeVerifier.APP_URL,\n \"appUrl\",\n );\n }\n\n /**\n * Get login success URL with proper base URL handling\n * Extracts from state parameter or query parameters, resolves with baseUrl if provided\n */\n static getLoginSuccessUrl(\n request: UrlDetectionRequest,\n baseUrl?: string | null,\n ): string | null {\n const state = request.searchParams.get(\"state\");\n const loginSuccessUrl =\n loginSuccessUrlFromState(state) ||\n CivicAuth.getDecodedQueryParam(request, \"loginSuccessUrl\");\n\n if (!loginSuccessUrl) {\n return null;\n }\n\n return baseUrl ? new URL(loginSuccessUrl, baseUrl).href : loginSuccessUrl;\n }\n\n /**\n * Convert relative URL to absolute URL using appUrl for proxy environments\n */\n static toAbsoluteUrl(\n request: UrlDetectionRequest,\n url: string,\n appUrl?: string | null,\n ): string {\n if (url.startsWith(\"http\")) {\n return url;\n }\n\n // Use appUrl if available (for proxy environments), otherwise fall back to request origin\n const baseUrl = appUrl || new URL(request.url).origin;\n return new URL(url, baseUrl).href;\n }\n\n /**\n * Get post-logout redirect URL with proxy environment support\n */\n getPostLogoutRedirectUrl(request: UrlDetectionRequest): string {\n // Check if we have a target URL in the request (from middleware)\n const targetUrl = request.searchParams.get(\"targetUrl\");\n if (targetUrl) {\n return targetUrl;\n }\n\n const redirectTarget = this.authConfig.loginSuccessUrl ?? \"/\";\n\n // If loginSuccessUrl is absolute, use it as-is\n const isAbsoluteRedirect = /^(https?:\\/\\/|www\\.).+/i.test(redirectTarget);\n if (isAbsoluteRedirect) {\n return redirectTarget;\n }\n\n // Use appUrl from client for proxy environments\n const appUrl = CivicAuth.getAppUrl(request);\n if (appUrl) {\n return new URL(redirectTarget, appUrl).href;\n }\n\n // Fallback to request origin\n return new URL(request.url).origin;\n }\n\n /**\n * Smart callback handler that automatically detects frontend vs backend requests\n * and redirects appropriately. Use this instead of resolveOAuthAccessCode + manual redirect.\n *\n * @param params An object containing the authorization code, state, and the incoming request.\n * @param params.code The authorization code from query parameters.\n * @param params.state The OAuth state parameter.\n * @param params.req The incoming request object (e.g., from Express).\n * @param options Configuration options (frontendUrl override, apiResponse flag).\n * @returns Object with redirect information or HTML content for iframe completion.\n *\n * @example\n * ```javascript\n * app.get('/auth/callback', async (req, res) => {\n * const { code, state } = req.query;\n * // The request object 'req' is passed directly\n * const result = await req.civicAuth.handleCallback({ code, state, req });\n *\n * if (result.htmlContent) {\n * res.setHeader('Content-Type', 'text/html');\n * res.send(result.htmlContent);\n * } else if (result.redirectTo) {\n * res.redirect(result.redirectTo);\n * } else {\n * res.json({ success: true, user: result.user });\n * }\n * });\n * ```\n */\n async handleCallback(\n { code, state, req }: HandleCallbackParams,\n options?: {\n frontendUrl?: string;\n apiResponse?: boolean;\n },\n ): Promise<{\n redirectTo?: string;\n content?: string | { success: boolean; user?: User | null };\n }> {\n // Handle same-domain callback for iframe workaround\n if (isSameDomainCallback(req)) {\n try {\n // Check if user is already authenticated before attempting token exchange\n const isAlreadyLoggedIn = await this.isLoggedIn();\n let user: User | null = null;\n\n if (isAlreadyLoggedIn) {\n // User is already authenticated, get existing user data\n user = await this.getUser();\n console.log(\n \"User already authenticated in same-domain callback:\",\n !!user,\n );\n } else {\n // For same-domain callbacks, we should have access to cookies\n const tokens = await this.resolveOAuthAccessCode(code, state);\n user = getUserFromTokens(tokens);\n console.log(\n \"Completed token exchange in same-domain callback:\",\n !!user,\n );\n }\n\n // Return JSON response for same-domain callback\n const currentUrl = new URL(req.url || \"\");\n\n // Extract and sanitize loginSuccessUrl (deep link) BEFORE cleaning up search params\n // Sanitization prevents open redirect attacks via malicious URLs in the query param\n const rawLoginSuccessUrl =\n currentUrl.searchParams.get(\"loginSuccessUrl\");\n const loginSuccessUrl = rawLoginSuccessUrl\n ? sanitizeReturnUrl(rawLoginSuccessUrl, currentUrl.origin)\n : null;\n\n const newSearchParams = new URLSearchParams(currentUrl.search);\n newSearchParams.delete(\"sameDomainCallback\");\n newSearchParams.delete(\"appUrl\");\n newSearchParams.delete(\"loginSuccessUrl\");\n\n // Use preserved deep link if available and valid, otherwise fall back to loginSuccessUrl or \"/\"\n // Note: Do NOT fall back to currentUrl.pathname as that's the callback URL, which would cause a loop\n const redirectUrl =\n loginSuccessUrl || this.authConfig.loginSuccessUrl || \"/\";\n return {\n content: {\n success: true,\n redirectUrl,\n } as { success: boolean; redirectUrl: string },\n };\n } catch (error) {\n console.error(\"Same-domain callback failed:\", error);\n throw error;\n }\n }\n\n // Try to resolve the OAuth code and create session\n let tokens: OIDCTokenResponseBody;\n let user: User | null;\n\n try {\n tokens = await this.resolveOAuthAccessCode(code, state);\n user = getUserFromTokens(tokens);\n } catch (error) {\n // Check if this is a code verifier error and we're in iframe mode\n const isCodeVerifierError =\n error instanceof Error &&\n error.message.includes(\"Code verifier not found in storage\");\n\n if (isCodeVerifierError) {\n // First check if user is already authenticated before trying iframe workaround\n try {\n const isAlreadyLoggedIn = await this.isLoggedIn();\n\n if (isAlreadyLoggedIn) {\n // \"User already authenticated, skipping iframe workaround\",\n const user = await this.getUser();\n const loginSuccessUrlFromStateValue =\n loginSuccessUrlFromState(state);\n const frontendUrl =\n options?.frontendUrl ||\n loginSuccessUrlFromStateValue ||\n this.authConfig.loginSuccessUrl;\n\n // Check if this is an iframe context - if so, generate iframe completion HTML\n const stateDisplayMode = displayModeFromState(state, undefined);\n const isConfiguredForIframe = stateDisplayMode === \"iframe\";\n\n if (\n isConfiguredForIframe &&\n !this.authConfig.disableIframeDetection &&\n user &&\n frontendUrl\n ) {\n // Generating iframe completion HTML for already authenticated user\",\n const completionHtml = this.generateIframeCompletionHtml(\n user,\n frontendUrl,\n );\n return { content: completionHtml };\n }\n\n if (frontendUrl) {\n return { redirectTo: frontendUrl };\n } else {\n // Return JSON when no redirect destination is available.\n // This is intentional for API-style callbacks and cross-origin scenarios\n // where cookies aren't accessible to read config. The JSON response allows\n // clients (e.g., vanilla JS SDK) to handle the success case programmatically.\n return { content: { success: true, user } };\n }\n }\n } catch (authCheckError) {\n console.warn(\n \"Failed to check authentication status:\",\n authCheckError,\n );\n // Continue with iframe workaround if auth check fails\n }\n\n const stateDisplayMode = displayModeFromState(state, undefined);\n const isConfiguredForIframe = stateDisplayMode === \"iframe\";\n\n if (isConfiguredForIframe && !this.authConfig.disableIframeDetection) {\n // Generate HTML that will trigger same-domain callback\n const loginSuccessUrlFromStateValue = loginSuccessUrlFromState(state);\n const frontendUrl =\n options?.frontendUrl ||\n loginSuccessUrlFromStateValue ||\n this.authConfig.loginSuccessUrl;\n\n const callbackUrl = req.url || \"\";\n const sameDomainHtml = this.generateSameDomainCallbackHtml(\n callbackUrl,\n frontendUrl,\n );\n return { content: sameDomainHtml };\n }\n\n // For non-iframe mode or when iframe detection is disabled, return trigger text\n return {\n content: `<html lang=\"en\"><body><span style=\"display:none\">${TOKEN_EXCHANGE_TRIGGER_TEXT}</span></body></html>`,\n };\n }\n\n // Re-throw other errors\n throw error;\n }\n\n // Extract loginSuccessUrl from state if present\n const loginSuccessUrlFromStateValue = loginSuccessUrlFromState(state);\n\n // Priority: options.frontendUrl > loginSuccessUrl from state > config loginSuccessUrl\n const frontendUrl =\n options?.frontendUrl ||\n loginSuccessUrlFromStateValue ||\n this.authConfig.loginSuccessUrl;\n\n // Priority 1: Check state for display mode configuration\n const stateDisplayMode = displayModeFromState(state, undefined);\n const isConfiguredForIframe = stateDisplayMode === \"iframe\";\n\n // Determine if this should be treated as an iframe request\n // Configuration (from state) takes precedence over auto-detection\n const shouldTreatAsIframe =\n isConfiguredForIframe && !this.authConfig.disableIframeDetection;\n\n const isTopLevelRedirect = req.headers[\"sec-fetch-dest\"] === \"document\";\n const isIframeRequest = req.headers[\"sec-fetch-dest\"] === \"iframe\";\n const isApiRequest =\n options?.apiResponse || req.headers.accept?.includes(\"application/json\");\n\n // Detect Safari or other browsers where iframe postMessage may fail due to cross-origin restrictions\n //TODO: Find a better way to detect this\n const userAgent = req.headers[\"user-agent\"] || \"\";\n const isSafari =\n userAgent.includes(\"Safari\") && !userAgent.includes(\"Chrome\");\n const isLikelyCrossOriginIframe =\n isSafari ||\n (userAgent.includes(\"WebKit\") && !userAgent.includes(\"Chrome\"));\n\n // Case 1: The request should be treated as iframe. Return HTML content.\n // Unless iframe detection is disabled via configuration OR we detect cross-origin issues\n if (\n shouldTreatAsIframe &&\n user &&\n frontendUrl &&\n !isLikelyCrossOriginIframe\n ) {\n const completionHtml = this.generateIframeCompletionHtml(\n user,\n frontendUrl,\n );\n return { content: completionHtml };\n }\n\n // Case 1b: Safari/cross-origin iframe case - redirect instead of HTML\n if (\n shouldTreatAsIframe &&\n user &&\n frontendUrl &&\n isLikelyCrossOriginIframe\n ) {\n return { redirectTo: frontendUrl };\n }\n\n // Case 2: The request is a top-level navigation. Return redirect URL.\n if (isTopLevelRedirect && frontendUrl) {\n return { redirectTo: frontendUrl };\n }\n\n // Case 2a: The request is from an iframe (detected by sec-fetch-dest)\n // Even if not configured for iframe in state, we should still generate iframe completion HTML\n if (isIframeRequest && user && frontendUrl) {\n if (isLikelyCrossOriginIframe) {\n console.log(\n \"Iframe request detected but cross-origin issues likely - redirecting\",\n );\n return { redirectTo: frontendUrl };\n } else {\n console.log(\n \"Generating iframe completion HTML for iframe request (detected by sec-fetch-dest)\",\n );\n const completionHtml = this.generateIframeCompletionHtml(\n user,\n frontendUrl,\n );\n return { content: completionHtml };\n }\n }\n\n // Case 3: The request is an API call. Return JSON content.\n if (isApiRequest) {\n return {\n content: {\n success: true,\n user,\n },\n };\n }\n\n // Fallback for older browsers or other contexts: if a frontend URL is configured,\n // assume a redirect to it.\n if (frontendUrl) {\n return { redirectTo: frontendUrl };\n }\n\n // Absolute fallback: redirect to loginSuccessUrl or \"/\"\n // Never return JSON for browser navigation - that would display raw JSON to the user\n return { redirectTo: this.authConfig.loginSuccessUrl || \"/\" };\n }\n\n /**\n * Generate HTML content for iframe completion that sends postMessage to parent\n */\n private generateIframeCompletionHtml(\n user: User,\n frontendUrl?: string,\n ): string {\n const escapedUser = JSON.stringify(user).replace(/'/g, \"\\\\'\");\n const clientId = this.authConfig.clientId;\n\n // Determine fallback redirect URL\n // Note: redirectUrl is the OAuth callback URL - it should NEVER be used as a post-login\n // destination as it would cause an infinite redirect loop in iframe mode.\n // postLogoutRedirectUrl is semantically incorrect for login success scenarios.\n const fallbackUrl = frontendUrl || this.authConfig.loginSuccessUrl || \"/\";\n\n return `\n <!DOCTYPE html>\n <html>\n <head>\n <title>Authentication Complete</title>\n <meta charset=\"utf-8\">\n </head>\n <body> \n <!-- Success signal for SignalObserver -->\n <div id=\"civic-auth-success-signal\" style=\"display: none;\" data-user-info='${escapedUser}'>\n ${TOKEN_EXCHANGE_SUCCESS_TEXT}\n </div>\n \n <script>\n // Send postMessage to parent to resolve authentication promise\n if (window.parent && window.parent !== window) {\n try {\n window.parent.postMessage({\n type: 'auth_success',\n detail: 'Authentication successful',\n data: {\n user: ${escapedUser},\n redirectUrl: ${JSON.stringify(fallbackUrl)}\n }\n }, '*');\n } catch (error) {\n console.error('❌ Failed to send postMessage:', error);\n }\n\n // Also send civicloginApp format message for compatibility\n try {\n window.parent.postMessage({\n source: 'civicloginApp',\n type: 'auth_success',\n clientId: ${JSON.stringify(clientId)},\n data: {\n user: ${escapedUser},\n redirectUrl: ${JSON.stringify(fallbackUrl)}\n }\n }, '*');\n } catch (error) {\n console.error('❌ Failed to send civicloginApp message:', error);\n }\n } else {\n console.log('❌ Not in iframe context or no parent window');\n }\n \n // Fallback redirect after 500ms delay to handle cases where:\n // 1. postMessage fails or parent doesn't respond\n // 2. Not in iframe context\n // 3. Any other edge cases where the user gets stuck\n setTimeout(function() {\n var redirectTarget = ${JSON.stringify(fallbackUrl)};\n console.log('🔄 Executing fallback redirect to:', redirectTarget);\n window.location.href = redirectTarget;\n }, 500);\n </script>\n </body>\n </html>\n `;\n }\n\n /**\n * Generate HTML response that triggers same-domain callback for iframe workaround\n */\n private generateSameDomainCallbackHtml = (\n callbackUrl: string,\n frontendUrl?: string,\n ): string => {\n const loginSuccessSegment = frontendUrl\n ? `&loginSuccessUrl=${encodeURIComponent(frontendUrl)}`\n : \"\";\n\n return `<html lang=\"en\">\n <body>\n <span style=\"display:none\">\n <script>\n window.onload = function () {\n // Get the complete URL including origin and path\n // This ensures we capture any base path like /directory\n const appUrl = window.location.href.substring(\n 0,\n window.location.href.indexOf(\"/api/auth\")\n );\n fetch('${callbackUrl}&sameDomainCallback=true&appUrl=' + encodeURIComponent(appUrl) + '${loginSuccessSegment}').then((response) => {\n response.json().then((jsonResponse) => {\n // For login: Redirect back to the callback route, so Case 2 in handleTokenExchangeComplete will be triggered\n // For logout: Redirect to the postLogoutRedirectUrl\n if(jsonResponse.redirectUrl) {\n window.location.href = jsonResponse.redirectUrl;\n }\n });\n });\n };\n </script>\n </span>\n </body>\n</html>\n`;\n };\n}\n"]}
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/server/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,OAAO,IAAI,iBAAiB,EAC5B,SAAS,IAAI,mBAAmB,GACjC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,4BAA4B,EAAE,MAAM,0CAA0C,CAAC;AACxF,OAAO,EACL,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,gBAAgB,CAAC;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AAoB,kBAAkB,CAAC,WAAW,CAAC,EAAE;YACvD,CAAC,CAAC,EAAE,CAAC;QAEP,OAAO;;;;;;;;;;;2BAWgB,WAAW,qEAAqE,mBAAmB;;;;;;;;;;;;;;CAc7H,CAAC;IACA,CAAC,CAAC;CACH","sourcesContent":["import {\n type OAuthTokens,\n type User,\n type EmptyObject,\n type UnknownObject,\n type OIDCTokenResponseBody,\n tokenKeys,\n} from \"@/types.js\";\nimport type { AuthConfig } from \"@/server/config.js\";\nimport {\n getUser as getUserFromShared,\n getTokens as getTokensFromShared,\n} from \"@/shared/lib/session.js\";\nimport { clearTokens as clearTokensUtil } from \"@/shared/lib/util.js\";\nimport { resolveOAuthAccessCode } from \"@/server/login.js\";\nimport { buildLoginUrl } from \"@/server/login.js\";\nimport { buildLogoutRedirectUrl } from \"@/server/logout.js\";\nimport {\n TOKEN_EXCHANGE_SUCCESS_TEXT,\n TOKEN_EXCHANGE_TRIGGER_TEXT,\n} from \"@/constants.js\";\nimport { refreshTokens } from \"@/server/refresh.js\";\nimport { getVersion } from \"@/shared/index.js\";\nimport { ServerAuthenticationResolver } from \"@/server/ServerAuthenticationResolver.js\";\nimport {\n DEFAULT_AUTH_SERVER,\n JWT_PAYLOAD_KNOWN_CLAIM_KEYS,\n} from \"@/constants.js\";\nimport type { AuthenticationResolver } from \"@/services/types.js\";\nimport {\n displayModeFromState,\n injectLoginSuccessUrlIntoState,\n loginSuccessUrlFromState,\n} from \"@/lib/oauth.js\";\nimport { decodeJwt, type JWTPayload } from \"jose\";\nimport {\n computeDeepLinkDestination,\n generateOauthLogoutUrl,\n getBackendEndpoints,\n prependBasePath,\n resolveEndpointUrl,\n sanitizeReturnUrl,\n} from \"@/shared/lib/util.js\";\nimport {\n AUTH_REDIRECT_MARKER_MAX_AGE,\n AuthFlowCookie,\n CodeVerifier,\n} from \"@/shared/lib/types.js\";\nimport type { CookieStorage } from \"./index.js\";\nimport { loggers } from \"@/lib/logger.js\";\n\n// Generic request interface for framework-agnostic URL detection\nexport type UrlDetectionRequest = {\n url: string;\n headers: Record<string, string | string[] | undefined>;\n searchParams: {\n get(name: string): string | null;\n };\n cookies: {\n get(name: string): { value: string } | undefined;\n };\n};\n\nexport type HandleCallbackRequest = {\n headers: {\n [key: string]: string | string[] | undefined;\n referer?: string;\n origin?: string;\n \"user-agent\"?: string;\n accept?: string;\n \"sec-fetch-dest\"?: string;\n };\n url?: string;\n};\n\nexport type HandleCallbackParams = {\n code: string;\n state: string;\n req: HandleCallbackRequest;\n};\n\n// Function to omit keys from an object\nconst omitKeys = <K extends keyof T, T extends Record<string, unknown>>(\n keys: K[],\n obj: T,\n): Omit<T, K> => {\n const result = { ...obj };\n keys.forEach((key) => {\n delete result[key];\n });\n return result;\n};\n\n/**\n * Helper to detect if this is a same-domain callback request (for iframe workaround)\n */\nconst isSameDomainCallback = (req: HandleCallbackRequest): boolean => {\n if (!req.url) return false;\n return req.url.includes(\"sameDomainCallback=true\");\n};\n\n/**\n * Extract user information directly from OIDC tokens\n * @param tokens The OIDC tokens response\n * @returns The user object or null if no valid ID token\n */\nfunction getUserFromTokens<T extends UnknownObject = EmptyObject>(\n tokens: OIDCTokenResponseBody,\n): User<T> | null {\n if (!tokens.id_token) return null;\n\n const parsedToken = decodeJwt(tokens.id_token) as JWTPayload & T;\n if (!parsedToken.sub) return null;\n\n // set the user ID from the token sub\n const userWithAdditionalTokenFields = {\n ...(parsedToken as T),\n id: parsedToken.sub,\n };\n\n // Remove the token keys from the user object to stop it getting too large\n return omitKeys(\n [...JWT_PAYLOAD_KNOWN_CLAIM_KEYS, ...tokenKeys],\n userWithAdditionalTokenFields,\n ) as User<T>;\n}\n\n/**\n * CivicAuth is the main entry point for server-side authentication operations.\n * It provides a unified interface to all the authentication functions.\n */\nexport class CivicAuth {\n _authResolver: AuthenticationResolver | null = null;\n constructor(\n readonly storage: CookieStorage,\n readonly authConfig: AuthConfig,\n ) {}\n\n get oauthServer(): string {\n return this.authConfig.oauthServer || DEFAULT_AUTH_SERVER;\n }\n\n async getAuthResolver(): Promise<AuthenticationResolver> {\n if (this._authResolver) {\n loggers.server.debug(\"Reusing existing auth resolver\", this.authConfig);\n return Promise.resolve(this._authResolver);\n }\n loggers.server.debug(\"Creating new auth resolver\", this.authConfig);\n this._authResolver = await ServerAuthenticationResolver.build(\n {\n ...this.authConfig,\n oauthServer: this.oauthServer,\n },\n this.storage,\n );\n return this._authResolver;\n }\n /**\n * Gets the authenticated user with token validation\n * @returns The user object if authenticated, null otherwise\n */\n async getUser<\n T extends UnknownObject = EmptyObject,\n >(): Promise<User<T> | null> {\n const resolver = await this.getAuthResolver();\n\n try {\n // Validate the session before returning the user\n const session = await resolver.validateExistingSession();\n if (!session?.authenticated) {\n return null;\n }\n\n // If session is valid, use the shared implementation to get the user\n return getUserFromShared<T>(this.storage);\n } catch (error) {\n console.error(\"Token validation failed during getUser\", error);\n return null;\n }\n }\n\n /**\n * Gets the authentication tokens with token validation\n * @returns The tokens if authenticated, null otherwise\n */\n async getTokens(): Promise<OAuthTokens | null> {\n const resolver = await this.getAuthResolver();\n\n try {\n // Validate the session before returning the tokens\n const session = await resolver.validateExistingSession();\n\n if (!session?.authenticated) {\n return null;\n }\n\n // If session is valid, use the shared implementation to get the tokens\n const tokens = await getTokensFromShared(this.storage);\n return tokens;\n } catch (error) {\n console.error(\"❌ Token validation failed during getTokens\", error);\n return null;\n }\n }\n\n /**\n * Resolve an OAuth access code to a set of OIDC tokens\n * @param code The access code from the query parameter\n * @param state The OAuth state parameter\n * @returns OIDC tokens\n */\n async resolveOAuthAccessCode(\n code: string,\n state: string,\n ): Promise<OIDCTokenResponseBody> {\n return resolveOAuthAccessCode(code, state, this.storage, this.authConfig);\n }\n\n /**\n * Check if the user is currently logged in\n * @returns true if logged in, false otherwise\n */\n async isLoggedIn(): Promise<boolean> {\n const resolver = await this.getAuthResolver();\n const session = await resolver.validateExistingSession();\n return session?.authenticated ?? false;\n }\n\n /**\n * Build a login URL to redirect the user to\n * @param options Additional options for building the login URL\n * @returns The login URL\n */\n async buildLoginUrl(options?: {\n scopes?: string[];\n state?: string;\n nonce?: string;\n }): Promise<URL> {\n const logger = loggers.server;\n let finalState = options?.state;\n\n // If deep linking is enabled, read the return URL cookie and inject into state\n if (this.authConfig.deepLinkHandling !== \"disabled\") {\n try {\n const returnUrl = await this.storage.get(AuthFlowCookie.RETURN_URL);\n if (returnUrl) {\n logger.debug(\n \"[buildLoginUrl] Found RETURN_URL cookie, injecting into state\",\n { returnUrl },\n );\n // Inject the return URL into state, preserving any existing state\n finalState = injectLoginSuccessUrlIntoState(\n finalState ?? null,\n returnUrl,\n );\n }\n } catch (error) {\n logger.warn(\"[buildLoginUrl] Failed to read RETURN_URL cookie\", {\n error,\n });\n // Continue without the cookie - don't block login\n }\n }\n\n return buildLoginUrl(\n {\n ...this.authConfig,\n scopes: options?.scopes,\n state: finalState,\n nonce: options?.nonce,\n framework: \"server\",\n sdkVersion: getVersion(),\n },\n this.storage,\n );\n }\n\n /**\n * Build a logout URL to redirect the user to\n * @param options Additional options for building the logout URL\n * @returns The logout URL\n */\n async buildLogoutRedirectUrl(options?: {\n scopes?: string[];\n state?: string;\n }): Promise<URL> {\n // Check if this is backend integration mode (loginUrl provided)\n if (this.authConfig.loginUrl) {\n // Backend integration mode: redirect to backend logout endpoint\n // This matches the vanilla client's logout logic for backend integration\n const backendUrl = new URL(this.authConfig.loginUrl).origin;\n const endpoints = getBackendEndpoints(this.authConfig.backendEndpoints);\n const backendLogoutUrl = resolveEndpointUrl(backendUrl, endpoints.logout);\n\n const logoutUrl = new URL(backendLogoutUrl);\n\n // Include logoutRedirectUrl as query parameter if configured\n if (this.authConfig.postLogoutRedirectUrl) {\n logoutUrl.searchParams.set(\n \"logoutRedirectUrl\",\n this.authConfig.postLogoutRedirectUrl,\n );\n }\n\n // Include state if provided\n if (options?.state) {\n logoutUrl.searchParams.set(\"state\", options.state);\n }\n\n return logoutUrl;\n }\n\n // Standard OAuth flow - redirect to OAuth provider's logout endpoint\n try {\n // Use the shared getTokens function directly - this bypasses session validation\n // since for logout we just need the raw ID token, not validated tokens\n const tokens = await getTokensFromShared(this.storage);\n\n if (tokens?.idToken) {\n // Ensure clientId is present for OAuth operations\n if (!this.authConfig.clientId) {\n throw new Error(\"clientId is required for OAuth logout operations\");\n }\n\n // We have access to the ID token from HTTP-only cookies\n // Build the logout URL manually using the shared utility\n\n const logoutUrl = await generateOauthLogoutUrl({\n clientId: this.authConfig.clientId,\n redirectUrl: this.authConfig.postLogoutRedirectUrl || \"/\",\n idToken: tokens.idToken,\n state: options?.state ?? Math.random().toString(36).substring(2),\n oauthServer: this.oauthServer,\n });\n\n return logoutUrl;\n }\n } catch (error) {\n // If direct token access fails, fall back to the generic function\n console.warn(\n \"❌ Could not get tokens directly from storage, falling back to generic logout method:\",\n error,\n );\n }\n\n // Fallback to the generic function for other storage types or when tokens aren't accessible\n return buildLogoutRedirectUrl(\n {\n ...this.authConfig,\n scopes: options?.scopes,\n state: options?.state,\n },\n this.storage,\n );\n }\n\n /**\n * Refresh the current set of OIDC tokens\n * @returns The refreshed tokens or null for backend flows where tokens are managed in HTTP-only cookies\n */\n async refreshTokens(): Promise<OIDCTokenResponseBody | null> {\n return refreshTokens(this.storage, this.authConfig);\n }\n\n /**\n * Clear all authentication tokens from storage\n */\n async clearTokens(): Promise<void> {\n return clearTokensUtil(this.storage);\n }\n\n /**\n * Handles deep linking by computing the return URL and setting it as a cookie.\n * This method encapsulates the deep-linking logic for use by middleware in any framework.\n *\n * The method automatically detects whether the user is at the login URL or a protected route\n * and applies the appropriate logic:\n *\n * **At login URL:**\n * - Auth redirect (marker present): Preserve existing deep link cookie\n * - Fresh navigation with query params: Set cookie with query params\n * - Fresh navigation without params: Clear stale cookie\n *\n * **At protected route:**\n * - Always set the cookie to capture the deep link destination\n *\n * @param requestUrl - The full URL of the request being made (the page the user tried to access)\n * @param originUrl - The origin URL of the application (e.g., \"https://myapp.com\")\n * @returns The computed deep link destination, or null if deep linking is disabled or the URL is invalid\n *\n * @example\n * ```typescript\n * // In middleware for any framework\n * if (!session.authenticated) {\n * await civicAuth.handleDeepLinking(requestUrl, originUrl);\n * }\n * ```\n */\n async handleDeepLinking(\n requestUrl: string,\n originUrl: string,\n ): Promise<string | null> {\n const logger = loggers.server;\n\n const deepLinkHandling =\n this.authConfig.deepLinkHandling ?? \"queryParamsOnly\";\n\n if (deepLinkHandling === \"disabled\") {\n return null;\n }\n\n // Parse the request URL to extract path, search, and hash\n let parsedUrl: URL;\n try {\n parsedUrl = new URL(requestUrl, originUrl);\n } catch (error) {\n logger.warn(\"[handleDeepLinking] Failed to parse request URL:\", {\n requestUrl,\n originUrl,\n error,\n });\n return null;\n }\n\n // Determine if we're at the login URL\n const loginUrl = this.authConfig.loginUrl || \"/\";\n const loginPathWithoutBasePath = loginUrl.startsWith(\"/\")\n ? loginUrl\n : new URL(loginUrl, originUrl).pathname;\n const isAtLoginUrl = parsedUrl.pathname === loginPathWithoutBasePath;\n\n logger.debug(\"[handleDeepLinking]:\", {\n pathname: parsedUrl.pathname,\n isAtLoginUrl,\n loginUrl: loginPathWithoutBasePath,\n });\n\n if (isAtLoginUrl) {\n // At login URL - use the updateDeepLinkCookie logic\n return this.handleDeepLinkingAtLoginUrl(parsedUrl, originUrl);\n }\n\n // At protected route - set the deep link cookie\n return this.handleDeepLinkingAtProtectedRoute(parsedUrl, originUrl);\n }\n\n /**\n * Internal: Handles deep linking when at a protected route.\n * Sets the cookie to capture the user's intended destination and the auth redirect marker.\n */\n private async handleDeepLinkingAtProtectedRoute(\n parsedUrl: URL,\n originUrl: string,\n ): Promise<string | null> {\n const logger = loggers.server;\n const deepLinkHandling =\n this.authConfig.deepLinkHandling ?? \"queryParamsOnly\";\n\n const returnTo = computeDeepLinkDestination(\n parsedUrl.pathname,\n parsedUrl.search,\n parsedUrl.hash,\n originUrl,\n deepLinkHandling,\n this.authConfig.loginSuccessUrl,\n );\n\n if (!returnTo) {\n logger.debug(\n \"[handleDeepLinking] No deep link destination computed (disabled or invalid URL)\",\n );\n return null;\n }\n\n // Set the cookie with the computed return URL\n await this.storage.set(AuthFlowCookie.RETURN_URL, returnTo, {});\n logger.debug(\"[handleDeepLinking] Set RETURN_URL cookie\", { returnTo });\n\n // Also set the auth redirect marker since we're at a protected route\n // and the user will be redirected to login\n await this.storage.set(AuthFlowCookie.AUTH_REDIRECT_MARKER, \"1\", {\n maxAge: AUTH_REDIRECT_MARKER_MAX_AGE,\n });\n logger.debug(\"[handleDeepLinking] Set auth redirect marker\");\n\n return returnTo;\n }\n\n /**\n * Internal: Handles deep linking when at the login URL.\n * Checks the auth redirect marker and handles appropriately.\n */\n private async handleDeepLinkingAtLoginUrl(\n parsedUrl: URL,\n originUrl: string,\n ): Promise<string | null> {\n const logger = loggers.server;\n const deepLinkHandling =\n this.authConfig.deepLinkHandling ?? \"queryParamsOnly\";\n const hasQueryParams = parsedUrl.searchParams.size > 0;\n\n // Check and clean up the auth redirect marker cookie\n const isAuthRedirect = await this.storage.get(\n AuthFlowCookie.AUTH_REDIRECT_MARKER,\n );\n await this.storage.delete(AuthFlowCookie.AUTH_REDIRECT_MARKER);\n\n // Get existing cookie to determine if we need to clear stale data\n const existingCookie = await this.storage.get(AuthFlowCookie.RETURN_URL);\n\n logger.debug(\"[handleDeepLinking] At login URL:\", {\n hasQueryParams,\n isAuthRedirect: !!isAuthRedirect,\n existingCookie,\n });\n\n if (isAuthRedirect) {\n // This is a redirect from auth middleware - preserve the existing cookie\n logger.debug(\n \"[handleDeepLinking] Auth redirect detected - preserving existing cookie\",\n );\n return existingCookie;\n }\n\n // Fresh navigation\n if (hasQueryParams) {\n // User visited with query params - capture them\n const returnTo = computeDeepLinkDestination(\n parsedUrl.pathname,\n parsedUrl.search,\n parsedUrl.hash,\n originUrl,\n deepLinkHandling,\n this.authConfig.loginSuccessUrl,\n );\n\n if (returnTo) {\n // Set the cookie with the computed return URL\n await this.storage.set(AuthFlowCookie.RETURN_URL, returnTo, {});\n logger.debug(\n `[handleDeepLinking] Fresh visit with params - setting cookie to \"${returnTo}\"`,\n );\n return returnTo;\n }\n }\n\n // Don't clear existing cookies on fresh visits - the user may be interacting\n // with the login page (e.g., clicking radio buttons) which triggers new requests.\n // The cookie has a limited lifetime and will expire naturally.\n return null;\n }\n\n /**\n * Sets the auth redirect marker cookie. This marker helps distinguish auth redirects\n * from fresh navigations to the login page, preventing the deep link cookie from being\n * incorrectly overwritten.\n *\n * **Note:** This method is automatically called by `handleDeepLinking` when the user is\n * at a protected route. You typically do NOT need to call this method manually unless\n * you have a specific use case where you're not using `handleDeepLinking`.\n *\n * @example\n * ```typescript\n * // In most cases, just call handleDeepLinking - it sets the marker automatically:\n * if (!isAuthenticated) {\n * await req.civicAuth.handleDeepLinking(requestUrl, originUrl);\n * return res.redirect('/login');\n * }\n * ```\n */\n async setAuthRedirectMarker(): Promise<void> {\n const logger = loggers.server;\n const deepLinkHandling =\n this.authConfig.deepLinkHandling ?? \"queryParamsOnly\";\n\n if (deepLinkHandling === \"disabled\") {\n return;\n }\n\n await this.storage.set(AuthFlowCookie.AUTH_REDIRECT_MARKER, \"1\", {\n maxAge: AUTH_REDIRECT_MARKER_MAX_AGE,\n });\n logger.debug(\"[setAuthRedirectMarker] Set auth redirect marker cookie\");\n }\n\n /**\n * Framework-agnostic URL detection and resolution helpers\n * These methods handle proxy environments and can be used by any framework\n */\n\n /**\n * Try to URI decode a value, returning the original value on error\n */\n static tryUriDecode(value: string): string {\n try {\n return decodeURIComponent(value);\n } catch (e) {\n console.error(\"Error decoding URI component:\", e);\n return value;\n }\n }\n\n /**\n * Get decoded query parameter from request\n */\n static getDecodedQueryParam(\n request: UrlDetectionRequest,\n paramName: string,\n ): string | null {\n const queryParam = request.searchParams.get(paramName);\n if (queryParam) {\n return CivicAuth.tryUriDecode(queryParam);\n }\n return null;\n }\n\n /**\n * Get value from cookie or query parameter (cookie takes precedence)\n */\n static getCookieOrQueryParam(\n request: UrlDetectionRequest,\n cookieName: string,\n queryName: string,\n ): string | null {\n // First check the cookie as it might have the full path with base directory\n const cookieValue = request.cookies.get(cookieName)?.value;\n if (cookieValue) {\n return CivicAuth.tryUriDecode(cookieValue);\n }\n\n // Fallback to query parameter\n return CivicAuth.getDecodedQueryParam(request, queryName);\n }\n\n /**\n * Get app URL from request (for proxy environment support)\n * Checks cookies first, then query parameters\n */\n static getAppUrl(request: UrlDetectionRequest): string | null {\n return CivicAuth.getCookieOrQueryParam(\n request,\n CodeVerifier.APP_URL,\n \"appUrl\",\n );\n }\n\n /**\n * Get login success URL with proper base URL handling\n * Extracts from state parameter or query parameters, resolves with baseUrl if provided\n */\n static getLoginSuccessUrl(\n request: UrlDetectionRequest,\n baseUrl?: string | null,\n ): string | null {\n const state = request.searchParams.get(\"state\");\n const loginSuccessUrl =\n loginSuccessUrlFromState(state) ||\n CivicAuth.getDecodedQueryParam(request, \"loginSuccessUrl\");\n\n if (!loginSuccessUrl) {\n return null;\n }\n\n return baseUrl ? new URL(loginSuccessUrl, baseUrl).href : loginSuccessUrl;\n }\n\n /**\n * Convert relative URL to absolute URL using appUrl for proxy environments\n */\n static toAbsoluteUrl(\n request: UrlDetectionRequest,\n url: string,\n appUrl?: string | null,\n ): string {\n if (url.startsWith(\"http\")) {\n return url;\n }\n\n // Use appUrl if available (for proxy environments), otherwise fall back to request origin\n const baseUrl = appUrl || new URL(request.url).origin;\n return new URL(url, baseUrl).href;\n }\n\n /**\n * Get post-logout redirect URL with proxy environment support\n */\n getPostLogoutRedirectUrl(request: UrlDetectionRequest): string {\n // Check if we have a target URL in the request (from middleware)\n const targetUrl = request.searchParams.get(\"targetUrl\");\n if (targetUrl) {\n return targetUrl;\n }\n\n const redirectTarget = this.authConfig.loginSuccessUrl ?? \"/\";\n\n // If loginSuccessUrl is absolute, use it as-is\n const isAbsoluteRedirect = /^(https?:\\/\\/|www\\.).+/i.test(redirectTarget);\n if (isAbsoluteRedirect) {\n return redirectTarget;\n }\n\n // Use appUrl from client for proxy environments\n const appUrl = CivicAuth.getAppUrl(request);\n if (appUrl) {\n return new URL(redirectTarget, appUrl).href;\n }\n\n // Fallback to request origin\n return new URL(request.url).origin;\n }\n\n /**\n * Smart callback handler that automatically detects frontend vs backend requests\n * and redirects appropriately. Use this instead of resolveOAuthAccessCode + manual redirect.\n *\n * @param params An object containing the authorization code, state, and the incoming request.\n * @param params.code The authorization code from query parameters.\n * @param params.state The OAuth state parameter.\n * @param params.req The incoming request object (e.g., from Express).\n * @param options Configuration options (frontendUrl override, apiResponse flag).\n * @returns Object with redirect information or HTML content for iframe completion.\n *\n * @example\n * ```javascript\n * app.get('/auth/callback', async (req, res) => {\n * const { code, state } = req.query;\n * // The request object 'req' is passed directly\n * const result = await req.civicAuth.handleCallback({ code, state, req });\n *\n * if (result.htmlContent) {\n * res.setHeader('Content-Type', 'text/html');\n * res.send(result.htmlContent);\n * } else if (result.redirectTo) {\n * res.redirect(result.redirectTo);\n * } else {\n * res.json({ success: true, user: result.user });\n * }\n * });\n * ```\n */\n async handleCallback(\n { code, state, req }: HandleCallbackParams,\n options?: {\n frontendUrl?: string;\n apiResponse?: boolean;\n },\n ): Promise<{\n redirectTo?: string;\n content?: string | { success: boolean; user?: User | null };\n }> {\n const logger = loggers.server;\n\n // Helper to clear the deep link cookie after successful auth.\n // This is centralized here so all framework implementations benefit.\n const clearReturnUrlCookie = async () => {\n try {\n await this.storage.delete(AuthFlowCookie.RETURN_URL);\n logger.debug(\n \"[handleCallback] Cleared deep link cookie after successful auth\",\n );\n } catch (error) {\n logger.warn(\"[handleCallback] Failed to clear deep link cookie\", {\n error,\n });\n }\n };\n\n // Handle same-domain callback for iframe workaround\n if (isSameDomainCallback(req)) {\n try {\n // Check if user is already authenticated before attempting token exchange\n const isAlreadyLoggedIn = await this.isLoggedIn();\n let user: User | null = null;\n\n if (isAlreadyLoggedIn) {\n // User is already authenticated, get existing user data\n user = await this.getUser();\n console.log(\n \"User already authenticated in same-domain callback:\",\n !!user,\n );\n } else {\n // For same-domain callbacks, we should have access to cookies\n const tokens = await this.resolveOAuthAccessCode(code, state);\n user = getUserFromTokens(tokens);\n console.log(\n \"Completed token exchange in same-domain callback:\",\n !!user,\n );\n }\n\n // Return JSON response for same-domain callback\n const currentUrl = new URL(req.url || \"\");\n\n // Extract and sanitize loginSuccessUrl (deep link) BEFORE cleaning up search params\n // Sanitization prevents open redirect attacks via malicious URLs in the query param\n const rawLoginSuccessUrl =\n currentUrl.searchParams.get(\"loginSuccessUrl\");\n const loginSuccessUrl = rawLoginSuccessUrl\n ? sanitizeReturnUrl(rawLoginSuccessUrl, currentUrl.origin)\n : null;\n\n const newSearchParams = new URLSearchParams(currentUrl.search);\n newSearchParams.delete(\"sameDomainCallback\");\n newSearchParams.delete(\"appUrl\");\n newSearchParams.delete(\"loginSuccessUrl\");\n\n // Use preserved deep link if available and valid, otherwise fall back to loginSuccessUrl or \"/\"\n // Note: Do NOT fall back to currentUrl.pathname as that's the callback URL, which would cause a loop\n let redirectUrl =\n loginSuccessUrl || this.authConfig.loginSuccessUrl || \"/\";\n\n // Apply basePath if configured\n if (this.authConfig.basePath) {\n redirectUrl = prependBasePath(redirectUrl, this.authConfig.basePath);\n }\n\n // Clear the deep link cookie after successful same-domain callback\n await clearReturnUrlCookie();\n\n return {\n content: {\n success: true,\n redirectUrl,\n } as { success: boolean; redirectUrl: string },\n };\n } catch (error) {\n console.error(\"Same-domain callback failed:\", error);\n throw error;\n }\n }\n\n // Try to resolve the OAuth code and create session\n let tokens: OIDCTokenResponseBody;\n let user: User | null;\n\n try {\n tokens = await this.resolveOAuthAccessCode(code, state);\n user = getUserFromTokens(tokens);\n\n // Clear the deep link cookie after successful token exchange\n await clearReturnUrlCookie();\n } catch (error) {\n // Check if this is a code verifier error and we're in iframe mode\n const isCodeVerifierError =\n error instanceof Error &&\n error.message.includes(\"Code verifier not found in storage\");\n\n if (isCodeVerifierError) {\n // First check if user is already authenticated before trying iframe workaround\n try {\n const isAlreadyLoggedIn = await this.isLoggedIn();\n\n if (isAlreadyLoggedIn) {\n // \"User already authenticated, skipping iframe workaround\",\n const user = await this.getUser();\n const loginSuccessUrlFromStateValue =\n loginSuccessUrlFromState(state);\n let frontendUrl =\n options?.frontendUrl ||\n loginSuccessUrlFromStateValue ||\n this.authConfig.loginSuccessUrl;\n\n // Apply basePath to frontendUrl if configured\n if (frontendUrl && this.authConfig.basePath) {\n frontendUrl = prependBasePath(\n frontendUrl,\n this.authConfig.basePath,\n );\n }\n\n // Check if this is an iframe context - if so, generate iframe completion HTML\n const stateDisplayMode = displayModeFromState(state, undefined);\n const isConfiguredForIframe = stateDisplayMode === \"iframe\";\n\n if (\n isConfiguredForIframe &&\n !this.authConfig.disableIframeDetection &&\n user &&\n frontendUrl\n ) {\n // Generating iframe completion HTML for already authenticated user\",\n const completionHtml = this.generateIframeCompletionHtml(\n user,\n frontendUrl,\n );\n return { content: completionHtml };\n }\n\n if (frontendUrl) {\n return { redirectTo: frontendUrl };\n } else {\n // Return JSON when no redirect destination is available.\n // This is intentional for API-style callbacks and cross-origin scenarios\n // where cookies aren't accessible to read config. The JSON response allows\n // clients (e.g., vanilla JS SDK) to handle the success case programmatically.\n return { content: { success: true, user } };\n }\n }\n } catch (authCheckError) {\n console.warn(\n \"Failed to check authentication status:\",\n authCheckError,\n );\n // Continue with iframe workaround if auth check fails\n }\n\n const stateDisplayMode = displayModeFromState(state, undefined);\n const isConfiguredForIframe = stateDisplayMode === \"iframe\";\n\n if (isConfiguredForIframe && !this.authConfig.disableIframeDetection) {\n // Generate HTML that will trigger same-domain callback\n const loginSuccessUrlFromStateValue = loginSuccessUrlFromState(state);\n let frontendUrl =\n options?.frontendUrl ||\n loginSuccessUrlFromStateValue ||\n this.authConfig.loginSuccessUrl;\n\n // Apply basePath to frontendUrl if configured\n if (frontendUrl && this.authConfig.basePath) {\n frontendUrl = prependBasePath(\n frontendUrl,\n this.authConfig.basePath,\n );\n }\n\n const callbackUrl = req.url || \"\";\n const sameDomainHtml = this.generateSameDomainCallbackHtml(\n callbackUrl,\n frontendUrl,\n );\n return { content: sameDomainHtml };\n }\n\n // For non-iframe mode or when iframe detection is disabled, return trigger text\n return {\n content: `<html lang=\"en\"><body><span style=\"display:none\">${TOKEN_EXCHANGE_TRIGGER_TEXT}</span></body></html>`,\n };\n }\n\n // Re-throw other errors\n throw error;\n }\n\n // Extract loginSuccessUrl from state if present\n const loginSuccessUrlFromStateValue = loginSuccessUrlFromState(state);\n\n // Priority: options.frontendUrl > loginSuccessUrl from state > config loginSuccessUrl\n let frontendUrl =\n options?.frontendUrl ||\n loginSuccessUrlFromStateValue ||\n this.authConfig.loginSuccessUrl;\n\n // Apply basePath to frontendUrl if configured\n if (frontendUrl && this.authConfig.basePath) {\n frontendUrl = prependBasePath(frontendUrl, this.authConfig.basePath);\n }\n\n // Priority 1: Check state for display mode configuration\n const stateDisplayMode = displayModeFromState(state, undefined);\n const isConfiguredForIframe = stateDisplayMode === \"iframe\";\n\n // Determine if this should be treated as an iframe request\n // Configuration (from state) takes precedence over auto-detection\n const shouldTreatAsIframe =\n isConfiguredForIframe && !this.authConfig.disableIframeDetection;\n\n const isTopLevelRedirect = req.headers[\"sec-fetch-dest\"] === \"document\";\n const isIframeRequest = req.headers[\"sec-fetch-dest\"] === \"iframe\";\n const isApiRequest =\n options?.apiResponse || req.headers.accept?.includes(\"application/json\");\n\n // Detect Safari or other browsers where iframe postMessage may fail due to cross-origin restrictions\n //TODO: Find a better way to detect this\n const userAgent = req.headers[\"user-agent\"] || \"\";\n const isSafari =\n userAgent.includes(\"Safari\") && !userAgent.includes(\"Chrome\");\n const isLikelyCrossOriginIframe =\n isSafari ||\n (userAgent.includes(\"WebKit\") && !userAgent.includes(\"Chrome\"));\n\n // Case 1: The request should be treated as iframe. Return HTML content.\n // Unless iframe detection is disabled via configuration OR we detect cross-origin issues\n if (\n shouldTreatAsIframe &&\n user &&\n frontendUrl &&\n !isLikelyCrossOriginIframe\n ) {\n const completionHtml = this.generateIframeCompletionHtml(\n user,\n frontendUrl,\n );\n return { content: completionHtml };\n }\n\n // Case 1b: Safari/cross-origin iframe case - redirect instead of HTML\n if (\n shouldTreatAsIframe &&\n user &&\n frontendUrl &&\n isLikelyCrossOriginIframe\n ) {\n return { redirectTo: frontendUrl };\n }\n\n // Case 2: The request is a top-level navigation. Return redirect URL.\n if (isTopLevelRedirect && frontendUrl) {\n return { redirectTo: frontendUrl };\n }\n\n // Case 2a: The request is from an iframe (detected by sec-fetch-dest)\n // Even if not configured for iframe in state, we should still generate iframe completion HTML\n if (isIframeRequest && user && frontendUrl) {\n if (isLikelyCrossOriginIframe) {\n console.log(\n \"Iframe request detected but cross-origin issues likely - redirecting\",\n );\n return { redirectTo: frontendUrl };\n } else {\n console.log(\n \"Generating iframe completion HTML for iframe request (detected by sec-fetch-dest)\",\n );\n const completionHtml = this.generateIframeCompletionHtml(\n user,\n frontendUrl,\n );\n return { content: completionHtml };\n }\n }\n\n // Case 3: The request is an API call. Return JSON content.\n if (isApiRequest) {\n return {\n content: {\n success: true,\n user,\n },\n };\n }\n\n // Fallback for older browsers or other contexts: if a frontend URL is configured,\n // assume a redirect to it.\n if (frontendUrl) {\n return { redirectTo: frontendUrl };\n }\n\n // Absolute fallback: redirect to loginSuccessUrl or \"/\"\n // Never return JSON for browser navigation - that would display raw JSON to the user\n const fallbackUrl = this.authConfig.loginSuccessUrl || \"/\";\n return {\n redirectTo: this.authConfig.basePath\n ? prependBasePath(fallbackUrl, this.authConfig.basePath)\n : fallbackUrl,\n };\n }\n\n /**\n * Generate HTML content for iframe completion that sends postMessage to parent\n */\n private generateIframeCompletionHtml(\n user: User,\n frontendUrl?: string,\n ): string {\n const escapedUser = JSON.stringify(user).replace(/'/g, \"\\\\'\");\n const clientId = this.authConfig.clientId;\n\n // Determine fallback redirect URL\n // Note: redirectUrl is the OAuth callback URL - it should NEVER be used as a post-login\n // destination as it would cause an infinite redirect loop in iframe mode.\n // postLogoutRedirectUrl is semantically incorrect for login success scenarios.\n const fallbackUrl = frontendUrl || this.authConfig.loginSuccessUrl || \"/\";\n\n return `\n <!DOCTYPE html>\n <html>\n <head>\n <title>Authentication Complete</title>\n <meta charset=\"utf-8\">\n </head>\n <body> \n <!-- Success signal for SignalObserver -->\n <div id=\"civic-auth-success-signal\" style=\"display: none;\" data-user-info='${escapedUser}'>\n ${TOKEN_EXCHANGE_SUCCESS_TEXT}\n </div>\n \n <script>\n // Send postMessage to parent to resolve authentication promise\n if (window.parent && window.parent !== window) {\n try {\n window.parent.postMessage({\n type: 'auth_success',\n detail: 'Authentication successful',\n data: {\n user: ${escapedUser},\n redirectUrl: ${JSON.stringify(fallbackUrl)}\n }\n }, '*');\n } catch (error) {\n console.error('❌ Failed to send postMessage:', error);\n }\n\n // Also send civicloginApp format message for compatibility\n try {\n window.parent.postMessage({\n source: 'civicloginApp',\n type: 'auth_success',\n clientId: ${JSON.stringify(clientId)},\n data: {\n user: ${escapedUser},\n redirectUrl: ${JSON.stringify(fallbackUrl)}\n }\n }, '*');\n } catch (error) {\n console.error('❌ Failed to send civicloginApp message:', error);\n }\n } else {\n console.log('❌ Not in iframe context or no parent window');\n }\n \n // Fallback redirect after 500ms delay to handle cases where:\n // 1. postMessage fails or parent doesn't respond\n // 2. Not in iframe context\n // 3. Any other edge cases where the user gets stuck\n setTimeout(function() {\n var redirectTarget = ${JSON.stringify(fallbackUrl)};\n console.log('🔄 Executing fallback redirect to:', redirectTarget);\n window.location.href = redirectTarget;\n }, 500);\n </script>\n </body>\n </html>\n `;\n }\n\n /**\n * Generate HTML response that triggers same-domain callback for iframe workaround\n */\n private generateSameDomainCallbackHtml = (\n callbackUrl: string,\n frontendUrl?: string,\n ): string => {\n const loginSuccessSegment = frontendUrl\n ? `&loginSuccessUrl=${encodeURIComponent(frontendUrl)}`\n : \"\";\n\n return `<html lang=\"en\">\n <body>\n <span style=\"display:none\">\n <script>\n window.onload = function () {\n // Get the complete URL including origin and path\n // This ensures we capture any base path like /directory\n const appUrl = window.location.href.substring(\n 0,\n window.location.href.indexOf(\"/api/auth\")\n );\n fetch('${callbackUrl}&sameDomainCallback=true&appUrl=' + encodeURIComponent(appUrl) + '${loginSuccessSegment}').then((response) => {\n response.json().then((jsonResponse) => {\n // For login: Redirect back to the callback route, so Case 2 in handleTokenExchangeComplete will be triggered\n // For logout: Redirect to the postLogoutRedirectUrl\n if(jsonResponse.redirectUrl) {\n window.location.href = jsonResponse.redirectUrl;\n }\n });\n });\n };\n </script>\n </span>\n </body>\n</html>\n`;\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"LoadingIcon.d.ts","sourceRoot":"","sources":["../../../src/shared/components/LoadingIcon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,KAAK,gBAAgB,GAAG;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B,CAAC;AAEF,QAAA,MAAM,WAAW,8BAId,gBAAgB,qDAkDlB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"LoadingIcon.d.ts","sourceRoot":"","sources":["../../../src/shared/components/LoadingIcon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,KAAK,gBAAgB,GAAG;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B,CAAC;AAEF,QAAA,MAAM,WAAW,GAAI,2BAIlB,gBAAgB,qDAkDlB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"cookieConfig.d.ts","sourceRoot":"","sources":["../../../src/shared/lib/cookieConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,WAAW,EACX,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACx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MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,qCAAqC;IACrC,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;IACrC,kDAAkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4CAA4C;IAC5C,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uBAAuB;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,MAAM,WAAW,8BAA8B;IAC7C,MAAM,EAAE,kBAAkB,GAAG;QAC3B,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC;KAClC,CAAC;IACF,IAAI,EAAE,YAAY,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,mBAAwB,GAChC,mBAAmB,CA6DrB;AAED;;GAEG;AACH,wBAAgB,4CAA4C,CAC1D,OAAO,GAAE,mBAAwB,GAChC,8BAA8B,CAsBhC;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,CAAC,EAAE,MAAM,GAChB,mBAAmB,CAQrB;AAED;;GAEG;AACH,wBAAgB,6BAA6B,IAAI,8BAA8B,CAM9E;AAED;;GAEG;AACH,wBAAgB,6BAA6B,IAAI,mBAAmB,CAKnE"}
@@ -1,5 +1,5 @@
1
1
  import { MAX_COOKIE_AGE_SECONDS } from "../../constants.js";
2
- import { AuthFlowCookie, CodeVerifier, OAuthTokenTypes, UserStorage, } from "./types.js";
2
+ import { AUTH_REDIRECT_MARKER_MAX_AGE, AuthFlowCookie, CodeVerifier, OAuthTokenTypes, UserStorage, } from "./types.js";
3
3
  /**
4
4
  * Creates a standardized cookie configuration for NextJS
5
5
  */
@@ -45,6 +45,11 @@ export function createCookieConfig(options = {}) {
45
45
  maxAge: 30 * 60, // 30 minutes
46
46
  httpOnly,
47
47
  },
48
+ [AuthFlowCookie.AUTH_REDIRECT_MARKER]: {
49
+ ...baseCookieConfig,
50
+ maxAge: AUTH_REDIRECT_MARKER_MAX_AGE,
51
+ httpOnly,
52
+ },
48
53
  },
49
54
  user: {
50
55
  ...baseCookieConfig,