@equinor/fusion-framework-module-msal 5.1.2 → 6.0.0-next.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 (144) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/README.md +237 -40
  3. package/dist/esm/MsalClient.interface.js +2 -0
  4. package/dist/esm/MsalClient.interface.js.map +1 -0
  5. package/dist/esm/MsalClient.js +215 -0
  6. package/dist/esm/MsalClient.js.map +1 -0
  7. package/dist/esm/MsalConfigurator.js +248 -0
  8. package/dist/esm/MsalConfigurator.js.map +1 -0
  9. package/dist/esm/MsalProvider.interface.js +2 -0
  10. package/dist/esm/MsalProvider.interface.js.map +1 -0
  11. package/dist/esm/MsalProvider.js +525 -0
  12. package/dist/esm/MsalProvider.js.map +1 -0
  13. package/dist/esm/MsalProxyProvider.interface.js +2 -0
  14. package/dist/esm/MsalProxyProvider.interface.js.map +1 -0
  15. package/dist/esm/__tests__/versioning/resolve-version.test.js +29 -38
  16. package/dist/esm/__tests__/versioning/resolve-version.test.js.map +1 -1
  17. package/dist/esm/create-client-log-callback.js +87 -0
  18. package/dist/esm/create-client-log-callback.js.map +1 -0
  19. package/dist/esm/create-proxy-provider.js +84 -0
  20. package/dist/esm/create-proxy-provider.js.map +1 -0
  21. package/dist/esm/index.js +1 -1
  22. package/dist/esm/index.js.map +1 -1
  23. package/dist/esm/module.js +64 -16
  24. package/dist/esm/module.js.map +1 -1
  25. package/dist/esm/static.js +32 -2
  26. package/dist/esm/static.js.map +1 -1
  27. package/dist/esm/types.js +9 -0
  28. package/dist/esm/types.js.map +1 -1
  29. package/dist/esm/util/compare-origin.js +11 -0
  30. package/dist/esm/util/compare-origin.js.map +1 -0
  31. package/dist/esm/{v2/client/util/url.js → util/normalize-uri.js} +1 -10
  32. package/dist/esm/util/normalize-uri.js.map +1 -0
  33. package/dist/esm/{v2/client/util/browser.js → util/redirect.js} +1 -1
  34. package/dist/esm/util/redirect.js.map +1 -0
  35. package/dist/esm/v2/IAuthClient.interface.js +2 -0
  36. package/dist/esm/v2/IAuthClient.interface.js.map +1 -0
  37. package/dist/esm/v2/IPublicClientApplication.interface.js +2 -0
  38. package/dist/esm/v2/IPublicClientApplication.interface.js.map +1 -0
  39. package/dist/esm/v2/MsalProvider.interface.js +2 -0
  40. package/dist/esm/v2/MsalProvider.interface.js.map +1 -0
  41. package/dist/esm/v2/create-proxy-client.js +155 -0
  42. package/dist/esm/v2/create-proxy-client.js.map +1 -0
  43. package/dist/esm/v2/create-proxy-provider.js +140 -0
  44. package/dist/esm/v2/create-proxy-provider.js.map +1 -0
  45. package/dist/esm/v2/map-account-info.js +18 -0
  46. package/dist/esm/v2/map-account-info.js.map +1 -0
  47. package/dist/esm/v2/map-authentication-result.js +22 -0
  48. package/dist/esm/v2/map-authentication-result.js.map +1 -0
  49. package/dist/esm/version.js +1 -1
  50. package/dist/esm/version.js.map +1 -1
  51. package/dist/esm/versioning/resolve-version.js +28 -16
  52. package/dist/esm/versioning/resolve-version.js.map +1 -1
  53. package/dist/tsconfig.tsbuildinfo +1 -1
  54. package/dist/types/MsalClient.d.ts +141 -0
  55. package/dist/types/MsalClient.interface.d.ts +103 -0
  56. package/dist/types/MsalConfigurator.d.ts +147 -0
  57. package/dist/types/MsalProvider.d.ts +291 -0
  58. package/dist/types/MsalProvider.interface.d.ts +159 -0
  59. package/dist/types/MsalProxyProvider.interface.d.ts +52 -0
  60. package/dist/types/create-client-log-callback.d.ts +38 -0
  61. package/dist/types/create-proxy-provider.d.ts +19 -0
  62. package/dist/types/index.d.ts +5 -4
  63. package/dist/types/module.d.ts +70 -4
  64. package/dist/types/static.d.ts +32 -1
  65. package/dist/types/types.d.ts +14 -6
  66. package/dist/types/util/redirect.d.ts +1 -0
  67. package/dist/types/v2/IAuthClient.interface.d.ts +68 -0
  68. package/dist/types/v2/IPublicClientApplication.interface.d.ts +68 -0
  69. package/dist/types/v2/MsalProvider.interface.d.ts +85 -0
  70. package/dist/types/v2/create-proxy-client.d.ts +22 -0
  71. package/dist/types/v2/create-proxy-provider.d.ts +24 -0
  72. package/dist/types/v2/map-account-info.d.ts +9 -0
  73. package/dist/types/v2/map-authentication-result.d.ts +9 -0
  74. package/dist/types/v2/types.d.ts +12 -0
  75. package/dist/types/version.d.ts +1 -1
  76. package/dist/types/versioning/resolve-version.d.ts +1 -1
  77. package/package.json +11 -6
  78. package/src/MsalClient.interface.ts +121 -0
  79. package/src/MsalClient.ts +274 -0
  80. package/src/MsalConfigurator.ts +289 -0
  81. package/src/MsalProvider.interface.ts +175 -0
  82. package/src/MsalProvider.ts +597 -0
  83. package/src/MsalProxyProvider.interface.ts +71 -0
  84. package/src/__tests__/versioning/resolve-version.test.ts +29 -42
  85. package/src/create-client-log-callback.ts +101 -0
  86. package/src/create-proxy-provider.ts +89 -0
  87. package/src/index.ts +6 -7
  88. package/src/module.ts +88 -20
  89. package/src/static.ts +32 -3
  90. package/src/types.ts +15 -7
  91. package/src/util/compare-origin.ts +11 -0
  92. package/src/{v2/client/util/url.ts → util/normalize-uri.ts} +0 -10
  93. package/src/v2/IAuthClient.interface.ts +91 -0
  94. package/src/v2/IPublicClientApplication.interface.ts +71 -0
  95. package/src/v2/MsalProvider.interface.ts +92 -0
  96. package/src/v2/create-proxy-client.ts +186 -0
  97. package/src/v2/create-proxy-provider.ts +156 -0
  98. package/src/v2/map-account-info.ts +20 -0
  99. package/src/v2/map-authentication-result.ts +24 -0
  100. package/src/v2/types.ts +12 -0
  101. package/src/version.ts +1 -1
  102. package/src/versioning/resolve-version.ts +35 -28
  103. package/tsconfig.json +3 -0
  104. package/dist/esm/v2/client/behavior.js +0 -5
  105. package/dist/esm/v2/client/behavior.js.map +0 -1
  106. package/dist/esm/v2/client/client.js +0 -142
  107. package/dist/esm/v2/client/client.js.map +0 -1
  108. package/dist/esm/v2/client/create-auth-client.js +0 -36
  109. package/dist/esm/v2/client/create-auth-client.js.map +0 -1
  110. package/dist/esm/v2/client/index.js +0 -5
  111. package/dist/esm/v2/client/index.js.map +0 -1
  112. package/dist/esm/v2/client/log/console.js +0 -45
  113. package/dist/esm/v2/client/log/console.js.map +0 -1
  114. package/dist/esm/v2/client/request.js +0 -2
  115. package/dist/esm/v2/client/request.js.map +0 -1
  116. package/dist/esm/v2/client/util/browser.js.map +0 -1
  117. package/dist/esm/v2/client/util/url.js.map +0 -1
  118. package/dist/esm/v2/configurator.js +0 -42
  119. package/dist/esm/v2/configurator.js.map +0 -1
  120. package/dist/esm/v2/index.js +0 -3
  121. package/dist/esm/v2/index.js.map +0 -1
  122. package/dist/esm/v2/provider.js +0 -115
  123. package/dist/esm/v2/provider.js.map +0 -1
  124. package/dist/types/v2/client/behavior.d.ts +0 -13
  125. package/dist/types/v2/client/client.d.ts +0 -89
  126. package/dist/types/v2/client/create-auth-client.d.ts +0 -27
  127. package/dist/types/v2/client/index.d.ts +0 -5
  128. package/dist/types/v2/client/log/console.d.ts +0 -28
  129. package/dist/types/v2/client/request.d.ts +0 -65
  130. package/dist/types/v2/configurator.d.ts +0 -32
  131. package/dist/types/v2/index.d.ts +0 -2
  132. package/dist/types/v2/provider.d.ts +0 -59
  133. package/src/v2/client/behavior.ts +0 -14
  134. package/src/v2/client/client.ts +0 -180
  135. package/src/v2/client/create-auth-client.ts +0 -48
  136. package/src/v2/client/index.ts +0 -8
  137. package/src/v2/client/log/console.ts +0 -58
  138. package/src/v2/client/request.ts +0 -66
  139. package/src/v2/configurator.ts +0 -58
  140. package/src/v2/index.ts +0 -2
  141. package/src/v2/provider.ts +0 -178
  142. /package/dist/types/{v2/client/util/browser.d.ts → util/compare-origin.d.ts} +0 -0
  143. /package/dist/types/{v2/client/util/url.d.ts → util/normalize-uri.d.ts} +0 -0
  144. /package/src/{v2/client/util/browser.ts → util/redirect.ts} +0 -0
