@azure/msal-angular 4.0.20 → 5.0.0-alpha.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.
Files changed (37) hide show
  1. package/IMsalService.d.ts +16 -17
  2. package/README.md +3 -1
  3. package/constants.d.ts +9 -5
  4. package/{fesm2020 → fesm2022}/azure-msal-angular.mjs +740 -734
  5. package/fesm2022/azure-msal-angular.mjs.map +1 -0
  6. package/index.d.ts +5 -5
  7. package/msal.broadcast.config.d.ts +3 -3
  8. package/msal.broadcast.service.d.ts +19 -19
  9. package/msal.guard.config.d.ts +9 -9
  10. package/msal.guard.d.ts +43 -43
  11. package/msal.interceptor.config.d.ts +13 -13
  12. package/msal.interceptor.d.ts +70 -70
  13. package/msal.module.d.ts +13 -13
  14. package/msal.navigation.client.d.ts +19 -19
  15. package/msal.redirect.component.d.ts +15 -15
  16. package/msal.service.d.ts +32 -33
  17. package/package.json +5 -15
  18. package/packageMetadata.d.ts +2 -2
  19. package/public-api.d.ts +17 -17
  20. package/esm2020/IMsalService.mjs +0 -6
  21. package/esm2020/azure-msal-angular.mjs +0 -5
  22. package/esm2020/constants.mjs +0 -10
  23. package/esm2020/msal.broadcast.config.mjs +0 -6
  24. package/esm2020/msal.broadcast.service.mjs +0 -66
  25. package/esm2020/msal.guard.config.mjs +0 -6
  26. package/esm2020/msal.guard.mjs +0 -218
  27. package/esm2020/msal.interceptor.config.mjs +0 -6
  28. package/esm2020/msal.interceptor.mjs +0 -270
  29. package/esm2020/msal.module.mjs +0 -46
  30. package/esm2020/msal.navigation.client.mjs +0 -53
  31. package/esm2020/msal.redirect.component.mjs +0 -31
  32. package/esm2020/msal.service.mjs +0 -88
  33. package/esm2020/packageMetadata.mjs +0 -4
  34. package/esm2020/public-api.mjs +0 -18
  35. package/fesm2015/azure-msal-angular.mjs +0 -762
  36. package/fesm2015/azure-msal-angular.mjs.map +0 -1
  37. package/fesm2020/azure-msal-angular.mjs.map +0 -1
