@chemmangat/msal-next 5.0.1 → 5.2.0

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
@@ -2,6 +2,114 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [5.2.0] - 2026-04-07
6
+
7
+ ### 🔧 Compatibility
8
+
9
+ #### Support for `@azure/msal-browser` v5.x and `@azure/msal-react` v4.x / v5.x
10
+
11
+ Peer dependency ranges updated to include the latest MSAL major versions:
12
+
13
+ ```json
14
+ "@azure/msal-browser": "^3.11.0 || ^4.0.0 || ^5.0.0",
15
+ "@azure/msal-react": "^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0"
16
+ ```
17
+
18
+ Breaking changes in `msal-browser` v5 are handled transparently at runtime — no changes required in your app code.
19
+
20
+ **What changed internally:**
21
+
22
+ - `handleRedirectPromise()` now receives an options object on v5 (`navigateToLoginRequestUrl` moved here from config)
23
+ - `storeAuthStateInCookie` and `navigateToLoginRequestUrl` are conditionally omitted from the MSAL config object when running on v5 (both were removed from `BrowserAuthOptions`/`CacheOptions`)
24
+ - `EventType.LOGIN_SUCCESS` payload is now `AccountInfo` on v5 (was `AuthenticationResult` on v3/v4) — handled with a runtime type guard
25
+ - `EventType.LOGIN_FAILURE` was removed in v5; login failures now surface as `ACQUIRE_TOKEN_FAILURE` — both are handled
26
+
27
+ ## [5.1.0] - 2026-03-17
28
+
29
+ ### ✨ New Features
30
+
31
+ #### 1. Multi-Tenant Support — `multiTenant` config
32
+
33
+ Pass a `multiTenant` object to `MSALProvider` to control which tenants can access your app:
34
+
35
+ ```tsx
36
+ <MSALProvider
37
+ clientId="..."
38
+ multiTenant={{
39
+ type: 'multi', // 'single' | 'multi' | 'organizations' | 'consumers' | 'common'
40
+ allowList: ['contoso.com', 'fabrikam.com'],
41
+ blockList: ['competitor.com'],
42
+ requireType: 'Member', // block B2B guests
43
+ requireMFA: true,
44
+ }}
45
+ onTenantDenied={(reason) => router.push(`/denied?reason=${reason}`)}
46
+ >
47
+ ```
48
+
49
+ - `type` maps to the MSAL authority (`single` → tenant, `multi`/`common` → common, etc.)
50
+ - `allowList` / `blockList` accept tenant IDs or domain names
51
+ - `requireType: 'Member'` blocks B2B guests; `'Guest'` allows only guests
52
+ - `requireMFA` checks the `amr` claim for MFA evidence
53
+ - Tenant validation runs automatically after redirect authentication
54
+
55
+ #### 2. `useTenant()` Hook
56
+
57
+ ```tsx
58
+ import { useTenant } from '@chemmangat/msal-next';
59
+
60
+ const { tenantId, tenantDomain, isGuestUser, homeTenantId, resourceTenantId, claims } = useTenant();
61
+ ```
62
+
63
+ Returns tenant context for the current user including B2B guest detection.
64
+
65
+ #### 3. Per-Page Tenant Restrictions
66
+
67
+ ```tsx
68
+ // app/admin/page.tsx
69
+ export const auth = {
70
+ required: true,
71
+ tenant: {
72
+ allowList: ['contoso.com'],
73
+ requireMFA: true,
74
+ },
75
+ };
76
+ ```
77
+
78
+ #### 4. Middleware Tenant Validation
79
+
80
+ ```ts
81
+ // middleware.ts
82
+ export const middleware = createAuthMiddleware({
83
+ protectedRoutes: ['/dashboard'],
84
+ tenantConfig: { allowList: ['contoso.com'] },
85
+ tenantDeniedPath: '/unauthorized',
86
+ });
87
+ ```
88
+
89
+ #### 5. Cross-Tenant Token Acquisition
90
+
91
+ ```tsx
92
+ const { acquireTokenForTenant } = useMsalAuth();
93
+ const token = await acquireTokenForTenant('target-tenant-id', ['User.Read']);
94
+ ```
95
+
96
+ #### 6. `useTenantConfig()` Hook
97
+
98
+ Access the `multiTenant` config from anywhere in the component tree:
99
+
100
+ ```tsx
101
+ import { useTenantConfig } from '@chemmangat/msal-next';
102
+ const config = useTenantConfig();
103
+ ```
104
+
105
+ ### 🔧 Internal
106
+
107
+ - `createMsalConfig` now maps `multiTenant.type` to the correct MSAL authority (takes precedence over legacy `authorityType`)
108
+ - `validateTenantAccess` utility exported for advanced use cases
109
+ - `TenantAuthConfig` type exported for per-page tenant config
110
+
111
+ ---
112
+
5
113
  ## [5.0.0] - 2026-03-16
6
114
 
7
115
  ### ⚠️ Breaking Changes