@@ -0,0 +1,159 @@
1
+ import type { AcquireTokenOptions, AcquireTokenResult, IMsalClient, LoginOptions, LoginResult, LogoutOptions } from './MsalClient.interface';
2
+ import type { IProxyProvider } from './MsalProxyProvider.interface';
3
+ import type { AccountInfo, AuthenticationResult } from './types';
4
+ /**
5
+ * Legacy token acquisition options maintaining backward compatibility.
6
+ *
7
+ * This type extends `AcquireTokenOptions` with an optional `scopes` property
8
+ * to support legacy API calls that passed scopes directly rather than in the request object.
9
+ *
10
+ * @property scopes - Optional array of OAuth scopes (deprecated, use request.scopes)
11
+ *
12
+ * @deprecated Use the modern format with scopes in the request object instead
13
+ * @example
14
+ * ```typescript
15
+ * // Deprecated legacy format
16
+ * acquireToken({ scopes: ['User.Read'] })
17
+ *
18
+ * // Modern format (preferred)
19
+ * acquireToken({ request: { scopes: ['User.Read'] } })
20
+ * ```
21
+ */
22
+ export type AcquireTokenOptionsLegacy = AcquireTokenOptions & {
23
+ scopes?: string[];
24
+ };
25
+ /**
26
+ * Interface for MSAL v4 authentication provider.
27
+ *
28
+ * This interface defines the contract for authentication providers that work
29
+ * with Microsoft Authentication Library v4, providing a unified API for
30
+ * token acquisition, user authentication, and account management.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const provider: IMsalProvider = new MsalProvider(config);
35
+ *
36
+ * // Login user (v4 format)
37
+ * await provider.login({ request: { scopes: ['User.Read'] } });
38
+ *
39
+ * // Acquire token (v4 format - recommended)
40
+ * const token = await provider.acquireAccessToken({
41
+ * request: { scopes: ['https://graph.microsoft.com/.default'] }
42
+ * });
43
+ * ```
44
+ */
45
+ export interface IMsalProvider extends IProxyProvider {
46
+ /**
47
+ * The MSAL PublicClientApplication client instance.
48
+ *
49
+ * Provides access to the underlying MSAL client for advanced use cases.
50
+ * Use provider methods for standard authentication operations.
51
+ */
52
+ readonly client: IMsalClient;
53
+ /**
54
+ * The currently authenticated account information.
55
+ *
56
+ * Returns the active account if available, or null if no user is authenticated.
57
+ */
58
+ readonly account: AccountInfo | null;
59
+ /**
60
+ * Initializes the MSAL provider and handles authentication state.
61
+ *
62
+ * This method must be called before using other provider methods. It:
63
+ * - Initializes the MSAL client
64
+ * - Processes any pending authentication redirects
65
+ * - Attempts automatic login if requiresAuth is enabled
66
+ *
67
+ * @returns Promise that resolves when initialization is complete
68
+ */
69
+ initialize(): Promise<void>;
70
+ /**
71
+ * Acquires an access token string for the specified scopes.
72
+ *
73
+ * This is a convenience method that returns only the access token string,
74
+ * unlike `acquireToken` which returns the full authentication result.
75
+ *
76
+ * @param options - Token acquisition options including scopes
77
+ * @returns Promise resolving to the access token string, or undefined if acquisition fails
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const token = await provider.acquireAccessToken({
82
+ * request: { scopes: ['User.Read'] }
83
+ * });
84
+ * ```
85
+ */
86
+ acquireAccessToken(options: AcquireTokenOptionsLegacy): Promise<string | undefined>;
87
+ /**
88
+ * Acquires a full authentication result including token and account information.
89
+ *
90
+ * This method attempts silent token acquisition first, then falls back to interactive
91
+ * authentication based on the configured behavior (popup or redirect).
92
+ *
93
+ * @param options - Token acquisition options including scopes
94
+ * @returns Promise resolving to full authentication result or null/undefined on failure
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const result = await provider.acquireToken({
99
+ * request: { scopes: ['User.Read'] },
100
+ * behavior: 'popup'
101
+ * });
102
+ * ```
103
+ */
104
+ acquireToken(options: AcquireTokenOptionsLegacy): Promise<AcquireTokenResult>;
105
+ /**
106
+ * Authenticates a user interactively with Microsoft Identity Platform.
107
+ *
108
+ * This method implements a sophisticated flow that attempts silent authentication
109
+ * first (if configured) and falls back to interactive authentication based on behavior.
110
+ *
111
+ * @param options - Login configuration options including request, behavior, and silent flag
112
+ * @returns Promise resolving to authentication result or undefined for redirect flows
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * // Basic login with default settings
117
+ * await provider.login({ request: { scopes: ['User.Read'] } });
118
+ * ```
119
+ */
120
+ login(options: LoginOptions): Promise<LoginResult>;
121
+ /**
122
+ * Logs out the current user and clears authentication state.
123
+ *
124
+ * Initiates a logout flow that clears local tokens and navigates to Microsoft's
125
+ * logout endpoint. Always uses redirect flow for reliability.
126
+ *
127
+ * @param options - Optional logout configuration
128
+ * @returns Promise resolving to true on success, false on failure
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * // Basic logout
133
+ * await provider.logout();
134
+ *
135
+ * // Logout with redirect
136
+ * await provider.logout({ redirectUri: 'https://app.com/logout' });
137
+ * ```
138
+ */
139
+ logout(options?: LogoutOptions): Promise<boolean>;
140
+ /**
141
+ * Processes any pending authentication redirect after browser navigation.
142
+ *
143
+ * This method must be called on app initialization to handle authentication
144
+ * results from redirect-based flows. It processes tokens and account information
145
+ * returned by Microsoft's identity provider.
146
+ *
147
+ * @returns Promise resolving to authentication result or null if no redirect pending
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * // Call on app startup
152
+ * const result = await provider.handleRedirect();
153
+ * if (result?.account) {
154
+ * // User successfully authenticated via redirect
155
+ * }
156
+ * ```
157
+ */
158
+ handleRedirect(): Promise<AuthenticationResult | null>;
159
+ }
@@ -0,0 +1,52 @@
1
+ import type { SemVer } from 'semver';
2
+ import type { MsalModuleVersion } from './static';
3
+ /**
4
+ * Interface for providers that can create version-compatible proxy providers.
5
+ *
6
+ * This interface enables backward compatibility by allowing providers to create
7
+ * proxies that adapt their API to match different MSAL version signatures. The proxy
8
+ * wraps the v4 implementation and exposes it through older version interfaces.
9
+ *
10
+ * @remarks
11
+ * This interface should ideally be defined in the @equinor/fusion-framework-module package
12
+ * for broader framework compatibility.
13
+ *
14
+ * @property version - The semantic version of the provider
15
+ * @property msalVersion - The MSAL module version enum value
16
+ * @property createProxyProvider - Method to create a version-specific proxy provider
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const provider: IMsalProvider = new MsalProvider(config);
21
+ *
22
+ * // Create a v2-compatible proxy
23
+ * const v2Proxy = provider.createProxyProvider('2.0.0');
24
+ * // v2Proxy now has v2-compatible method signatures
25
+ * ```
26
+ */
27
+ export interface IProxyProvider {
28
+ /**
29
+ * The semantic version of the provider.
30
+ *
31
+ * This represents the actual version number of the MSAL implementation,
32
+ * following semantic versioning (semver) standards.
33
+ */
34
+ readonly version: string | SemVer;
35
+ /**
36
+ * The MSAL module version enum value indicating the API compatibility level.
37
+ *
38
+ * This property specifies which MSAL version's API surface this provider implements,
39
+ * allowing for version-specific behavior and proxy provider creation.
40
+ */
41
+ msalVersion: MsalModuleVersion;
42
+ /**
43
+ * Creates a proxy provider compatible with the specified MSAL version.
44
+ *
45
+ * The proxy adapts the provider's v4 API to match the requested version's interface,
46
+ * enabling backward compatibility during migration scenarios.
47
+ *
48
+ * @param version - Target version key (V2, V4, or Latest)
49
+ * @returns Proxy provider with version-specific type
50
+ */
51
+ createProxyProvider<T extends keyof ProxyProviderMap>(version: T): ProxyProviderMap[T];
52
+ }
@@ -0,0 +1,38 @@
1
+ import { type ILoggerCallback } from '@azure/msal-browser';
2
+ import { type ITelemetryProvider } from '@equinor/fusion-framework-module-telemetry';
3
+ /**
4
+ * Creates a telemetry callback function for MSAL logging integration.
5
+ *
6
+ * This function bridges MSAL's internal logging system with the framework's
7
+ * telemetry infrastructure. It maps MSAL log levels to telemetry levels and
8
+ * forwards log events to the provided telemetry provider with structured metadata.
9
+ *
10
+ * The callback function returned by this method will be called by MSAL whenever
11
+ * a log event occurs, allowing for centralized logging and monitoring of
12
+ * authentication-related events.
13
+ *
14
+ * @param provider - Telemetry provider instance to receive log events
15
+ * @param metadata - Additional metadata to include with each telemetry event (e.g., module version, environment)
16
+ * @param scope - Telemetry scope identifiers for categorization and filtering
17
+ * @returns Logger callback function for MSAL that forwards events to telemetry provider
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const callback = createClientLogCallback(
22
+ * telemetryProvider,
23
+ * { module: 'msal', version: '4.0.0' },
24
+ * ['framework', 'authentication']
25
+ * );
26
+ *
27
+ * // Use with MSAL configuration
28
+ * const config = {
29
+ * system: {
30
+ * loggerOptions: {
31
+ * loggerCallback: callback,
32
+ * piiLoggingEnabled: false
33
+ * }
34
+ * }
35
+ * };
36
+ * ```
37
+ */
38
+ export declare const createClientLogCallback: (provider: ITelemetryProvider, metadata: Record<string, unknown>, scope: string[]) => ILoggerCallback | undefined;
@@ -0,0 +1,19 @@
1
+ import type { IMsalProvider } from './MsalProvider.interface';
2
+ /**
3
+ * Creates a proxy provider for version compatibility.
4
+ *
5
+ * This function handles the creation of proxy providers that maintain
6
+ * backward compatibility with different MSAL versions while using the
7
+ * latest MSAL v4 implementation under the hood.
8
+ *
9
+ * @param provider - The base MSAL provider instance
10
+ * @param version - The target version string (e.g., '2.0.0', '4.0.0')
11
+ * @returns A proxy provider compatible with the specified version
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const baseProvider = new MsalProvider(config);
16
+ * const v2Proxy = createProxyProvider(baseProvider, '2.0.0');
17
+ * ```
18
+ */
19
+ export declare function createProxyProvider<T = IMsalProvider>(provider: IMsalProvider, version: string): T;
@@ -1,5 +1,6 @@
1
- export { module, configureMsal, enableMSAL, type AuthConfigurator as IAppConfigurator, type AuthConfigFn, type IAuthProvider, type MsalModule, } from './module';
2
- export { MsalModuleVersion } from './static';
1
+ export { module, configureMsal, enableMSAL, type MsalModule, type AuthConfigFn, } from './module';
2
+ export type { IMsalProvider } from './MsalProvider.interface';
3
+ export type { IMsalClient } from './MsalClient.interface';
4
+ export { MsalClient, type MsalClientConfig } from './MsalClient';
5
+ export type { AccountInfo, AuthenticationResult } from './types';
3
6
  export { default } from './module';
