@equinor/fusion-framework-module-msal 5.1.1 → 6.0.0-next.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 +109 -0
- package/README.md +237 -40
- package/dist/esm/MsalClient.interface.js +2 -0
- package/dist/esm/MsalClient.interface.js.map +1 -0
- package/dist/esm/MsalClient.js +215 -0
- package/dist/esm/MsalClient.js.map +1 -0
- package/dist/esm/MsalConfigurator.js +248 -0
- package/dist/esm/MsalConfigurator.js.map +1 -0
- package/dist/esm/MsalProvider.interface.js +2 -0
- package/dist/esm/MsalProvider.interface.js.map +1 -0
- package/dist/esm/MsalProvider.js +525 -0
- package/dist/esm/MsalProvider.js.map +1 -0
- package/dist/esm/MsalProxyProvider.interface.js +2 -0
- package/dist/esm/MsalProxyProvider.interface.js.map +1 -0
- package/dist/esm/__tests__/versioning/resolve-version.test.js +29 -38
- package/dist/esm/__tests__/versioning/resolve-version.test.js.map +1 -1
- package/dist/esm/create-client-log-callback.js +87 -0
- package/dist/esm/create-client-log-callback.js.map +1 -0
- package/dist/esm/create-proxy-provider.js +84 -0
- package/dist/esm/create-proxy-provider.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/module.js +64 -16
- package/dist/esm/module.js.map +1 -1
- package/dist/esm/static.js +32 -2
- package/dist/esm/static.js.map +1 -1
- package/dist/esm/types.js +9 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/util/compare-origin.js +11 -0
- package/dist/esm/util/compare-origin.js.map +1 -0
- package/dist/esm/{v2/client/util/url.js → util/normalize-uri.js} +1 -10
- package/dist/esm/util/normalize-uri.js.map +1 -0
- package/dist/esm/{v2/client/util/browser.js → util/redirect.js} +1 -1
- package/dist/esm/util/redirect.js.map +1 -0
- package/dist/esm/v2/IAuthClient.interface.js +2 -0
- package/dist/esm/v2/IAuthClient.interface.js.map +1 -0
- package/dist/esm/v2/IPublicClientApplication.interface.js +2 -0
- package/dist/esm/v2/IPublicClientApplication.interface.js.map +1 -0
- package/dist/esm/v2/MsalProvider.interface.js +2 -0
- package/dist/esm/v2/MsalProvider.interface.js.map +1 -0
- package/dist/esm/v2/create-proxy-client.js +155 -0
- package/dist/esm/v2/create-proxy-client.js.map +1 -0
- package/dist/esm/v2/create-proxy-provider.js +140 -0
- package/dist/esm/v2/create-proxy-provider.js.map +1 -0
- package/dist/esm/v2/map-account-info.js +18 -0
- package/dist/esm/v2/map-account-info.js.map +1 -0
- package/dist/esm/v2/map-authentication-result.js +22 -0
- package/dist/esm/v2/map-authentication-result.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/esm/versioning/resolve-version.js +28 -16
- package/dist/esm/versioning/resolve-version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/MsalClient.d.ts +141 -0
- package/dist/types/MsalClient.interface.d.ts +103 -0
- package/dist/types/MsalConfigurator.d.ts +147 -0
- package/dist/types/MsalProvider.d.ts +291 -0
- package/dist/types/MsalProvider.interface.d.ts +159 -0
- package/dist/types/MsalProxyProvider.interface.d.ts +52 -0
- package/dist/types/create-client-log-callback.d.ts +38 -0
- package/dist/types/create-proxy-provider.d.ts +19 -0
- package/dist/types/index.d.ts +5 -4
- package/dist/types/module.d.ts +70 -4
- package/dist/types/static.d.ts +32 -1
- package/dist/types/types.d.ts +14 -6
- package/dist/types/util/redirect.d.ts +1 -0
- package/dist/types/v2/IAuthClient.interface.d.ts +68 -0
- package/dist/types/v2/IPublicClientApplication.interface.d.ts +68 -0
- package/dist/types/v2/MsalProvider.interface.d.ts +85 -0
- package/dist/types/v2/create-proxy-client.d.ts +22 -0
- package/dist/types/v2/create-proxy-provider.d.ts +24 -0
- package/dist/types/v2/map-account-info.d.ts +9 -0
- package/dist/types/v2/map-authentication-result.d.ts +9 -0
- package/dist/types/v2/types.d.ts +12 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/types/versioning/resolve-version.d.ts +1 -1
- package/package.json +11 -6
- package/src/MsalClient.interface.ts +121 -0
- package/src/MsalClient.ts +274 -0
- package/src/MsalConfigurator.ts +289 -0
- package/src/MsalProvider.interface.ts +175 -0
- package/src/MsalProvider.ts +597 -0
- package/src/MsalProxyProvider.interface.ts +71 -0
- package/src/__tests__/versioning/resolve-version.test.ts +29 -42
- package/src/create-client-log-callback.ts +101 -0
- package/src/create-proxy-provider.ts +89 -0
- package/src/index.ts +6 -7
- package/src/module.ts +88 -20
- package/src/static.ts +32 -3
- package/src/types.ts +15 -7
- package/src/util/compare-origin.ts +11 -0
- package/src/{v2/client/util/url.ts → util/normalize-uri.ts} +0 -10
- package/src/v2/IAuthClient.interface.ts +91 -0
- package/src/v2/IPublicClientApplication.interface.ts +71 -0
- package/src/v2/MsalProvider.interface.ts +92 -0
- package/src/v2/create-proxy-client.ts +186 -0
- package/src/v2/create-proxy-provider.ts +156 -0
- package/src/v2/map-account-info.ts +20 -0
- package/src/v2/map-authentication-result.ts +24 -0
- package/src/v2/types.ts +12 -0
- package/src/version.ts +1 -1
- package/src/versioning/resolve-version.ts +35 -28
- package/tsconfig.json +3 -0
- package/dist/esm/v2/client/behavior.js +0 -5
- package/dist/esm/v2/client/behavior.js.map +0 -1
- package/dist/esm/v2/client/client.js +0 -142
- package/dist/esm/v2/client/client.js.map +0 -1
- package/dist/esm/v2/client/create-auth-client.js +0 -36
- package/dist/esm/v2/client/create-auth-client.js.map +0 -1
- package/dist/esm/v2/client/index.js +0 -5
- package/dist/esm/v2/client/index.js.map +0 -1
- package/dist/esm/v2/client/log/console.js +0 -45
- package/dist/esm/v2/client/log/console.js.map +0 -1
- package/dist/esm/v2/client/request.js +0 -2
- package/dist/esm/v2/client/request.js.map +0 -1
- package/dist/esm/v2/client/util/browser.js.map +0 -1
- package/dist/esm/v2/client/util/url.js.map +0 -1
- package/dist/esm/v2/configurator.js +0 -42
- package/dist/esm/v2/configurator.js.map +0 -1
- package/dist/esm/v2/index.js +0 -3
- package/dist/esm/v2/index.js.map +0 -1
- package/dist/esm/v2/provider.js +0 -115
- package/dist/esm/v2/provider.js.map +0 -1
- package/dist/types/v2/client/behavior.d.ts +0 -13
- package/dist/types/v2/client/client.d.ts +0 -89
- package/dist/types/v2/client/create-auth-client.d.ts +0 -27
- package/dist/types/v2/client/index.d.ts +0 -5
- package/dist/types/v2/client/log/console.d.ts +0 -28
- package/dist/types/v2/client/request.d.ts +0 -65
- package/dist/types/v2/configurator.d.ts +0 -32
- package/dist/types/v2/index.d.ts +0 -2
- package/dist/types/v2/provider.d.ts +0 -59
- package/src/v2/client/behavior.ts +0 -14
- package/src/v2/client/client.ts +0 -180
- package/src/v2/client/create-auth-client.ts +0 -48
- package/src/v2/client/index.ts +0 -8
- package/src/v2/client/log/console.ts +0 -58
- package/src/v2/client/request.ts +0 -66
- package/src/v2/configurator.ts +0 -58
- package/src/v2/index.ts +0 -2
- package/src/v2/provider.ts +0 -178
- /package/dist/types/{v2/client/util/browser.d.ts → util/compare-origin.d.ts} +0 -0
- /package/dist/types/{v2/client/util/url.d.ts → util/normalize-uri.d.ts} +0 -0
- /package/src/{v2/client/util/browser.ts → util/redirect.ts} +0 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import { BaseConfigBuilder } from '@equinor/fusion-framework-module';
|
|
3
|
+
import { MsalModuleVersion } from './static';
|
|
4
|
+
import semver from 'semver';
|
|
5
|
+
import type { IMsalProvider } from './MsalProvider.interface';
|
|
6
|
+
import {
|
|
7
|
+
TelemetryLevel,
|
|
8
|
+
type ITelemetryProvider,
|
|
9
|
+
} from '@equinor/fusion-framework-module-telemetry';
|
|
10
|
+
import { MsalClient, type MsalClientConfig, type IMsalClient } from './MsalClient';
|
|
11
|
+
import { createClientLogCallback } from './create-client-log-callback';
|
|
12
|
+
import { LogLevel } from '@azure/msal-browser';
|
|
13
|
+
import { version } from './version';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Zod schema for telemetry configuration validation.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
const TelemetryConfigSchema = z.object({
|
|
21
|
+
provider: z.custom<ITelemetryProvider>().optional(),
|
|
22
|
+
metadata: z.record(z.string(), z.unknown()).optional().default({
|
|
23
|
+
module: 'msal',
|
|
24
|
+
version,
|
|
25
|
+
}),
|
|
26
|
+
scope: z.array(z.string()).optional().default(['framework', 'authentication']),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Telemetry configuration for MSAL module.
|
|
31
|
+
*
|
|
32
|
+
* This configuration controls how authentication events are tracked and logged
|
|
33
|
+
* through the framework's telemetry system.
|
|
34
|
+
*/
|
|
35
|
+
export type TelemetryConfig = z.infer<typeof TelemetryConfigSchema>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Zod schema for MSAL module configuration validation.
|
|
39
|
+
*
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
const MsalConfigSchema = z.object({
|
|
43
|
+
client: z.custom<IMsalClient>(),
|
|
44
|
+
provider: z.custom<IMsalProvider>().optional(),
|
|
45
|
+
requiresAuth: z.boolean().optional(),
|
|
46
|
+
redirectUri: z.string().optional(),
|
|
47
|
+
version: z.string().transform((x: string) => String(semver.coerce(x))),
|
|
48
|
+
telemetry: TelemetryConfigSchema,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Complete configuration object for MSAL authentication module.
|
|
53
|
+
*
|
|
54
|
+
* This type represents the full configuration including client setup, authentication
|
|
55
|
+
* requirements, telemetry, and version information.
|
|
56
|
+
*/
|
|
57
|
+
export type MsalConfig = z.infer<typeof MsalConfigSchema>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Configuration builder for MSAL v4 authentication module.
|
|
61
|
+
*
|
|
62
|
+
* This configurator provides a fluent API for setting up Microsoft Authentication Library
|
|
63
|
+
* configuration with support for MSAL v4 features and breaking changes.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const configurator = new MsalConfigurator();
|
|
68
|
+
* configurator.setClient(new AuthClient('your-tenant-id', 'your-client-id'));
|
|
69
|
+
* configurator.setRequiresAuth(true);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export class MsalConfigurator extends BaseConfigBuilder<MsalConfig> {
|
|
73
|
+
#msalConfig?: MsalClientConfig;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The MSAL module version being configured.
|
|
77
|
+
*
|
|
78
|
+
* @default Latest
|
|
79
|
+
*/
|
|
80
|
+
public get version(): string {
|
|
81
|
+
return version;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Creates a new MSAL configurator instance.
|
|
86
|
+
*
|
|
87
|
+
* Sets up default configuration including version and telemetry provider integration.
|
|
88
|
+
*/
|
|
89
|
+
constructor() {
|
|
90
|
+
super();
|
|
91
|
+
// Set default version
|
|
92
|
+
this._set('version', async () => this.version);
|
|
93
|
+
// Auto-detect and integrate telemetry module if available
|
|
94
|
+
this._set('telemetry.provider', async (args) => {
|
|
95
|
+
if (args.hasModule('telemetry')) {
|
|
96
|
+
const telemetry = await args.requireInstance('telemetry');
|
|
97
|
+
return telemetry;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Sets the MSAL client configuration for authentication.
|
|
104
|
+
*
|
|
105
|
+
* This method stores the configuration which will be used to create an MSAL client
|
|
106
|
+
* instance during module initialization. The client will be auto-created if not provided
|
|
107
|
+
* via `setClient`.
|
|
108
|
+
*
|
|
109
|
+
* @param config - Client configuration object with MSAL settings (client ID, tenant ID, etc.)
|
|
110
|
+
* @returns The configurator instance for method chaining
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* configurator.setClientConfig({
|
|
115
|
+
* auth: {
|
|
116
|
+
* clientId: 'your-client-id',
|
|
117
|
+
* tenantId: 'your-tenant-id'
|
|
118
|
+
* }
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
setClientConfig(config?: MsalClientConfig): this {
|
|
123
|
+
this.#msalConfig = config;
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Sets whether authentication is required for the application.
|
|
129
|
+
*
|
|
130
|
+
* When set to true, the application will attempt automatic login during initialization
|
|
131
|
+
* if no valid authentication session exists. When false, authentication is optional
|
|
132
|
+
* and must be triggered manually.
|
|
133
|
+
*
|
|
134
|
+
* @param requiresAuth - Whether authentication is mandatory for the application
|
|
135
|
+
* @returns The configurator instance for method chaining
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* // Require authentication on app load
|
|
140
|
+
* configurator.setRequiresAuth(true);
|
|
141
|
+
*
|
|
142
|
+
* // Make authentication optional
|
|
143
|
+
* configurator.setRequiresAuth(false);
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
setRequiresAuth(requiresAuth: boolean): this {
|
|
147
|
+
this._set('requiresAuth', async () => requiresAuth);
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @deprecated - since version 5.1.0, use setClient instead
|
|
153
|
+
*/
|
|
154
|
+
setProvider(provider?: IMsalProvider): this {
|
|
155
|
+
this._set('provider', async () => provider);
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Sets a pre-configured MSAL client instance.
|
|
161
|
+
*
|
|
162
|
+
* This method allows you to provide an already-instantiated MSAL client rather than
|
|
163
|
+
* letting the configurator create one from configuration. Useful when you need
|
|
164
|
+
* custom client configuration outside the standard configurator options.
|
|
165
|
+
*
|
|
166
|
+
* @param client - Pre-configured MSAL client instance
|
|
167
|
+
* @returns The configurator instance for method chaining
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const customClient = new MsalClient(customConfig);
|
|
172
|
+
* configurator.setClient(customClient);
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
setClient(client: IMsalClient): this {
|
|
176
|
+
this._set('client', async () => client);
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Sets telemetry provider for MSAL authentication events.
|
|
182
|
+
*
|
|
183
|
+
* This allows MSAL authentication events to be tracked through the framework's
|
|
184
|
+
* telemetry system. If not provided, telemetry module will be auto-detected if
|
|
185
|
+
* available in the framework configuration.
|
|
186
|
+
*
|
|
187
|
+
* @param telemetry - Telemetry provider instance or undefined to disable telemetry
|
|
188
|
+
* @returns The configurator instance for method chaining
|
|
189
|
+
*/
|
|
190
|
+
setTelemetry(telemetry: ITelemetryProvider | undefined): this {
|
|
191
|
+
this._set('telemetry.provider', async () => telemetry);
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Sets optional metadata to be included on all MSAL telemetry events.
|
|
197
|
+
* @deprecated Use setTelemetry({ metadata }) instead
|
|
198
|
+
*/
|
|
199
|
+
setTelemetryMetadata(metadata: Record<string, unknown> | undefined): this {
|
|
200
|
+
this._set('telemetry.metadata', async () => metadata);
|
|
201
|
+
return this;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Sets the telemetry scope for MSAL authentication events.
|
|
206
|
+
*
|
|
207
|
+
* The scope is used to categorize and filter telemetry events in the telemetry system.
|
|
208
|
+
* Default scope is ['framework', 'authentication'].
|
|
209
|
+
*
|
|
210
|
+
* @param scope - Array of scope identifiers for telemetry categorization
|
|
211
|
+
* @returns The configurator instance for method chaining
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* configurator.setTelemetryScope(['custom', 'auth', 'msal']);
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
setTelemetryScope(scope: string[]): this {
|
|
219
|
+
this._set('telemetry.scope', async () => scope);
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Processes and validates the configuration.
|
|
225
|
+
*
|
|
226
|
+
* @param config - Raw configuration object
|
|
227
|
+
* @returns Processed and validated configuration
|
|
228
|
+
*/
|
|
229
|
+
async _processConfig(rawConfig: MsalConfig): Promise<MsalConfig> {
|
|
230
|
+
// Validate and coerce configuration using Zod schema
|
|
231
|
+
const config = await MsalConfigSchema.parseAsync(rawConfig);
|
|
232
|
+
|
|
233
|
+
// Auto-create client if config provided but no client instance
|
|
234
|
+
// This allows users to provide configuration without manually instantiating the client
|
|
235
|
+
if (!config.client && !!this.#msalConfig) {
|
|
236
|
+
const clientConfig = this.#msalConfig;
|
|
237
|
+
|
|
238
|
+
config.telemetry.provider?.trackEvent({
|
|
239
|
+
name: 'module-msal.configurator._processConfig.creating-client',
|
|
240
|
+
level: TelemetryLevel.Debug,
|
|
241
|
+
scope: config.telemetry.scope,
|
|
242
|
+
metadata: { ...config.telemetry.metadata, clientConfig },
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// Auto-generate authority URL from tenant ID if not explicitly provided
|
|
246
|
+
// This simplifies configuration for most common cases
|
|
247
|
+
if (!clientConfig.auth.authority && clientConfig.auth.tenantId) {
|
|
248
|
+
clientConfig.auth.authority = `https://login.microsoftonline.com/${clientConfig.auth.tenantId}`;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Set default cache location to localStorage for browser environments
|
|
252
|
+
// MSAL supports sessionStorage as well, but localStorage is the standard for persistent auth
|
|
253
|
+
if (!clientConfig.cache) {
|
|
254
|
+
clientConfig.cache = { cacheLocation: 'localStorage' };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Integrate framework telemetry with MSAL logging system
|
|
258
|
+
// This allows MSAL events to flow through the framework's telemetry pipeline
|
|
259
|
+
if (!clientConfig.system?.loggerOptions && config.telemetry?.provider) {
|
|
260
|
+
const { provider, metadata, scope } = config.telemetry;
|
|
261
|
+
|
|
262
|
+
provider.trackEvent({
|
|
263
|
+
name: 'module-msal.configurator._processConfig.client-telemetry-connected',
|
|
264
|
+
level: TelemetryLevel.Debug,
|
|
265
|
+
scope,
|
|
266
|
+
metadata,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
clientConfig.system = {
|
|
270
|
+
...clientConfig.system,
|
|
271
|
+
loggerOptions: {
|
|
272
|
+
// Only log PII in development to protect user privacy in production
|
|
273
|
+
piiLoggingEnabled: process.env.NODE_ENV === 'development',
|
|
274
|
+
// Bridge MSAL log events to framework telemetry system
|
|
275
|
+
loggerCallback: createClientLogCallback(provider, metadata, [...scope, '3rd-party']),
|
|
276
|
+
// Use Warning level by default - captures errors and warnings without being verbose
|
|
277
|
+
logLevel: LogLevel.Warning,
|
|
278
|
+
// Preserve any user-provided logger options (allows customization)
|
|
279
|
+
...clientConfig.system?.loggerOptions,
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
// Instantiate MSAL client with fully configured options
|
|
284
|
+
config.client = new MsalClient(clientConfig);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return config;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AcquireTokenOptions,
|
|
3
|
+
AcquireTokenResult,
|
|
4
|
+
IMsalClient,
|
|
5
|
+
LoginOptions,
|
|
6
|
+
LoginResult,
|
|
7
|
+
LogoutOptions,
|
|
8
|
+
} from './MsalClient.interface';
|
|
9
|
+
|
|
10
|
+
import type { IProxyProvider } from './MsalProxyProvider.interface';
|
|
11
|
+
|
|
12
|
+
import type { AccountInfo, AuthenticationResult } from './types';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Legacy token acquisition options maintaining backward compatibility.
|
|
16
|
+
*
|
|
17
|
+
* This type extends `AcquireTokenOptions` with an optional `scopes` property
|
|
18
|
+
* to support legacy API calls that passed scopes directly rather than in the request object.
|
|
19
|
+
*
|
|
20
|
+
* @property scopes - Optional array of OAuth scopes (deprecated, use request.scopes)
|
|
21
|
+
*
|
|
22
|
+
* @deprecated Use the modern format with scopes in the request object instead
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* // Deprecated legacy format
|
|
26
|
+
* acquireToken({ scopes: ['User.Read'] })
|
|
27
|
+
*
|
|
28
|
+
* // Modern format (preferred)
|
|
29
|
+
* acquireToken({ request: { scopes: ['User.Read'] } })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export type AcquireTokenOptionsLegacy = AcquireTokenOptions & { scopes?: string[] };
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Interface for MSAL v4 authentication provider.
|
|
36
|
+
*
|
|
37
|
+
* This interface defines the contract for authentication providers that work
|
|
38
|
+
* with Microsoft Authentication Library v4, providing a unified API for
|
|
39
|
+
* token acquisition, user authentication, and account management.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const provider: IMsalProvider = new MsalProvider(config);
|
|
44
|
+
*
|
|
45
|
+
* // Login user (v4 format)
|
|
46
|
+
* await provider.login({ request: { scopes: ['User.Read'] } });
|
|
47
|
+
*
|
|
48
|
+
* // Acquire token (v4 format - recommended)
|
|
49
|
+
* const token = await provider.acquireAccessToken({
|
|
50
|
+
* request: { scopes: ['https://graph.microsoft.com/.default'] }
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export interface IMsalProvider extends IProxyProvider {
|
|
55
|
+
/**
|
|
56
|
+
* The MSAL PublicClientApplication client instance.
|
|
57
|
+
*
|
|
58
|
+
* Provides access to the underlying MSAL client for advanced use cases.
|
|
59
|
+
* Use provider methods for standard authentication operations.
|
|
60
|
+
*/
|
|
61
|
+
readonly client: IMsalClient;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The currently authenticated account information.
|
|
65
|
+
*
|
|
66
|
+
* Returns the active account if available, or null if no user is authenticated.
|
|
67
|
+
*/
|
|
68
|
+
readonly account: AccountInfo | null;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Initializes the MSAL provider and handles authentication state.
|
|
72
|
+
*
|
|
73
|
+
* This method must be called before using other provider methods. It:
|
|
74
|
+
* - Initializes the MSAL client
|
|
75
|
+
* - Processes any pending authentication redirects
|
|
76
|
+
* - Attempts automatic login if requiresAuth is enabled
|
|
77
|
+
*
|
|
78
|
+
* @returns Promise that resolves when initialization is complete
|
|
79
|
+
*/
|
|
80
|
+
initialize(): Promise<void>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Acquires an access token string for the specified scopes.
|
|
84
|
+
*
|
|
85
|
+
* This is a convenience method that returns only the access token string,
|
|
86
|
+
* unlike `acquireToken` which returns the full authentication result.
|
|
87
|
+
*
|
|
88
|
+
* @param options - Token acquisition options including scopes
|
|
89
|
+
* @returns Promise resolving to the access token string, or undefined if acquisition fails
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const token = await provider.acquireAccessToken({
|
|
94
|
+
* request: { scopes: ['User.Read'] }
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
acquireAccessToken(options: AcquireTokenOptionsLegacy): Promise<string | undefined>;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Acquires a full authentication result including token and account information.
|
|
102
|
+
*
|
|
103
|
+
* This method attempts silent token acquisition first, then falls back to interactive
|
|
104
|
+
* authentication based on the configured behavior (popup or redirect).
|
|
105
|
+
*
|
|
106
|
+
* @param options - Token acquisition options including scopes
|
|
107
|
+
* @returns Promise resolving to full authentication result or null/undefined on failure
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const result = await provider.acquireToken({
|
|
112
|
+
* request: { scopes: ['User.Read'] },
|
|
113
|
+
* behavior: 'popup'
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
acquireToken(options: AcquireTokenOptionsLegacy): Promise<AcquireTokenResult>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Authenticates a user interactively with Microsoft Identity Platform.
|
|
121
|
+
*
|
|
122
|
+
* This method implements a sophisticated flow that attempts silent authentication
|
|
123
|
+
* first (if configured) and falls back to interactive authentication based on behavior.
|
|
124
|
+
*
|
|
125
|
+
* @param options - Login configuration options including request, behavior, and silent flag
|
|
126
|
+
* @returns Promise resolving to authentication result or undefined for redirect flows
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* // Basic login with default settings
|
|
131
|
+
* await provider.login({ request: { scopes: ['User.Read'] } });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
login(options: LoginOptions): Promise<LoginResult>;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Logs out the current user and clears authentication state.
|
|
138
|
+
*
|
|
139
|
+
* Initiates a logout flow that clears local tokens and navigates to Microsoft's
|
|
140
|
+
* logout endpoint. Always uses redirect flow for reliability.
|
|
141
|
+
*
|
|
142
|
+
* @param options - Optional logout configuration
|
|
143
|
+
* @returns Promise resolving to true on success, false on failure
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* // Basic logout
|
|
148
|
+
* await provider.logout();
|
|
149
|
+
*
|
|
150
|
+
* // Logout with redirect
|
|
151
|
+
* await provider.logout({ redirectUri: 'https://app.com/logout' });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
logout(options?: LogoutOptions): Promise<boolean>;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Processes any pending authentication redirect after browser navigation.
|
|
158
|
+
*
|
|
159
|
+
* This method must be called on app initialization to handle authentication
|
|
160
|
+
* results from redirect-based flows. It processes tokens and account information
|
|
161
|
+
* returned by Microsoft's identity provider.
|
|
162
|
+
*
|
|
163
|
+
* @returns Promise resolving to authentication result or null if no redirect pending
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* // Call on app startup
|
|
168
|
+
* const result = await provider.handleRedirect();
|
|
169
|
+
* if (result?.account) {
|
|
170
|
+
* // User successfully authenticated via redirect
|
|
171
|
+
* }
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
handleRedirect(): Promise<AuthenticationResult | null>;
|
|
175
|
+
}
|