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