4
- export type { AccountInfo, AuthenticationResult } from './v2/types';
5
- export type { AuthClientConfig } from './v2/configurator';
@@ -1,13 +1,79 @@
1
1
  import { type Module, type IModulesConfigurator } from '@equinor/fusion-framework-module';
2
- import { AuthConfigurator, type AuthClientConfig, type IAuthProvider } from './v2';
3
- export type MsalModule = Module<'auth', IAuthProvider, AuthConfigurator, [MsalModule]>;
4
- export type { AuthConfigurator, IAuthProvider };
2
+ import { MsalConfigurator } from './MsalConfigurator';
3
+ import { type IMsalProvider } from './MsalProvider';
4
+ import type { MsalClientConfig } from './MsalClient';
5
+ /**
6
+ * MSAL authentication module configuration.
7
+ *
8
+ * This module provides Microsoft Authentication Library (MSAL) integration for the
9
+ * Fusion Framework, supporting MSAL v4 with backward compatibility for v2 applications.
10
+ */
11
+ export type MsalModule = Module<'auth', IMsalProvider, MsalConfigurator, [MsalModule]>;
12
+ /**
13
+ * MSAL authentication module definition.
14
+ *
15
+ * This module manages authentication providers with the following initialization flow:
16
+ * 1. Check for custom provider configuration
17
+ * 2. Check for existing provider in parent module (for proxy compatibility)
18
+ * 3. Create new provider with client configuration
19
+ *
20
+ * @remarks
21
+ * The module supports proxy providers for version compatibility, allowing v4 implementations
22
+ * to work with v2-compatible code during migration periods.
23
+ */
5
24
  export declare const module: MsalModule;