@@ -1,762 +0,0 @@
1
- import * as i0 from '@angular/core';
2
- import { InjectionToken, Injectable, Inject, Optional, Component, NgModule } from '@angular/core';
3
- import { InteractionStatus, EventMessageUtils, WrapperSKU, InteractionType, BrowserConfigurationAuthError, UrlString, BrowserUtils, StringUtils, NavigationClient } from '@azure/msal-browser';
4
- import { ReplaySubject, Subject, BehaviorSubject, from, of, EMPTY } from 'rxjs';
5
- import * as i3 from '@angular/common';
6
- import { DOCUMENT, CommonModule } from '@angular/common';
7
- import { map, concatMap, catchError, switchMap, take, filter } from 'rxjs/operators';
8
- import * as i4 from '@angular/router';
9
- import { __awaiter } from 'tslib';
10
-
11
- /* eslint-disable header/header */
12
- const name = "@azure/msal-angular";
13
- const version = "4.0.20";
14
-
15
- /*
16
- * Copyright (c) Microsoft Corporation. All rights reserved.
17
- * Licensed under the MIT License.
18
- */
19
- const MSAL_INSTANCE = new InjectionToken("MSAL_INSTANCE");
20
- const MSAL_GUARD_CONFIG = new InjectionToken("MSAL_GUARD_CONFIG");
21
- const MSAL_INTERCEPTOR_CONFIG = new InjectionToken("MSAL_INTERCEPTOR_CONFIG");
22
- const MSAL_BROADCAST_CONFIG = new InjectionToken("MSAL_BROADCAST_CONFIG");
23
-
24
- /*
25
- * Copyright (c) Microsoft Corporation. All rights reserved.
26
- * Licensed under the MIT License.
27
- */
28
- class MsalBroadcastService {
29
- constructor(msalInstance, msalBroadcastConfig) {
30
- this.msalInstance = msalInstance;
31
- this.msalBroadcastConfig = msalBroadcastConfig;
32
- // Make _msalSubject a ReplaySubject if configured to replay past events
33
- if (this.msalBroadcastConfig &&
34
- this.msalBroadcastConfig.eventsToReplay > 0) {
35
- this.msalInstance
36
- .getLogger()
37
- .clone(name, version)
38
- .verbose(`BroadcastService - eventsToReplay set on BroadcastConfig, replaying the last ${this.msalBroadcastConfig.eventsToReplay} events`);
39
- this._msalSubject = new ReplaySubject(this.msalBroadcastConfig.eventsToReplay);
40
- }
41
- else {
42
- // Defaults to _msalSubject being a Subject
43
- this._msalSubject = new Subject();
44
- }
45
- this.msalSubject$ = this._msalSubject.asObservable();
46
- // InProgress as BehaviorSubject so most recent inProgress state will be available upon subscription
47
- this._inProgress = new BehaviorSubject(InteractionStatus.Startup);
48
- this.inProgress$ = this._inProgress.asObservable();
49
- this.msalInstance.addEventCallback((message) => {
50
- this._msalSubject.next(message);
51
- const status = EventMessageUtils.getInteractionStatusFromEvent(message, this._inProgress.value);
52
- if (status !== null) {
53
- this.msalInstance
54
- .getLogger()
55
- .clone(name, version)
56
- .verbose(`BroadcastService - ${message.eventType} results in setting inProgress from ${this._inProgress.value} to ${status}`);
57
- this._inProgress.next(status);
58
- }
59
- });
60
- }
61
- /**
62
- * Resets inProgress state to None
63
- */
64
- resetInProgressEvent() {
65
- if (this._inProgress.value === InteractionStatus.Startup) {
66
- this._inProgress.next(InteractionStatus.None);
67
- }
68
- }
69
- }
70
- MsalBroadcastService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalBroadcastService, deps: [{ token: MSAL_INSTANCE }, { token: MSAL_BROADCAST_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
71
- MsalBroadcastService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalBroadcastService });
72
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalBroadcastService, decorators: [{
73
- type: Injectable
74
- }], ctorParameters: function () {
75
- return [{ type: undefined, decorators: [{
76
- type: Inject,
77
- args: [MSAL_INSTANCE]
78
- }] }, { type: undefined, decorators: [{
79
- type: Optional
80
- }, {
81
- type: Inject,
82
- args: [MSAL_BROADCAST_CONFIG]
83
- }] }];
84
- } });
85
-
86
- /*
87
- * Copyright (c) Microsoft Corporation. All rights reserved.
88
- * Licensed under the MIT License.
89
- */
90
- class MsalService {
91
- constructor(instance, location, injector) {
92
- this.instance = instance;
93
- this.location = location;
94
- this.injector = injector;
95
- const hash = this.location.path(true).split("#").pop();
96
- if (hash) {
97
- this.redirectHash = `#${hash}`;
98
- }
99
- this.instance.initializeWrapperLibrary(WrapperSKU.Angular, version);
100
- }
101
- initialize() {
102
- return from(this.instance.initialize());
103
- }
104
- acquireTokenPopup(request) {
105
- return from(this.instance.acquireTokenPopup(request));
106
- }
107
- acquireTokenRedirect(request) {
108
- return from(this.instance.acquireTokenRedirect(request));
109
- }
110
- acquireTokenSilent(silentRequest) {
111
- return from(this.instance.acquireTokenSilent(silentRequest));
112
- }
113
- handleRedirectObservable(hash) {
114
- return from(this.instance
115
- .initialize()
116
- .then(() => this.instance.handleRedirectPromise(hash || this.redirectHash))
117
- .finally(() => {
118
- // update inProgress state to none
119
- this.injector.get(MsalBroadcastService).resetInProgressEvent();
120
- }));
121
- }
122
- loginPopup(request) {
123
- return from(this.instance.loginPopup(request));
124
- }
125
- loginRedirect(request) {
126
- return from(this.instance.loginRedirect(request));
127
- }
128
- // @deprecated: Use logoutRedirect or logoutPopup
129
- logout(logoutRequest) {
130
- return from(this.instance.logout(logoutRequest));
131
- }
132
- logoutRedirect(logoutRequest) {
133
- return from(this.instance.logoutRedirect(logoutRequest));
134
- }
135
- logoutPopup(logoutRequest) {
136
- return from(this.instance.logoutPopup(logoutRequest));
137
- }
138
- ssoSilent(request) {
139
- return from(this.instance.ssoSilent(request));
140
- }
141
- /**
142
- * Gets logger for msal-angular.
143
- * If no logger set, returns logger instance created with same options as msal-browser
144
- */
145
- getLogger() {
146
- if (!this.logger) {
147
- this.logger = this.instance.getLogger().clone(name, version);
148
- }
149
- return this.logger;
150
- }
151
- // Create a logger instance for msal-angular with the same options as msal-browser
152
- setLogger(logger) {
153
- this.logger = logger.clone(name, version);
154
- this.instance.setLogger(logger);
155
- }
156
- }
157
- MsalService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalService, deps: [{ token: MSAL_INSTANCE }, { token: i3.Location }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
158
- MsalService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalService });
159
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalService, decorators: [{
160
- type: Injectable
161
- }], ctorParameters: function () {
162
- return [{ type: undefined, decorators: [{
163
- type: Inject,
164
- args: [MSAL_INSTANCE]
165
- }] }, { type: i3.Location }, { type: i0.Injector }];
166
- } });
167
-
168
- /*
169
- * Copyright (c) Microsoft Corporation. All rights reserved.
170
- * Licensed under the MIT License.
171
- */
172
- class MsalGuard {
173
- constructor(msalGuardConfig, msalBroadcastService, authService, location, router) {
174
- this.msalGuardConfig = msalGuardConfig;
175
- this.msalBroadcastService = msalBroadcastService;
176
- this.authService = authService;
177
- this.location = location;
178
- this.router = router;
179
- // Subscribing so events in MsalGuard will set inProgress$ observable
180
- this.msalBroadcastService.inProgress$.subscribe();
181
- }
182
- /**
183
- * Parses url string to UrlTree
184
- * @param url
185
- */
186
- parseUrl(url) {
187
- return this.router.parseUrl(url);
188
- }
189
- /**
190
- * Builds the absolute url for the destination page
191
- * @param path Relative path of requested page
192
- * @returns Full destination url
193
- */
194
- getDestinationUrl(path) {
195
- this.authService.getLogger().verbose("Guard - getting destination url");
196
- // Absolute base url for the application (default to origin if base element not present)
197
- const baseElements = document.getElementsByTagName("base");
198
- const baseUrl = this.location.normalize(baseElements.length ? baseElements[0].href : window.location.origin);
199
- // Path of page (including hash, if using hash routing)
200
- const pathUrl = this.location.prepareExternalUrl(path);
201
- // Hash location strategy
202
- if (pathUrl.startsWith("#")) {
203
- this.authService
204
- .getLogger()
205
- .verbose("Guard - destination by hash routing");
206
- return `${baseUrl}/${pathUrl}`;
207
- }
208
- /*
209
- * If using path location strategy, pathUrl will include the relative portion of the base path (e.g. /base/page).
210
- * Since baseUrl also includes /base, can just concatentate baseUrl + path
211
- */
212
- return `${baseUrl}${path}`;
213
- }
214
- /**
215
- * Interactively prompt the user to login
216
- * @param url Path of the requested page
217
- */
218
- loginInteractively(state) {
219
- const authRequest = typeof this.msalGuardConfig.authRequest === "function"
220
- ? this.msalGuardConfig.authRequest(this.authService, state)
221
- : Object.assign({}, this.msalGuardConfig.authRequest);
222
- if (this.msalGuardConfig.interactionType === InteractionType.Popup) {
223
- this.authService.getLogger().verbose("Guard - logging in by popup");
224
- return this.authService.loginPopup(authRequest).pipe(map((response) => {
225
- this.authService
226
- .getLogger()
227
- .verbose("Guard - login by popup successful, can activate, setting active account");
228
- this.authService.instance.setActiveAccount(response.account);
229
- return true;
230
- }));
231
- }
232
- this.authService.getLogger().verbose("Guard - logging in by redirect");
233
- const redirectStartPage = this.getDestinationUrl(state.url);
234
- return this.authService
235
- .loginRedirect(Object.assign({ redirectStartPage }, authRequest))
236
- .pipe(map(() => false));
237
- }
238
- /**
239
- * Helper which checks for the correct interaction type, prevents page with Guard to be set as redirect, and calls handleRedirectObservable
240
- * @param state
241
- */
242
- activateHelper(state) {
243
- if (this.msalGuardConfig.interactionType !== InteractionType.Popup &&
244
- this.msalGuardConfig.interactionType !== InteractionType.Redirect) {
245
- throw new BrowserConfigurationAuthError("invalid_interaction_type", "Invalid interaction type provided to MSAL Guard. InteractionType.Popup or InteractionType.Redirect must be provided in the MsalGuardConfiguration");
246
- }
247
- this.authService.getLogger().verbose("MSAL Guard activated");
248
- /*
249
- * If a page with MSAL Guard is set as the redirect for acquireTokenSilent,
250
- * short-circuit to prevent redirecting or popups.
251
- */
252
- if (typeof window !== "undefined") {
253
- if (UrlString.hashContainsKnownProperties(window.location.hash) &&
254
- BrowserUtils.isInIframe() &&
255
- !this.authService.instance.getConfiguration().system
256
- .allowRedirectInIframe) {
257
- this.authService
258
- .getLogger()
259
- .warning("Guard - redirectUri set to page with MSAL Guard. It is recommended to not set redirectUri to a page that requires authentication.");
260
- return of(false);
261
- }
262
- }
263
- else {
264
- this.authService
265
- .getLogger()
266
- .info("Guard - window is undefined, MSAL does not support server-side token acquisition");
267
- return of(true);
268
- }
269
- /**
270
- * If a loginFailedRoute is set in the config, set this as the loginFailedRoute
271
- */
272
- if (this.msalGuardConfig.loginFailedRoute) {
273
- this.loginFailedRoute = this.parseUrl(this.msalGuardConfig.loginFailedRoute);
274
- }
275
- // Capture current path before it gets changed by handleRedirectObservable
276
- const currentPath = this.location.path(true);
277
- return this.authService.initialize().pipe(concatMap(() => {
278
- return this.authService.handleRedirectObservable();
279
- }), concatMap(() => {
280
- if (!this.authService.instance.getAllAccounts().length) {
281
- if (state) {
282
- this.authService
283
- .getLogger()
284
- .verbose("Guard - no accounts retrieved, log in required to activate");
285
- return this.loginInteractively(state);
286
- }
287
- this.authService
288
- .getLogger()
289
- .verbose("Guard - no accounts retrieved, no state, cannot load");
290
- return of(false);
291
- }
292
- this.authService
293
- .getLogger()
294
- .verbose("Guard - at least 1 account exists, can activate or load");
295
- // Prevent navigating the app to /#code= or /code=
296
- if (state) {
297
- /*
298
- * Path routing:
299
- * state.url: /#code=...
300
- * state.root.fragment: code=...
301
- */
302
- /*
303
- * Hash routing:
304
- * state.url: /code
305
- * state.root.fragment: null
306
- */
307
- const urlContainsCode = this.includesCode(state.url);
308
- const fragmentContainsCode = !!state.root &&
309
- !!state.root.fragment &&
310
- this.includesCode(`#${state.root.fragment}`);
311
- const hashRouting = this.location.prepareExternalUrl(state.url).indexOf("#") === 0;
312
- // Ensure code parameter is in fragment (and not in query parameter), or that hash hash routing is used
313
- if (urlContainsCode && (fragmentContainsCode || hashRouting)) {
314
- this.authService
315
- .getLogger()
316
- .info("Guard - Hash contains known code response, stopping navigation.");
317
- // Path routing (navigate to current path without hash)
318
- if (currentPath.indexOf("#") > -1) {
319
- return of(this.parseUrl(this.location.path()));
320
- }
321
- // Hash routing (navigate to root path)
322
- return of(this.parseUrl(""));
323
- }
324
- }
325
- return of(true);
326
- }), catchError((error) => {
327
- this.authService
328
- .getLogger()
329
- .error("Guard - error while logging in, unable to activate");
330
- this.authService
331
- .getLogger()
332
- .errorPii(`Guard - error: ${error.message}`);
333
- /**
334
- * If a loginFailedRoute is set, checks to see if state is passed before returning route
335
- */
336
- if (this.loginFailedRoute && state) {
337
- this.authService
338
- .getLogger()
339
- .verbose("Guard - loginFailedRoute set, redirecting");
340
- return of(this.loginFailedRoute);
341
- }
342
- return of(false);
343
- }));
344
- }
345
- includesCode(path) {
346
- return ((path.lastIndexOf("/code") > -1 &&
347
- path.lastIndexOf("/code") === path.length - "/code".length) || // path.endsWith("/code")
348
- path.indexOf("#code=") > -1 ||
349
- path.indexOf("&code=") > -1);
350
- }
351
- canActivate(route, state) {
352
- this.authService.getLogger().verbose("Guard - canActivate");
353
- return this.activateHelper(state);
354
- }
355
- canActivateChild(route, state) {
356
- this.authService.getLogger().verbose("Guard - canActivateChild");
357
- return this.activateHelper(state);
358
- }
359
- canMatch() {
360
- this.authService.getLogger().verbose("Guard - canLoad");
361
- return this.activateHelper();
362
- }
363
- }
364
- MsalGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalGuard, deps: [{ token: MSAL_GUARD_CONFIG }, { token: MsalBroadcastService }, { token: MsalService }, { token: i3.Location }, { token: i4.Router }], target: i0.ɵɵFactoryTarget.Injectable });
365
- MsalGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalGuard });
366
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalGuard, decorators: [{
367
- type: Injectable
368
- }], ctorParameters: function () {
369
- return [{ type: undefined, decorators: [{
370
- type: Inject,
371
- args: [MSAL_GUARD_CONFIG]
372
- }] }, { type: MsalBroadcastService }, { type: MsalService }, { type: i3.Location }, { type: i4.Router }];
373
- } });
374
-
375
- /*
376
- * Copyright (c) Microsoft Corporation. All rights reserved.
377
- * Licensed under the MIT License.
378
- */
379
- class MsalInterceptor {
380
- constructor(msalInterceptorConfig, authService, location, msalBroadcastService,
381
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
382
- document) {
383
- this.msalInterceptorConfig = msalInterceptorConfig;
384
- this.authService = authService;
385
- this.location = location;
386
- this.msalBroadcastService = msalBroadcastService;
387
- this._document = document;
388
- }
389
- intercept(req, // eslint-disable-line @typescript-eslint/no-explicit-any
390
- next
391
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
392
- ) {
393
- if (this.msalInterceptorConfig.interactionType !== InteractionType.Popup &&
394
- this.msalInterceptorConfig.interactionType !== InteractionType.Redirect) {
395
- throw new BrowserConfigurationAuthError("invalid_interaction_type", "Invalid interaction type provided to MSAL Interceptor. InteractionType.Popup, InteractionType.Redirect must be provided in the msalInterceptorConfiguration");
396
- }
397
- this.authService.getLogger().verbose("MSAL Interceptor activated");
398
- const scopes = this.getScopesForEndpoint(req.url, req.method);
399
- // If no scopes for endpoint, does not acquire token
400
- if (!scopes || scopes.length === 0) {
401
- this.authService
402
- .getLogger()
403
- .verbose("Interceptor - no scopes for endpoint");
404
- return next.handle(req);
405
- }
406
- // Sets account as active account or first account
407
- let account;
408
- if (!!this.authService.instance.getActiveAccount()) {
409
- this.authService
410
- .getLogger()
411
- .verbose("Interceptor - active account selected");
412
- account = this.authService.instance.getActiveAccount();
413
- }
414
- else {
415
- this.authService
416
- .getLogger()
417
- .verbose("Interceptor - no active account, fallback to first account");
418
- account = this.authService.instance.getAllAccounts()[0];
419
- }
420
- const authRequest = typeof this.msalInterceptorConfig.authRequest === "function"
421
- ? this.msalInterceptorConfig.authRequest(this.authService, req, {
422
- account: account,
423
- })
424
- : Object.assign(Object.assign({}, this.msalInterceptorConfig.authRequest), { account });
425
- this.authService
426
- .getLogger()
427
- .info(`Interceptor - ${scopes.length} scopes found for endpoint`);
428
- this.authService
429
- .getLogger()
430
- .infoPii(`Interceptor - [${scopes}] scopes found for ${req.url}`);
431
- return this.acquireToken(authRequest, scopes, account).pipe(switchMap((result) => {
432
- this.authService
433
- .getLogger()
434
- .verbose("Interceptor - setting authorization headers");
435
- const headers = req.headers.set("Authorization", `Bearer ${result.accessToken}`);
436
- const requestClone = req.clone({ headers });
437
- return next.handle(requestClone);
438
- }));
439
- }
440
- /**
441
- * Try to acquire token silently. Invoke interaction if acquireTokenSilent rejected with error or resolved with null access token
442
- * @param authRequest Request
443
- * @param scopes Array of scopes for the request
444
- * @param account Account
445
- * @returns Authentication result
446
- */
447
- acquireToken(authRequest, scopes, account) {
448
- // Note: For MSA accounts, include openid scope when calling acquireTokenSilent to return idToken
449
- return this.authService
450
- .acquireTokenSilent(Object.assign(Object.assign({}, authRequest), { scopes, account }))
451
- .pipe(catchError(() => {
452
- this.authService
453
- .getLogger()
454
- .error("Interceptor - acquireTokenSilent rejected with error. Invoking interaction to resolve.");
455
- return this.msalBroadcastService.inProgress$.pipe(take(1), switchMap((status) => {
456
- if (status === InteractionStatus.None) {
457
- return this.acquireTokenInteractively(authRequest, scopes);
458
- }
459
- return this.msalBroadcastService.inProgress$.pipe(filter((status) => status === InteractionStatus.None), take(1), switchMap(() => this.acquireToken(authRequest, scopes, account)));
460
- }));
461
- }), switchMap((result) => {
462
- if (!result.accessToken) {
463
- this.authService
464
- .getLogger()
465
- .error("Interceptor - acquireTokenSilent resolved with null access token. Known issue with B2C tenants, invoking interaction to resolve.");
466
- return this.msalBroadcastService.inProgress$.pipe(filter((status) => status === InteractionStatus.None), take(1), switchMap(() => this.acquireTokenInteractively(authRequest, scopes)));
467
- }
468
- return of(result);
469
- }));
470
- }
471
- /**
472
- * Invoke interaction for the given set of scopes
473
- * @param authRequest Request
474
- * @param scopes Array of scopes for the request
475
- * @returns Result from the interactive request
476
- */
477
- acquireTokenInteractively(authRequest, scopes) {
478
- if (this.msalInterceptorConfig.interactionType === InteractionType.Popup) {
479
- this.authService
480
- .getLogger()
481
- .verbose("Interceptor - error acquiring token silently, acquiring by popup");
482
- return this.authService.acquireTokenPopup(Object.assign(Object.assign({}, authRequest), { scopes }));
483
- }
484
- this.authService
485
- .getLogger()
486
- .verbose("Interceptor - error acquiring token silently, acquiring by redirect");
487
- const redirectStartPage = window.location.href;
488
- this.authService.acquireTokenRedirect(Object.assign(Object.assign({}, authRequest), { scopes,
489
- redirectStartPage }));
490
- return EMPTY;
491
- }
492
- /**
493
- * Looks up the scopes for the given endpoint from the protectedResourceMap
494
- * @param endpoint Url of the request
495
- * @param httpMethod Http method of the request
496
- * @returns Array of scopes, or null if not found
497
- *
498
- */
499
- getScopesForEndpoint(endpoint, httpMethod) {
500
- this.authService
501
- .getLogger()
502
- .verbose("Interceptor - getting scopes for endpoint");
503
- // Ensures endpoints and protected resources compared are normalized
504
- const normalizedEndpoint = this.location.normalize(endpoint);
505
- const protectedResourcesArray = Array.from(this.msalInterceptorConfig.protectedResourceMap.keys());
506
- const matchingProtectedResources = this.matchResourcesToEndpoint(protectedResourcesArray, normalizedEndpoint);
507
- if (matchingProtectedResources.length > 0) {
508
- return this.matchScopesToEndpoint(this.msalInterceptorConfig.protectedResourceMap, matchingProtectedResources, httpMethod);
509
- }
510
- return null;
511
- }
512
- /**
513
- * Finds resource endpoints that match request endpoint
514
- * @param protectedResourcesEndpoints
515
- * @param endpoint
516
- * @returns
517
- */
518
- matchResourcesToEndpoint(protectedResourcesEndpoints, endpoint) {
519
- const matchingResources = [];
520
- protectedResourcesEndpoints.forEach((key) => {
521
- const normalizedKey = this.location.normalize(key);
522
- // Get url components
523
- const absoluteKey = this.getAbsoluteUrl(normalizedKey);
524
- const keyComponents = new URL(absoluteKey);
525
- const absoluteEndpoint = this.getAbsoluteUrl(endpoint);
526
- const endpointComponents = new URL(absoluteEndpoint);
527
- if (this.checkUrlComponents(keyComponents, endpointComponents)) {
528
- matchingResources.push(key);
529
- }
530
- });
531
- return matchingResources;
532
- }
533
- /**
534
- * Compares URL segments between key and endpoint
535
- * @param key
536
- * @param endpoint
537
- * @returns
538
- */
539
- checkUrlComponents(keyComponents, endpointComponents) {
540
- // URL properties from https://developer.mozilla.org/en-US/docs/Web/API/URL
541
- const urlProperties = ["protocol", "host", "pathname", "search", "hash"];
542
- for (const property of urlProperties) {
543
- if (keyComponents[property]) {
544
- const decodedInput = decodeURIComponent(keyComponents[property]);
545
- if (!StringUtils.matchPattern(decodedInput, endpointComponents[property])) {
546
- return false;
547
- }
548
- }
549
- }
550
- return true;
551
- }
552
- /**
553
- * Transforms relative urls to absolute urls
554
- * @param url
555
- * @returns
556
- */
557
- getAbsoluteUrl(url) {
558
- const link = this._document.createElement("a");
559
- link.href = url;
560
- return link.href;
561
- }
562
- /**
563
- * Finds scopes from first matching endpoint with HTTP method that matches request
564
- * @param protectedResourceMap Protected resource map
565
- * @param endpointArray Array of resources that match request endpoint
566
- * @param httpMethod Http method of the request
567
- * @returns
568
- */
569
- matchScopesToEndpoint(protectedResourceMap, endpointArray, httpMethod) {
570
- const allMatchedScopes = [];
571
- // Check each matched endpoint for matching HttpMethod and scopes
572
- endpointArray.forEach((matchedEndpoint) => {
573
- const scopesForEndpoint = [];
574
- const methodAndScopesArray = protectedResourceMap.get(matchedEndpoint);
575
- // Return if resource is unprotected
576
- if (methodAndScopesArray === null) {
577
- allMatchedScopes.push(null);
578
- return;
579
- }
580
- methodAndScopesArray.forEach((entry) => {
581
- // Entry is either array of scopes or ProtectedResourceScopes object
582
- if (typeof entry === "string") {
583
- scopesForEndpoint.push(entry);
584
- }
585
- else {
586
- // Ensure methods being compared are normalized
587
- const normalizedRequestMethod = httpMethod.toLowerCase();
588
- const normalizedResourceMethod = entry.httpMethod.toLowerCase();
589
- // Method in protectedResourceMap matches request http method
590
- if (normalizedResourceMethod === normalizedRequestMethod) {
591
- // Validate if scopes comes null to unprotect the resource in a certain http method
592
- if (entry.scopes === null) {
593
- allMatchedScopes.push(null);
594
- }
595
- else {
596
- entry.scopes.forEach((scope) => {
597
- scopesForEndpoint.push(scope);
598
- });
599
- }
600
- }
601
- }
602
- });
603
- // Only add to all scopes if scopes for endpoint and method is found
604
- if (scopesForEndpoint.length > 0) {
605
- allMatchedScopes.push(scopesForEndpoint);
606
- }
607
- });
608
- if (allMatchedScopes.length > 0) {
609
- if (allMatchedScopes.length > 1) {
610
- this.authService
611
- .getLogger()
612
- .warning("Interceptor - More than 1 matching scopes for endpoint found.");
613
- }
614
- // Returns scopes for first matching endpoint
615
- return allMatchedScopes[0];
616
- }
617
- return null;
618
- }
619
- }
620
- MsalInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalInterceptor, deps: [{ token: MSAL_INTERCEPTOR_CONFIG }, { token: MsalService }, { token: i3.Location }, { token: MsalBroadcastService }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
621
- MsalInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalInterceptor });
622
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalInterceptor, decorators: [{
623
- type: Injectable
624
- }], ctorParameters: function () {
625
- return [{ type: undefined, decorators: [{
626
- type: Inject,
627
- args: [MSAL_INTERCEPTOR_CONFIG]
628
- }] }, { type: MsalService }, { type: i3.Location }, { type: MsalBroadcastService }, { type: undefined, decorators: [{
629
- type: Inject,
630
- args: [DOCUMENT]
631
- }] }];
632
- } });
633
-
634
- /*
635
- * Copyright (c) Microsoft Corporation. All rights reserved.
636
- * Licensed under the MIT License.
637
- */
638
- /**
639
- * This is a dedicated redirect component to be added to Angular apps to
640
- * handle redirects when using @azure/msal-angular.
641
- * Import this component to use redirects in your app.
642
- */
643
- class MsalRedirectComponent {
644
- constructor(authService) {
645
- this.authService = authService;
646
- }
647
- ngOnInit() {
648
- this.authService.getLogger().verbose("MsalRedirectComponent activated");
649
- this.authService.handleRedirectObservable().subscribe();
650
- }
651
- }
652
- MsalRedirectComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalRedirectComponent, deps: [{ token: MsalService }], target: i0.ɵɵFactoryTarget.Component });
653
- MsalRedirectComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: MsalRedirectComponent, selector: "app-redirect", ngImport: i0, template: "", isInline: true });
654
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalRedirectComponent, decorators: [{
655
- type: Component,
656
- args: [{
657
- selector: "app-redirect",
658
- template: "",
659
- }]
660
- }], ctorParameters: function () { return [{ type: MsalService }]; } });
661
-
662
- /*
663
- * Copyright (c) Microsoft Corporation. All rights reserved.
664
- * Licensed under the MIT License.
665
- */
666
- class MsalModule {
667
- static forRoot(msalInstance, guardConfig, interceptorConfig) {
668
- return {
669
- ngModule: MsalModule,
670
- providers: [
671
- {
672
- provide: MSAL_INSTANCE,
673
- useValue: msalInstance,
674
- },
675
- {
676
- provide: MSAL_GUARD_CONFIG,
677
- useValue: guardConfig,
678
- },
679
- {
680
- provide: MSAL_INTERCEPTOR_CONFIG,
681
- useValue: interceptorConfig,
682
- },
683
- MsalService,
684
- ],
685
- };
686
- }
687
- }
688
- MsalModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
689
- MsalModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.10", ngImport: i0, type: MsalModule, declarations: [MsalRedirectComponent], imports: [CommonModule] });
690
- MsalModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalModule, providers: [MsalGuard, MsalBroadcastService], imports: [CommonModule] });
691
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalModule, decorators: [{
692
- type: NgModule,
693
- args: [{
694
- declarations: [MsalRedirectComponent],
695
- imports: [CommonModule],
696
- providers: [MsalGuard, MsalBroadcastService],
697
- }]
698
- }] });
699
-
700
- /**
701
- * Custom navigation used for Angular client-side navigation.
702
- * See performance doc for details:
703
- * https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-angular/docs/performance.md
704
- */
705
- class MsalCustomNavigationClient extends NavigationClient {
706
- constructor(authService, router, location) {
707
- super();
708
- this.authService = authService;
709
- this.router = router;
710
- this.location = location;
711
- }
712
- navigateInternal(url, options) {
713
- const _super = Object.create(null, {
714
- navigateInternal: { get: () => super.navigateInternal }
715
- });
716
- return __awaiter(this, void 0, void 0, function* () {
717
- this.authService.getLogger().trace("MsalCustomNavigationClient called");
718
- this.authService
719
- .getLogger()
720
- .verbose("MsalCustomNavigationClient - navigating");
721
- this.authService
722
- .getLogger()
723
- .verbosePii(`MsalCustomNavigationClient - navigating to url: ${url}`);
724
- // Prevent hash clearing from causing an issue with Client-side navigation after redirect is handled
725
- if (options.noHistory) {
726
- return _super.navigateInternal.call(this, url, options);
727
- }
728
- else {
729
- // Normalizing newUrl if no query string
730
- const urlComponents = new UrlString(url).getUrlComponents();
731
- const newUrl = urlComponents.QueryString
732
- ? `${urlComponents.AbsolutePath}?${urlComponents.QueryString}`
733
- : this.location.normalize(urlComponents.AbsolutePath);
734
- yield this.router.navigateByUrl(newUrl, {
735
- replaceUrl: options.noHistory,
736
- });
737
- }
738
- return Promise.resolve(options.noHistory);
739
- });
740
- }
741
- }
742
- MsalCustomNavigationClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalCustomNavigationClient, deps: [{ token: MsalService }, { token: i4.Router }, { token: i3.Location }], target: i0.ɵɵFactoryTarget.Injectable });
743
- MsalCustomNavigationClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalCustomNavigationClient });
744
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MsalCustomNavigationClient, decorators: [{
745
- type: Injectable
746
- }], ctorParameters: function () { return [{ type: MsalService }, { type: i4.Router }, { type: i3.Location }]; } });
747
-
748
- /*
749
- * Copyright (c) Microsoft Corporation. All rights reserved.
750
- * Licensed under the MIT License.
751
- */
752
- /**
753
- * @packageDocumentation
754
- * @module @azure/msal-angular
755
- */
756
-
757
- /**
758
- * Generated bundle index. Do not edit.
759
- */
760
-
761
- export { MSAL_BROADCAST_CONFIG, MSAL_GUARD_CONFIG, MSAL_INSTANCE, MSAL_INTERCEPTOR_CONFIG, MsalBroadcastService, MsalCustomNavigationClient, MsalGuard, MsalInterceptor, MsalModule, MsalRedirectComponent, MsalService, version };
762
- //# sourceMappingURL=azure-msal-angular.mjs.map