@equinor/fusion-framework-vite-plugin-spa 3.1.5 → 3.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @equinor/fusion-framework-vite-plugin-spa
2
2
 
3
+ ## 3.1.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`0b34d5d`](https://github.com/equinor/fusion-framework/commit/0b34d5d895c740a77fc995abeca910fdca1cf633)]:
8
+ - @equinor/fusion-framework-module-msal@7.1.0
9
+
3
10
  ## 3.1.5
4
11
 
5
12
  ### Patch Changes
@@ -1,3 +1,3 @@
1
1
  // Generated by genversion.
2
- export const version = '3.1.5';
2
+ export const version = '3.1.6';
3
3
  //# sourceMappingURL=version.js.map
@@ -153,8 +153,8 @@ function requireRe () {
153
153
 
154
154
  // ## Pre-release Version Identifier
155
155
  // A numeric identifier, or a non-numeric identifier.
156
- // Non-numberic identifiers include numberic identifiers but can be longer.
157
- // Therefore non-numberic identifiers must go first.
156
+ // Non-numeric identifiers include numeric identifiers but can be longer.
157
+ // Therefore non-numeric identifiers must go first.
158
158
 
159
159
  createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NONNUMERICIDENTIFIER]
160
160
  }|${src[t.NUMERICIDENTIFIER]})`);
@@ -850,7 +850,7 @@ function requireDiff () {
850
850
  return prefix + 'patch'
851
851
  }
852
852
 
853
- // high and low are preleases
853
+ // high and low are prereleases
854
854
  return 'prerelease'
855
855
  };
856
856
 
@@ -2409,7 +2409,7 @@ function requireSubset () {
2409
2409
  // - If LT
2410
2410
  // - If LT.semver is greater than any < or <= comp in C, return false
2411
2411
  // - If LT is <=, and LT.semver does not satisfy every C, return false
2412
- // - If GT.semver has a prerelease, and not in prerelease mode
2412
+ // - If LT.semver has a prerelease, and not in prerelease mode
2413
2413
  // - If no C has a prerelease and the LT.semver tuple, return false
2414
2414
  // - Else return true
2415
2415
 
@@ -40463,7 +40463,7 @@ const createClientLogCallback = (provider, metadata, scope) => {
40463
40463
  };
40464
40464
 
40465
40465
  // Generated by genversion.
40466
- const version$2 = '7.0.0';
40466
+ const version$2 = '7.1.0';
40467
40467
 
40468
40468
  /**
40469
40469
  * Zod schema for telemetry configuration validation.
@@ -40488,6 +40488,7 @@ const MsalConfigSchema = z.object({
40488
40488
  provider: z.custom().optional(),
40489
40489
  requiresAuth: z.boolean().optional(),
40490
40490
  redirectUri: z.string().optional(),
40491
+ authCode: z.string().optional(),
40491
40492
  version: z.string().transform((x) => String(semver.coerce(x))),
40492
40493
  telemetry: TelemetryConfigSchema,
40493
40494
  });
@@ -40555,6 +40556,37 @@ class MsalConfigurator extends BaseConfigBuilder {
40555
40556
  this.#msalConfig = config;
40556
40557
  return this;
40557
40558
  }
40559
+ /**
40560
+ * Sets a backend-issued authorization code for token exchange.
40561
+ *
40562
+ * This enables the MSAL module to exchange a backend-generated auth code for tokens
40563
+ * during initialization, allowing users to be automatically signed in without triggering
40564
+ * an interactive MSAL login flow. The auth code is exchanged before the requiresAuth check,
40565
+ * so tokens are cached and no login prompt appears.
40566
+ *
40567
+ * This follows Microsoft's standard SPA Auth Code Flow pattern and is compatible with
40568
+ * MSAL Browser's acquireTokenByCode() method.
40569
+ *
40570
+ * @param authCode - The authorization code issued by the backend
40571
+ * @returns The configurator instance for method chaining
40572
+ *
40573
+ * @example
40574
+ * ```typescript
40575
+ * // Backend provides auth code in HTML/config
40576
+ * const config = { auth: { code: getAuthCodeFromBackend() } };
40577
+ * configurator.setAuthCode(config.auth.code);
40578
+ * ```
40579
+ *
40580
+ * @remarks
40581
+ * - Auth codes are single-use and short-lived (typically 5-10 minutes)
40582
+ * - The exchange happens during module initialization before requiresAuth check
40583
+ * - If exchange fails, the provider falls back to standard MSAL authentication flows
40584
+ * - Requires backend to be configured with SPA Auth Code support
40585
+ */
40586
+ setAuthCode(authCode) {
40587
+ this._set('authCode', async () => authCode);
40588
+ return this;
40589
+ }
40558
40590
  /**
40559
40591
  * Sets whether authentication is required for the application.
40560
40592
  *
@@ -41441,6 +41473,7 @@ class MsalProvider extends BaseModuleProvider {
41441
41473
  #client;
41442
41474
  #telemetry;
41443
41475
  #requiresAuth;
41476
+ #authCode;
41444
41477
  /**
41445
41478
  * The MSAL module version enum value indicating the API compatibility level.
41446
41479
  *
@@ -41498,6 +41531,9 @@ class MsalProvider extends BaseModuleProvider {
41498
41531
  });
41499
41532
  this.#requiresAuth = config.requiresAuth;
41500
41533
  this.#telemetry = config.telemetry;
41534
+ // Extract auth code from config if present
41535
+ // This will be used during initialize to exchange for tokens
41536
+ this.#authCode = config.authCode;
41501
41537
  // Validate required client configuration
41502
41538
  if (!config.client) {
41503
41539
  const error = new Error('Client is required, please provide a valid client in the configuration');
@@ -41513,12 +41549,17 @@ class MsalProvider extends BaseModuleProvider {
41513
41549
  *
41514
41550
  * This method must be called before using any authentication operations. It performs:
41515
41551
  * - Client initialization
41552
+ * - Auth code exchange (if backend-issued code provided)
41516
41553
  * - Redirect result handling (if returning from auth flow)
41517
41554
  * - Automatic login attempt if requiresAuth is enabled and no valid session exists
41518
41555
  *
41519
41556
  * @returns Promise that resolves when initialization is complete
41520
41557
  *
41521
41558
  * @remarks
41559
+ * Auth code exchange happens before the requiresAuth check, allowing automatic sign-in
41560
+ * without user interaction when a valid backend-issued code is provided. If exchange fails,
41561
+ * the provider falls back to standard MSAL authentication flows.
41562
+ *
41522
41563
  * The provider will attempt automatic login with empty scopes if requiresAuth is true.
41523
41564
  * Apps should call acquireToken with actual scopes after initialization completes.
41524
41565
  */
@@ -41526,6 +41567,52 @@ class MsalProvider extends BaseModuleProvider {
41526
41567
  const measurement = this._trackMeasurement('initialize', TelemetryLevel.Debug);
41527
41568
  // Initialize the underlying MSAL client first
41528
41569
  await this.#client.initialize();
41570
+ // Priority 0: Exchange auth code if provided by backend
41571
+ // This must happen before the requiresAuth check so tokens are cached
41572
+ if (this.#authCode) {
41573
+ try {
41574
+ this._trackEvent('initialize.exchanging-auth-code', TelemetryLevel.Information);
41575
+ // Use MSAL's acquireTokenByCode to exchange backend auth code for tokens
41576
+ // This follows Microsoft's standard SPA Auth Code Flow pattern
41577
+ const clientId = this.#client.clientId;
41578
+ if (!clientId) {
41579
+ throw new Error('Client ID is required for auth code exchange');
41580
+ }
41581
+ // Exchange the auth code for tokens using the client ID's default scope.
41582
+ // The `/.default` scope represents all permissions configured for this app in Entra ID,
41583
+ // ensuring the exchanged tokens have the correct app-level permissions without requiring
41584
+ // the caller to specify scopes. This follows MSAL's recommended SPA auth code pattern.
41585
+ // This method is inherited from PublicClientApplication (MSAL Browser v4+)
41586
+ const result = await this.#client.acquireTokenByCode({
41587
+ code: this.#authCode,
41588
+ scopes: [`${clientId}/.default`],
41589
+ });
41590
+ // Successfully exchanged auth code - set active account
41591
+ if (result.account) {
41592
+ this.#client.setActiveAccount(result.account);
41593
+ this._trackEvent('initialize.auth-code-exchanged-account', TelemetryLevel.Information, {
41594
+ properties: {
41595
+ username: result.account.username,
41596
+ },
41597
+ });
41598
+ }
41599
+ }
41600
+ catch (error) {
41601
+ // Auth code exchange failed - log and fall back to standard flows
41602
+ this._trackException('initialize.auth-code-exchange-failed', TelemetryLevel.Warning, {
41603
+ exception: error instanceof Error ? error : new Error(String(error)),
41604
+ properties: {
41605
+ message: error instanceof Error ? error.message : String(error),
41606
+ reason: 'Auth code exchange failed, falling back to standard authentication flows',
41607
+ },
41608
+ });
41609
+ // Continue to requiresAuth check - will trigger standard login if needed
41610
+ }
41611
+ finally {
41612
+ // Clear auth code to avoid repeated attempts
41613
+ this.#authCode = undefined;
41614
+ }
41615
+ }
41529
41616
  // Only attempt authentication if this provider requires it
41530
41617
  if (this.#requiresAuth) {
41531
41618
  // Priority 1: Check if returning from redirect-based authentication
@@ -44818,7 +44905,7 @@ async function registerServiceWorker(framework) {
44818
44905
  }
44819
44906
 
44820
44907
  // Generated by genversion.
44821
- const version = '3.1.5';
44908
+ const version = '3.1.6';
44822
44909
 
44823
44910
  // Allow dynamic import without vite
44824
44911
  const importWithoutVite = (path) => import(/* @vite-ignore */ path);