25
+ /**
26
+ * Configuration function type for MSAL module setup.
27
+ *
28
+ * This function receives a builder object with methods to configure the MSAL client
29
+ * and authentication requirements.
30
+ */
6
31
  export type AuthConfigFn = (builder: {
7
- setClientConfig: (config: AuthClientConfig) => void;
32
+ /**
33
+ * Set MSAL client configuration
34
+ * @param config - Client configuration with tenant ID, client ID, etc.
35
+ */
36
+ setClientConfig: (config: MsalClientConfig) => void;
37
+ /**
38
+ * Set whether authentication is required for the application
39
+ * @param requiresAuth - If true, app will attempt automatic login on initialization
40
+ */
8
41
  setRequiresAuth: (requiresAuth: boolean) => void;
9
42
  }) => void;
43
+ /**
44
+ * Enables MSAL authentication module in the framework.
45
+ *
46
+ * This is a convenience function that adds the MSAL module configuration to the
47
+ * framework configurator with optional configuration callback.
48
+ *
49
+ * @param configurator - The framework modules configurator instance
50
+ * @param configure - Optional configuration callback for MSAL setup
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * enableMSAL(frameworkConfigurator, (builder) => {
55
+ * builder.setClientConfig({
56
+ * auth: { clientId: 'your-client-id', tenantId: 'your-tenant-id' }
57
+ * });
58
+ * builder.setRequiresAuth(true);
59
+ * });
60
+ * ```
61
+ */
10
62
  export declare const enableMSAL: (configurator: IModulesConfigurator<any, any>, configure?: AuthConfigFn) => void;
63
+ /**
64
+ * Creates MSAL module configuration with custom setup.
65
+ *
66
+ * @param configure - Configuration callback function
67
+ * @returns Module configuration object ready for framework integration
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const msalConfig = configureMsal((builder) => {
72
+ * builder.setClientConfig(msalClientConfig);
73
+ * builder.setRequiresAuth(true);
74
+ * });
75
+ * ```
76
+ */
11
77
  export declare const configureMsal: (configure: AuthConfigFn) => {
12
78
  module: MsalModule;
13
79
  configure: AuthConfigFn;
@@ -1,5 +1,36 @@
1
+ /**
2
+ * Module identifier for the MSAL authentication module.
3
+ *
4
+ * This constant is used to register and identify the MSAL module within the Fusion Framework.
5
+ */
1
6
  export declare const ModuleName: "msal";
7
+ /**
8
+ * Enumeration of supported MSAL module versions.
9
+ *
10
+ * This enum defines the available MSAL versions and provides type-safe access to version identifiers.
11
+ * The `Latest` value is automatically set to the current module version at build time.
12
+ *
13
+ * @remarks
14
+ * - `V2`: MSAL v2 compatibility (legacy support)
15
+ * - `V4`: MSAL v4 (current major version)
16
+ * - `Latest`: Always points to the current module version (5.1.0)
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { MsalModuleVersion } from '@equinor/fusion-framework-module-msal';
21
+ *
22
+ * // Check version
23
+ * if (version === MsalModuleVersion.Latest) {
24
+ * console.log('Using latest MSAL version');
25
+ * }
26
+ *
27
+ * // Create version-specific proxy
28
+ * const proxy = provider.createProxyProvider(MsalModuleVersion.V2);
29
+ * ```
30
+ */
2
31
  export declare enum MsalModuleVersion {
32
+ /** MSAL v2 compatibility version */
3
33
  V2 = "v2",
4
- Latest = "5.1.2"
34
+ /** MSAL v4 (current major version) */
35
+ V4 = "v4"
5
36
  }
@@ -1,6 +1,14 @@
1
- import type { SemVer } from 'semver';
2
- import type { MsalModuleVersion } from './static';
3
- export interface IProxyProvider {
4
- version: string | SemVer;
5
- createProxyProvider<T>(version: MsalModuleVersion): T;
6
- }
1
+ /**
2
+ * Re-exports of core MSAL types from @azure/msal-browser.
3
+ *
4
+ * This module provides convenient access to commonly used MSAL types without
5
+ * requiring direct imports from @azure/msal-browser. These types represent
6
+ * fundamental authentication entities used throughout the MSAL module.
7
+ *
8
+ * @module
9
+ */
10
+ export {
11
+ /** Represents account information for an authenticated user */
12
+ AccountInfo,
13
+ /** Represents the result of an authentication operation including tokens and account */
14
+ AuthenticationResult, } from '@azure/msal-browser';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,68 @@
1
+ import type { AuthenticationResult, AccountInfo as AccountInfoBase, IPublicClientApplication } from '@azure/msal-browser';
2
+ export type IdTokenClaims = {
3
+ aud: string;
4
+ exp: number;
5
+ };
6
+ export type AccountInfo = AccountInfoBase & {
7
+ idTokenClaims?: IdTokenClaims;
8
+ };
9
+ export type AuthBehavior = 'popup' | 'redirect';
10
+ export type AuthRequest = {
11
+ scopes?: string[];
12
+ loginHint?: string;
13
+ };
14
+ /**
15
+ * Interface for MSAL v2 compatible authentication client.
16
+ *
17
+ * This interface defines the contract for authentication clients that maintain
18
+ * backward compatibility with MSAL v2 API while using MSAL v4 implementation
19
+ * under the hood. This is useful for gradual migration scenarios.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const client: IAuthClient_v2 = createProxyClient(baseClient);
24
+ *
25
+ * // Use v2 compatible API
26
+ * const account = client.account;
27
+ * const result = await client.login({ scopes: ['User.Read'] });
28
+ * ```
29
+ */
30
+ export interface IAuthClient extends IPublicClientApplication {
31
+ /**
32
+ * Tenant ID for the client domain
33
+ */
34
+ readonly tenantId: string;
35
+ /**
36
+ * Returns account for client tenant that MSAL currently has data for.
37
+ * (the account object is created at the time of successful login)
38
+ */
39
+ get account(): AccountInfo | undefined;
40
+ /**
41
+ * Check if the current account has valid claims
42
+ */
43
+ get hasValidClaims(): boolean;
44
+ /**
45
+ * Configured client ID
46
+ */
47
+ get clientId(): string | undefined;
48
+ /**
49
+ * Request origin from browser storage
50
+ */
51
+ get requestOrigin(): string | null;
52
+ /**
53
+ * Login user with optional silent authentication fallback
54
+ * @param options - Optional authentication request options
55
+ * @param behavior - Authentication method: 'popup' or 'redirect'
56
+ * @param silent - Whether to attempt silent authentication first
57
+ * @returns Promise resolving to authentication result or void
58
+ */
59
+ login(options?: AuthRequest, behavior?: AuthBehavior, silent?: boolean): Promise<AuthenticationResult | void>;
60
+ /**
61
+ * Acquire access token with optional silent authentication fallback
62
+ * @param options - Authentication request options
63
+ * @param behavior - Authentication method: 'popup' or 'redirect'
64
+ * @param silent - Whether to attempt silent authentication first
65
+ * @returns Promise resolving to authentication result or void
66
+ */
67
+ acquireToken(options?: AuthRequest, behavior?: AuthBehavior, silent?: boolean): Promise<AuthenticationResult | void>;
68
+ }
@@ -0,0 +1,68 @@
1
+ import type { AccountInfo, AuthenticationResult } from './types';
2
+ /**
3
+ * MSAL v2 compatible PublicClientApplication interface.
4
+ *
5
+ * This interface defines the contract for MSAL v2 PublicClientApplication
6
+ * to maintain backward compatibility while using MSAL v4 implementation.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const v4Client = new PublicClientApplication(config);
11
+ * const v2Client = createProxyClient_v2(v4Client);
12
+ *
13
+ * // Use v2-compatible methods
14
+ * const accounts = v2Client.getAllAccounts();
15
+ * const token = await v2Client.acquireTokenSilent({ scopes: ['User.Read'], account });
16
+ * ```
17
+ */
18
+ export interface IPublicClientApplication {
19
+ /**
20
+ * Get all cached accounts
21
+ * @returns Array of cached account information
22
+ */
23
+ getAllAccounts(): AccountInfo[];
24
+ /**
25
+ * Acquire token silently using cached credentials
26
+ * @param request - Token request parameters
27
+ * @returns Promise resolving to authentication result
28
+ */
29
+ acquireTokenSilent(request: {
30
+ scopes: string[];
31
+ account: AccountInfo;
32
+ }): Promise<AuthenticationResult>;
33
+ /**
34
+ * Login user via popup window
35
+ * @param request - Optional login request parameters
36
+ * @returns Promise resolving to authentication result
37
+ */
38
+ loginPopup(request?: {
39
+ scopes?: string[];
40
+ }): Promise<AuthenticationResult>;
41
+ /**
42
+ * Login user via redirect
43
+ * @param request - Optional login request parameters
44
+ * @returns Promise that resolves when redirect is initiated
45
+ */
46
+ loginRedirect(request?: {
47
+ scopes?: string[];
48
+ }): Promise<void>;
49
+ /**
50
+ * Logout user via redirect
51
+ * @param request - Optional logout request parameters
52
+ * @returns Promise that resolves when logout is complete
53
+ */
54
+ logoutRedirect(request?: {
55
+ postLogoutRedirectUri?: string;
56
+ account?: AccountInfo;
57
+ }): Promise<void>;
58
+ /**
59
+ * Handle authentication redirect after login/logout
60
+ * @returns Promise resolving to authentication result or null
61
+ */
62
+ handleRedirectPromise(): Promise<AuthenticationResult | null>;
63
+ /**
64
+ * Get the currently active account
65
+ * @returns Active account information or null
66
+ */
67
+ getActiveAccount(): AccountInfo | null;
68
+ }
@@ -0,0 +1,85 @@
1
+ import type { SemVer } from 'semver';
2
+ import type { MsalModuleVersion } from '../static';
3
+ import type { IPublicClientApplication } from './IPublicClientApplication.interface';
4
+ import type { AccountInfo, AuthenticationResult } from './types';
5
+ /**
6
+ * Interface for MSAL v2 compatible authentication provider.
7
+ *
8
+ * This interface defines the contract for authentication providers that maintain
9
+ * backward compatibility with MSAL v2 API while using MSAL v4 implementation
10
+ * under the hood. This is useful for gradual migration scenarios.
11
+ */
12
+ export interface IMsalProvider {
13
+ /** Current version of the provider (MSAL module version) */
14
+ version: string | SemVer;
15
+ /** Current MSAL module version */
16
+ msalVersion: MsalModuleVersion;
17
+ /**
18
+ * The MSAL PublicClientApplication instance (v2 compatible)
19
+ */
20
+ readonly client: IPublicClientApplication;
21
+ /**
22
+ * The current authenticated account (v2 compatibility)
23
+ * @deprecated Use activeAccount instead
24
+ */
25
+ readonly defaultAccount: AccountInfo | undefined;
26
+ /**
27
+ * The client configuration used to initialize this provider
28
+ * @deprecated Configuration should not be exposed
29
+ */
30
+ readonly defaultConfig: unknown | undefined;
31
+ /**
32
+ * The MSAL client instance (v2 compatibility)
33
+ * @deprecated Use client instead
34
+ */
35
+ readonly defaultClient: IPublicClientApplication;
36
+ /**
37
+ * Create a new MSAL client instance
38
+ * @deprecated This method is deprecated in MSAL v4
39
+ */
40
+ createClient(): IPublicClientApplication;
41
+ /**
42
+ * Acquire an access token for the specified scopes
43
+ * @param req - Auth request options (v2 compatible)
44
+ */
45
+ acquireAccessToken(req: {
46
+ scopes: string[];
47
+ account?: AccountInfo;
48
+ }): Promise<string | undefined>;
49
+ /**
50
+ * Acquire full authentication result
51
+ * @param req - Auth request options (v2 compatible)
52
+ */
53
+ acquireToken(req: {
54
+ scopes: string[];
55
+ account?: AccountInfo;
56
+ }): Promise<AuthenticationResult | undefined>;
57
+ /**
58
+ * Login user interactively
59
+ * @param options - Login options (v2 compatible)
60
+ */
61
+ login(options?: {
62
+ onlyIfRequired?: boolean;
63
+ }): Promise<void>;
64
+ /**
65
+ * Logout user
66
+ * @param options - Logout options (v2 compatible)
67
+ */
68
+ logout(options?: {
69
+ redirectUri?: string;
70
+ }): Promise<void>;
71
+ /**
72
+ * Handle authentication redirect
73
+ */
74
+ handleRedirect(): Promise<void | null>;
75
+ /**
76
+ * Create a proxy provider for version compatibility
77
+ * @param version - Version string
78
+ * @returns Proxy provider
79
+ */
80
+ createProxyProvider<T = IMsalProvider>(version: string): T;
81
+ /**
82
+ * Dispose of the provider and clean up resources
83
+ */
84
+ dispose(): void;
85
+ }
@@ -0,0 +1,22 @@
1
+ import type { IMsalClient } from '../MsalClient.interface';
2
+ import type { IAuthClient } from './IAuthClient.interface';
3
+ /**
4
+ * Creates a v2-compatible proxy for MSAL PublicClientApplication.
5
+ *
6
+ * This function creates a proxy that wraps the MSAL v4 PublicClientApplication
7
+ * and provides v2-compatible method signatures and return types.
8
+ *
9
+ * @param client - The MSAL v4 PublicClientApplication instance
10
+ * @returns A proxy client with v2-compatible interface
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const v4Client = new PublicClientApplication(config);
15
+ * const v2Client = createProxyClient_v2(v4Client);
16
+ *
17
+ * // Use v2-compatible methods
18
+ * const accounts = v2Client.getAllAccounts();
19
+ * const token = await v2Client.acquireTokenSilent({ scopes: ['User.Read'], account });
20
+ * ```
21
+ */
22
+ export declare function createProxyClient(client: IMsalClient): IAuthClient;