@azure/msal-angular 4.0.13 → 4.0.15
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/IMsalService.d.ts +17 -0
- package/README.md +1 -1
- package/constants.d.ts +5 -0
- package/esm2020/IMsalService.mjs +6 -0
- package/esm2020/azure-msal-angular.mjs +5 -0
- package/esm2020/constants.mjs +10 -0
- package/esm2020/msal.broadcast.config.mjs +6 -0
- package/esm2020/msal.broadcast.service.mjs +66 -0
- package/esm2020/msal.guard.config.mjs +6 -0
- package/esm2020/msal.guard.mjs +218 -0
- package/esm2020/msal.interceptor.config.mjs +6 -0
- package/esm2020/msal.interceptor.mjs +270 -0
- package/esm2020/msal.module.mjs +46 -0
- package/esm2020/msal.navigation.client.mjs +53 -0
- package/esm2020/msal.redirect.component.mjs +31 -0
- package/esm2020/msal.service.mjs +88 -0
- package/esm2020/packageMetadata.mjs +4 -0
- package/esm2020/public-api.mjs +18 -0
- package/fesm2015/azure-msal-angular.mjs +762 -0
- package/fesm2015/azure-msal-angular.mjs.map +1 -0
- package/fesm2020/azure-msal-angular.mjs +758 -0
- package/fesm2020/azure-msal-angular.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/msal.broadcast.config.d.ts +3 -0
- package/msal.broadcast.service.d.ts +19 -0
- package/msal.guard.config.d.ts +9 -0
- package/msal.guard.d.ts +43 -0
- package/msal.interceptor.config.d.ts +13 -0
- package/msal.interceptor.d.ts +70 -0
- package/msal.module.d.ts +13 -0
- package/msal.navigation.client.d.ts +19 -0
- package/msal.redirect.component.d.ts +15 -0
- package/msal.service.d.ts +33 -0
- package/package.json +26 -56
- package/packageMetadata.d.ts +2 -0
- package/{src/public-api.ts → public-api.d.ts} +17 -35
- package/.beachballrc +0 -3
- package/.editorconfig +0 -16
- package/.eslintrc.json +0 -3
- package/CHANGELOG.json +0 -2315
- package/CHANGELOG.md +0 -869
- package/FAQ.md +0 -182
- package/angular.json +0 -51
- package/docs/angular-universal.md +0 -64
- package/docs/configuration.md +0 -609
- package/docs/errors.md +0 -89
- package/docs/events.md +0 -262
- package/docs/initialization.md +0 -206
- package/docs/known-issues.md +0 -19
- package/docs/logging.md +0 -47
- package/docs/msal-guard.md +0 -208
- package/docs/msal-interceptor.md +0 -160
- package/docs/multi-tenant.md +0 -90
- package/docs/performance.md +0 -50
- package/docs/public-apis.md +0 -29
- package/docs/redirects.md +0 -257
- package/docs/security.md +0 -4
- package/docs/ssosilent.md +0 -84
- package/docs/v0-v1-upgrade-guide.md +0 -61
- package/docs/v1-v2-upgrade-guide.md +0 -70
- package/docs/v2-v3-upgrade-guide.md +0 -52
- package/docs/v3-v4-upgrade-guide.md +0 -36
- package/karma.conf.js +0 -44
- package/ng-package.json +0 -7
- package/src/IMsalService.ts +0 -34
- package/src/constants.ts +0 -20
- package/src/msal.broadcast.config.ts +0 -8
- package/src/msal.broadcast.service.spec.ts +0 -471
- package/src/msal.broadcast.service.ts +0 -84
- package/src/msal.guard.config.ts +0 -27
- package/src/msal.guard.spec.ts +0 -525
- package/src/msal.guard.ts +0 -290
- package/src/msal.interceptor.config.ts +0 -39
- package/src/msal.interceptor.spec.ts +0 -1168
- package/src/msal.interceptor.ts +0 -388
- package/src/msal.module.ts +0 -51
- package/src/msal.navigation.client.spec.ts +0 -96
- package/src/msal.navigation.client.ts +0 -59
- package/src/msal.redirect.component.spec.ts +0 -64
- package/src/msal.redirect.component.ts +0 -26
- package/src/msal.service.spec.ts +0 -468
- package/src/msal.service.ts +0 -104
- package/src/packageMetadata.ts +0 -3
- package/src/test.ts +0 -19
- package/tsconfig.json +0 -25
- package/tsconfig.lib.json +0 -27
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -17
- package/typedoc.json +0 -10
package/src/IMsalService.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
EndSessionRequest,
|
|
8
|
-
AuthenticationResult,
|
|
9
|
-
PopupRequest,
|
|
10
|
-
RedirectRequest,
|
|
11
|
-
SilentRequest,
|
|
12
|
-
Logger,
|
|
13
|
-
SsoSilentRequest,
|
|
14
|
-
} from "@azure/msal-browser";
|
|
15
|
-
import { Observable } from "rxjs";
|
|
16
|
-
|
|
17
|
-
export interface IMsalService {
|
|
18
|
-
initialize(): Observable<void>;
|
|
19
|
-
acquireTokenPopup(request: PopupRequest): Observable<AuthenticationResult>;
|
|
20
|
-
acquireTokenRedirect(request: RedirectRequest): Observable<void>;
|
|
21
|
-
acquireTokenSilent(
|
|
22
|
-
silentRequest: SilentRequest
|
|
23
|
-
): Observable<AuthenticationResult>;
|
|
24
|
-
handleRedirectObservable(): Observable<AuthenticationResult | null>;
|
|
25
|
-
loginPopup(request?: PopupRequest): Observable<AuthenticationResult>;
|
|
26
|
-
loginRedirect(request?: RedirectRequest): Observable<void>;
|
|
27
|
-
// @deprecated: Use logoutRedirect or logoutPopup
|
|
28
|
-
logout(logoutRequest?: EndSessionRequest): Observable<void>;
|
|
29
|
-
logoutRedirect(logoutRequest?: EndSessionRequest): Observable<void>;
|
|
30
|
-
logoutPopup(logoutRequest?: EndSessionRequest): Observable<void>;
|
|
31
|
-
ssoSilent(request: SsoSilentRequest): Observable<AuthenticationResult>;
|
|
32
|
-
getLogger(): Logger;
|
|
33
|
-
setLogger(logger: Logger): void;
|
|
34
|
-
}
|
package/src/constants.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { InjectionToken } from "@angular/core";
|
|
7
|
-
|
|
8
|
-
export const MSAL_INSTANCE = new InjectionToken<string>("MSAL_INSTANCE");
|
|
9
|
-
|
|
10
|
-
export const MSAL_GUARD_CONFIG = new InjectionToken<string>(
|
|
11
|
-
"MSAL_GUARD_CONFIG"
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
export const MSAL_INTERCEPTOR_CONFIG = new InjectionToken<string>(
|
|
15
|
-
"MSAL_INTERCEPTOR_CONFIG"
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
export const MSAL_BROADCAST_CONFIG = new InjectionToken<string>(
|
|
19
|
-
"MSAL_BROADCAST_CONFIG"
|
|
20
|
-
);
|
|
@@ -1,471 +0,0 @@
|
|
|
1
|
-
import { TestBed } from "@angular/core/testing";
|
|
2
|
-
import {
|
|
3
|
-
EventHandler,
|
|
4
|
-
EventType,
|
|
5
|
-
InteractionStatus,
|
|
6
|
-
InteractionType,
|
|
7
|
-
PublicClientApplication,
|
|
8
|
-
} from "@azure/msal-browser";
|
|
9
|
-
import { Subscription } from "rxjs";
|
|
10
|
-
import { MsalModule, MSAL_BROADCAST_CONFIG } from "./public-api";
|
|
11
|
-
import { MsalBroadcastService } from "./msal.broadcast.service";
|
|
12
|
-
|
|
13
|
-
let broadcastService: MsalBroadcastService;
|
|
14
|
-
let subscription: Subscription;
|
|
15
|
-
|
|
16
|
-
const msalInstance = new PublicClientApplication({
|
|
17
|
-
auth: {
|
|
18
|
-
clientId: "b5c2e510-4a17-4feb-b219-e55aa5b74144",
|
|
19
|
-
redirectUri: "http://localhost:4200",
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
let eventHandler;
|
|
24
|
-
const eventSpy = jasmine.createSpy("addEventCallback");
|
|
25
|
-
msalInstance.addEventCallback = eventSpy;
|
|
26
|
-
|
|
27
|
-
function initializeMsal(providers: any[] = []) {
|
|
28
|
-
TestBed.resetTestingModule();
|
|
29
|
-
|
|
30
|
-
eventHandler = new EventHandler();
|
|
31
|
-
eventSpy.and.callFake((callback, types) => {
|
|
32
|
-
return eventHandler.addEventCallback(callback, types);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
TestBed.configureTestingModule({
|
|
36
|
-
imports: [
|
|
37
|
-
MsalModule.forRoot(msalInstance, null, {
|
|
38
|
-
interactionType: InteractionType.Popup,
|
|
39
|
-
protectedResourceMap: new Map(),
|
|
40
|
-
}),
|
|
41
|
-
],
|
|
42
|
-
providers: [MsalBroadcastService, ...providers],
|
|
43
|
-
teardown: { destroyAfterEach: false },
|
|
44
|
-
});
|
|
45
|
-
broadcastService = TestBed.inject(MsalBroadcastService);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
describe("MsalBroadcastService", () => {
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
initializeMsal();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
afterEach(() => {
|
|
54
|
-
subscription.unsubscribe();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("broadcasts event from PublicClientApplication", (done) => {
|
|
58
|
-
const sub = broadcastService.msalSubject$.subscribe((result) => {
|
|
59
|
-
expect(result.eventType).toEqual(EventType.LOGIN_START);
|
|
60
|
-
expect(result.interactionType).toEqual(InteractionType.Popup);
|
|
61
|
-
expect(result.payload).toEqual(null);
|
|
62
|
-
expect(result.error).toEqual(null);
|
|
63
|
-
expect(result.timestamp).toBeInstanceOf(Number);
|
|
64
|
-
sub.unsubscribe();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const expectedInProgress = [
|
|
68
|
-
InteractionStatus.Startup,
|
|
69
|
-
InteractionStatus.Login,
|
|
70
|
-
];
|
|
71
|
-
let index = 0;
|
|
72
|
-
|
|
73
|
-
subscription = broadcastService.inProgress$.subscribe((result) => {
|
|
74
|
-
expect(result).toEqual(expectedInProgress[index]);
|
|
75
|
-
if (index === expectedInProgress.length - 1) {
|
|
76
|
-
done();
|
|
77
|
-
} else {
|
|
78
|
-
index++;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
eventHandler.emitEvent(EventType.LOGIN_START, InteractionType.Popup);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("broadcasts previous events if MsalBroadcastConfig set and eventsToReplay is greater than 0", (done) => {
|
|
86
|
-
initializeMsal([
|
|
87
|
-
{
|
|
88
|
-
provide: MSAL_BROADCAST_CONFIG,
|
|
89
|
-
useValue: {
|
|
90
|
-
eventsToReplay: 3,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
]);
|
|
94
|
-
|
|
95
|
-
const expectedMsalSubjectFirstSubscription = [
|
|
96
|
-
{
|
|
97
|
-
eventType: EventType.LOGIN_START,
|
|
98
|
-
interactionType: InteractionType.Redirect,
|
|
99
|
-
payload: null,
|
|
100
|
-
error: null,
|
|
101
|
-
},
|
|
102
|
-
];
|
|
103
|
-
let firstIndex = 0;
|
|
104
|
-
|
|
105
|
-
subscription = broadcastService.msalSubject$.subscribe((result) => {
|
|
106
|
-
expect(result.eventType).toEqual(
|
|
107
|
-
expectedMsalSubjectFirstSubscription[firstIndex].eventType
|
|
108
|
-
);
|
|
109
|
-
expect(result.interactionType).toEqual(
|
|
110
|
-
expectedMsalSubjectFirstSubscription[firstIndex].interactionType
|
|
111
|
-
);
|
|
112
|
-
expect(result.payload).toEqual(
|
|
113
|
-
expectedMsalSubjectFirstSubscription[firstIndex].payload
|
|
114
|
-
);
|
|
115
|
-
expect(result.error).toEqual(
|
|
116
|
-
expectedMsalSubjectFirstSubscription[firstIndex].error
|
|
117
|
-
);
|
|
118
|
-
expect(result.timestamp).toBeInstanceOf(Number);
|
|
119
|
-
if (firstIndex === expectedMsalSubjectFirstSubscription.length - 1) {
|
|
120
|
-
return;
|
|
121
|
-
} else {
|
|
122
|
-
firstIndex++;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
eventHandler.emitEvent(EventType.LOGIN_START, InteractionType.Redirect);
|
|
127
|
-
|
|
128
|
-
subscription.unsubscribe();
|
|
129
|
-
|
|
130
|
-
let index = 0;
|
|
131
|
-
const expectedMsalSubject = [
|
|
132
|
-
{
|
|
133
|
-
eventType: EventType.LOGIN_START,
|
|
134
|
-
interactionType: InteractionType.Redirect,
|
|
135
|
-
payload: null,
|
|
136
|
-
error: null,
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
eventType: EventType.HANDLE_REDIRECT_START,
|
|
140
|
-
interactionType: InteractionType.Redirect,
|
|
141
|
-
payload: null,
|
|
142
|
-
error: null,
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
eventType: EventType.HANDLE_REDIRECT_END,
|
|
146
|
-
interactionType: InteractionType.Redirect,
|
|
147
|
-
payload: null,
|
|
148
|
-
error: null,
|
|
149
|
-
},
|
|
150
|
-
];
|
|
151
|
-
|
|
152
|
-
const newSubscription = broadcastService.msalSubject$.subscribe(
|
|
153
|
-
(result) => {
|
|
154
|
-
expect(result.eventType).toEqual(expectedMsalSubject[index].eventType);
|
|
155
|
-
expect(result.interactionType).toEqual(
|
|
156
|
-
expectedMsalSubject[index].interactionType
|
|
157
|
-
);
|
|
158
|
-
expect(result.payload).toEqual(expectedMsalSubject[index].payload);
|
|
159
|
-
expect(result.error).toEqual(expectedMsalSubject[index].error);
|
|
160
|
-
expect(result.timestamp).toBeInstanceOf(Number);
|
|
161
|
-
if (index === expectedMsalSubject.length - 1) {
|
|
162
|
-
done();
|
|
163
|
-
} else {
|
|
164
|
-
index++;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
eventHandler.emitEvent(
|
|
170
|
-
EventType.HANDLE_REDIRECT_START,
|
|
171
|
-
InteractionType.Redirect
|
|
172
|
-
);
|
|
173
|
-
eventHandler.emitEvent(
|
|
174
|
-
EventType.HANDLE_REDIRECT_END,
|
|
175
|
-
InteractionType.Redirect
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
newSubscription.unsubscribe();
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("broadcasts the set number of past events if MsalBroadcastConfig and eventsToReplay is set", (done) => {
|
|
182
|
-
initializeMsal([
|
|
183
|
-
{
|
|
184
|
-
provide: MSAL_BROADCAST_CONFIG,
|
|
185
|
-
useValue: {
|
|
186
|
-
eventsToReplay: 1,
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
]);
|
|
190
|
-
|
|
191
|
-
const expectedMsalSubjectFirstSubscription = [
|
|
192
|
-
{
|
|
193
|
-
eventType: EventType.INITIALIZE_START,
|
|
194
|
-
interactionType: InteractionType.Redirect,
|
|
195
|
-
payload: null,
|
|
196
|
-
error: null,
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
eventType: EventType.LOGIN_START,
|
|
200
|
-
interactionType: InteractionType.Redirect,
|
|
201
|
-
payload: null,
|
|
202
|
-
error: null,
|
|
203
|
-
},
|
|
204
|
-
];
|
|
205
|
-
let firstIndex = 0;
|
|
206
|
-
|
|
207
|
-
subscription = broadcastService.msalSubject$.subscribe((result) => {
|
|
208
|
-
expect(result.eventType).toEqual(
|
|
209
|
-
expectedMsalSubjectFirstSubscription[firstIndex].eventType
|
|
210
|
-
);
|
|
211
|
-
expect(result.interactionType).toEqual(
|
|
212
|
-
expectedMsalSubjectFirstSubscription[firstIndex].interactionType
|
|
213
|
-
);
|
|
214
|
-
expect(result.payload).toEqual(
|
|
215
|
-
expectedMsalSubjectFirstSubscription[firstIndex].payload
|
|
216
|
-
);
|
|
217
|
-
expect(result.error).toEqual(
|
|
218
|
-
expectedMsalSubjectFirstSubscription[firstIndex].error
|
|
219
|
-
);
|
|
220
|
-
expect(result.timestamp).toBeInstanceOf(Number);
|
|
221
|
-
if (firstIndex === expectedMsalSubjectFirstSubscription.length - 1) {
|
|
222
|
-
return;
|
|
223
|
-
} else {
|
|
224
|
-
firstIndex++;
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
eventHandler.emitEvent(
|
|
229
|
-
EventType.INITIALIZE_START,
|
|
230
|
-
InteractionType.Redirect
|
|
231
|
-
);
|
|
232
|
-
eventHandler.emitEvent(EventType.LOGIN_START, InteractionType.Redirect);
|
|
233
|
-
|
|
234
|
-
subscription.unsubscribe();
|
|
235
|
-
|
|
236
|
-
let index = 0;
|
|
237
|
-
const expectedMsalSubject = [
|
|
238
|
-
{
|
|
239
|
-
eventType: EventType.LOGIN_START,
|
|
240
|
-
interactionType: InteractionType.Redirect,
|
|
241
|
-
payload: null,
|
|
242
|
-
error: null,
|
|
243
|
-
},
|
|
244
|
-
{
|
|
245
|
-
eventType: EventType.HANDLE_REDIRECT_START,
|
|
246
|
-
interactionType: InteractionType.Redirect,
|
|
247
|
-
payload: null,
|
|
248
|
-
error: null,
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
eventType: EventType.HANDLE_REDIRECT_END,
|
|
252
|
-
interactionType: InteractionType.Redirect,
|
|
253
|
-
payload: null,
|
|
254
|
-
error: null,
|
|
255
|
-
},
|
|
256
|
-
];
|
|
257
|
-
|
|
258
|
-
const newSubscription = broadcastService.msalSubject$.subscribe(
|
|
259
|
-
(result) => {
|
|
260
|
-
expect(result.eventType).toEqual(expectedMsalSubject[index].eventType);
|
|
261
|
-
expect(result.interactionType).toEqual(
|
|
262
|
-
expectedMsalSubject[index].interactionType
|
|
263
|
-
);
|
|
264
|
-
expect(result.payload).toEqual(expectedMsalSubject[index].payload);
|
|
265
|
-
expect(result.error).toEqual(expectedMsalSubject[index].error);
|
|
266
|
-
expect(result.timestamp).toBeInstanceOf(Number);
|
|
267
|
-
if (index === expectedMsalSubject.length - 1) {
|
|
268
|
-
done();
|
|
269
|
-
} else {
|
|
270
|
-
index++;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
eventHandler.emitEvent(
|
|
276
|
-
EventType.HANDLE_REDIRECT_START,
|
|
277
|
-
InteractionType.Redirect
|
|
278
|
-
);
|
|
279
|
-
eventHandler.emitEvent(
|
|
280
|
-
EventType.HANDLE_REDIRECT_END,
|
|
281
|
-
InteractionType.Redirect
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
newSubscription.unsubscribe();
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it("does not broadcasts previous events if MsalBroadcastConfig is not set", (done) => {
|
|
288
|
-
const expectedMsalSubjectFirstSubscription = [
|
|
289
|
-
{
|
|
290
|
-
eventType: EventType.LOGIN_START,
|
|
291
|
-
interactionType: InteractionType.Redirect,
|
|
292
|
-
payload: null,
|
|
293
|
-
error: null,
|
|
294
|
-
},
|
|
295
|
-
];
|
|
296
|
-
let firstIndex = 0;
|
|
297
|
-
|
|
298
|
-
subscription = broadcastService.msalSubject$.subscribe((result) => {
|
|
299
|
-
expect(result.eventType).toEqual(
|
|
300
|
-
expectedMsalSubjectFirstSubscription[firstIndex].eventType
|
|
301
|
-
);
|
|
302
|
-
expect(result.interactionType).toEqual(
|
|
303
|
-
expectedMsalSubjectFirstSubscription[firstIndex].interactionType
|
|
304
|
-
);
|
|
305
|
-
expect(result.payload).toEqual(
|
|
306
|
-
expectedMsalSubjectFirstSubscription[firstIndex].payload
|
|
307
|
-
);
|
|
308
|
-
expect(result.error).toEqual(
|
|
309
|
-
expectedMsalSubjectFirstSubscription[firstIndex].error
|
|
310
|
-
);
|
|
311
|
-
expect(result.timestamp).toBeInstanceOf(Number);
|
|
312
|
-
if (firstIndex === expectedMsalSubjectFirstSubscription.length - 1) {
|
|
313
|
-
return;
|
|
314
|
-
} else {
|
|
315
|
-
firstIndex++;
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
eventHandler.emitEvent(EventType.LOGIN_START, InteractionType.Redirect);
|
|
320
|
-
|
|
321
|
-
subscription.unsubscribe();
|
|
322
|
-
|
|
323
|
-
let index = 0;
|
|
324
|
-
const expectedMsalSubject = [
|
|
325
|
-
{
|
|
326
|
-
eventType: EventType.HANDLE_REDIRECT_START,
|
|
327
|
-
interactionType: InteractionType.Redirect,
|
|
328
|
-
payload: null,
|
|
329
|
-
error: null,
|
|
330
|
-
},
|
|
331
|
-
{
|
|
332
|
-
eventType: EventType.HANDLE_REDIRECT_END,
|
|
333
|
-
interactionType: InteractionType.Redirect,
|
|
334
|
-
payload: null,
|
|
335
|
-
error: null,
|
|
336
|
-
},
|
|
337
|
-
];
|
|
338
|
-
|
|
339
|
-
const newSubscription = broadcastService.msalSubject$.subscribe(
|
|
340
|
-
(result) => {
|
|
341
|
-
expect(result.eventType).toEqual(expectedMsalSubject[index].eventType);
|
|
342
|
-
expect(result.interactionType).toEqual(
|
|
343
|
-
expectedMsalSubject[index].interactionType
|
|
344
|
-
);
|
|
345
|
-
expect(result.payload).toEqual(expectedMsalSubject[index].payload);
|
|
346
|
-
expect(result.error).toEqual(expectedMsalSubject[index].error);
|
|
347
|
-
expect(result.timestamp).toBeInstanceOf(Number);
|
|
348
|
-
if (index === expectedMsalSubject.length - 1) {
|
|
349
|
-
done();
|
|
350
|
-
} else {
|
|
351
|
-
index++;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
);
|
|
355
|
-
|
|
356
|
-
eventHandler.emitEvent(
|
|
357
|
-
EventType.HANDLE_REDIRECT_START,
|
|
358
|
-
InteractionType.Redirect
|
|
359
|
-
);
|
|
360
|
-
eventHandler.emitEvent(
|
|
361
|
-
EventType.HANDLE_REDIRECT_END,
|
|
362
|
-
InteractionType.Redirect
|
|
363
|
-
);
|
|
364
|
-
|
|
365
|
-
newSubscription.unsubscribe();
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
it("LOGIN_SUCCESS event does not set inProgress to None if handleRedirect is still in progress", (done) => {
|
|
369
|
-
const expectedInProgress = [
|
|
370
|
-
InteractionStatus.Startup,
|
|
371
|
-
InteractionStatus.HandleRedirect,
|
|
372
|
-
];
|
|
373
|
-
let index = 0;
|
|
374
|
-
|
|
375
|
-
subscription = broadcastService.inProgress$.subscribe((result) => {
|
|
376
|
-
expect(result).toEqual(expectedInProgress[index]);
|
|
377
|
-
if (index === expectedInProgress.length - 1) {
|
|
378
|
-
done();
|
|
379
|
-
} else {
|
|
380
|
-
index++;
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
eventHandler.emitEvent(
|
|
385
|
-
EventType.HANDLE_REDIRECT_START,
|
|
386
|
-
InteractionType.Redirect
|
|
387
|
-
);
|
|
388
|
-
eventHandler.emitEvent(EventType.LOGIN_SUCCESS, InteractionType.Redirect);
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
it("HANDLE_REDIRECT_END event sets inProgress to None if handleRedirect is in progress", (done) => {
|
|
392
|
-
const expectedInProgress = [
|
|
393
|
-
InteractionStatus.Startup,
|
|
394
|
-
InteractionStatus.HandleRedirect,
|
|
395
|
-
InteractionStatus.None,
|
|
396
|
-
];
|
|
397
|
-
let index = 0;
|
|
398
|
-
|
|
399
|
-
subscription = broadcastService.inProgress$.subscribe((result) => {
|
|
400
|
-
expect(result).toEqual(expectedInProgress[index]);
|
|
401
|
-
if (index === expectedInProgress.length - 1) {
|
|
402
|
-
done();
|
|
403
|
-
} else {
|
|
404
|
-
index++;
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
eventHandler.emitEvent(
|
|
409
|
-
EventType.HANDLE_REDIRECT_START,
|
|
410
|
-
InteractionType.Redirect
|
|
411
|
-
);
|
|
412
|
-
eventHandler.emitEvent(EventType.LOGIN_SUCCESS, InteractionType.Redirect);
|
|
413
|
-
eventHandler.emitEvent(
|
|
414
|
-
EventType.HANDLE_REDIRECT_END,
|
|
415
|
-
InteractionType.Redirect
|
|
416
|
-
);
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
it("HANDLE_REDIRECT_END event does not set inProgress to None if login is in progress", (done) => {
|
|
420
|
-
const expectedInProgress = [
|
|
421
|
-
InteractionStatus.Startup,
|
|
422
|
-
InteractionStatus.HandleRedirect,
|
|
423
|
-
InteractionStatus.Login,
|
|
424
|
-
];
|
|
425
|
-
let index = 0;
|
|
426
|
-
|
|
427
|
-
subscription = broadcastService.inProgress$.subscribe((result) => {
|
|
428
|
-
expect(result).toEqual(expectedInProgress[index]);
|
|
429
|
-
if (index === expectedInProgress.length - 1) {
|
|
430
|
-
done();
|
|
431
|
-
} else {
|
|
432
|
-
index++;
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
eventHandler.emitEvent(
|
|
437
|
-
EventType.HANDLE_REDIRECT_START,
|
|
438
|
-
InteractionType.Redirect
|
|
439
|
-
);
|
|
440
|
-
eventHandler.emitEvent(EventType.LOGIN_START, InteractionType.Redirect);
|
|
441
|
-
eventHandler.emitEvent(
|
|
442
|
-
EventType.HANDLE_REDIRECT_END,
|
|
443
|
-
InteractionType.Redirect
|
|
444
|
-
);
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
it("automatically sets inProgress to None when handleRedirectPromise returns without emitting an event", (done) => {
|
|
448
|
-
const expectedInProgress = [
|
|
449
|
-
InteractionStatus.Startup,
|
|
450
|
-
InteractionStatus.None,
|
|
451
|
-
];
|
|
452
|
-
let index = 0;
|
|
453
|
-
|
|
454
|
-
subscription = broadcastService.inProgress$.subscribe((result) => {
|
|
455
|
-
expect(result).toEqual(expectedInProgress[index]);
|
|
456
|
-
if (index === expectedInProgress.length - 1) {
|
|
457
|
-
done();
|
|
458
|
-
} else if (expectedInProgress[index] === InteractionStatus.Startup) {
|
|
459
|
-
index++;
|
|
460
|
-
broadcastService.resetInProgressEvent();
|
|
461
|
-
} else {
|
|
462
|
-
index++;
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
eventHandler.emitEvent(
|
|
467
|
-
EventType.INITIALIZE_START,
|
|
468
|
-
InteractionType.Redirect
|
|
469
|
-
);
|
|
470
|
-
});
|
|
471
|
-
});
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Inject, Injectable, Optional } from "@angular/core";
|
|
7
|
-
import {
|
|
8
|
-
EventMessage,
|
|
9
|
-
EventMessageUtils,
|
|
10
|
-
IPublicClientApplication,
|
|
11
|
-
InteractionStatus,
|
|
12
|
-
} from "@azure/msal-browser";
|
|
13
|
-
import { BehaviorSubject, Observable, ReplaySubject, Subject } from "rxjs";
|
|
14
|
-
import { MsalBroadcastConfiguration } from "./msal.broadcast.config";
|
|
15
|
-
import { MSAL_BROADCAST_CONFIG, MSAL_INSTANCE } from "./constants";
|
|
16
|
-
import { name, version } from "./packageMetadata";
|
|
17
|
-
|
|
18
|
-
@Injectable()
|
|
19
|
-
export class MsalBroadcastService {
|
|
20
|
-
private _msalSubject: Subject<EventMessage>;
|
|
21
|
-
public msalSubject$: Observable<EventMessage>;
|
|
22
|
-
private _inProgress: BehaviorSubject<InteractionStatus>;
|
|
23
|
-
public inProgress$: Observable<InteractionStatus>;
|
|
24
|
-
|
|
25
|
-
constructor(
|
|
26
|
-
@Inject(MSAL_INSTANCE) private msalInstance: IPublicClientApplication,
|
|
27
|
-
@Optional()
|
|
28
|
-
@Inject(MSAL_BROADCAST_CONFIG)
|
|
29
|
-
private msalBroadcastConfig?: MsalBroadcastConfiguration
|
|
30
|
-
) {
|
|
31
|
-
// Make _msalSubject a ReplaySubject if configured to replay past events
|
|
32
|
-
if (
|
|
33
|
-
this.msalBroadcastConfig &&
|
|
34
|
-
this.msalBroadcastConfig.eventsToReplay > 0
|
|
35
|
-
) {
|
|
36
|
-
this.msalInstance
|
|
37
|
-
.getLogger()
|
|
38
|
-
.clone(name, version)
|
|
39
|
-
.verbose(
|
|
40
|
-
`BroadcastService - eventsToReplay set on BroadcastConfig, replaying the last ${this.msalBroadcastConfig.eventsToReplay} events`
|
|
41
|
-
);
|
|
42
|
-
this._msalSubject = new ReplaySubject<EventMessage>(
|
|
43
|
-
this.msalBroadcastConfig.eventsToReplay
|
|
44
|
-
);
|
|
45
|
-
} else {
|
|
46
|
-
// Defaults to _msalSubject being a Subject
|
|
47
|
-
this._msalSubject = new Subject<EventMessage>();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
this.msalSubject$ = this._msalSubject.asObservable();
|
|
51
|
-
|
|
52
|
-
// InProgress as BehaviorSubject so most recent inProgress state will be available upon subscription
|
|
53
|
-
this._inProgress = new BehaviorSubject<InteractionStatus>(
|
|
54
|
-
InteractionStatus.Startup
|
|
55
|
-
);
|
|
56
|
-
this.inProgress$ = this._inProgress.asObservable();
|
|
57
|
-
|
|
58
|
-
this.msalInstance.addEventCallback((message: EventMessage) => {
|
|
59
|
-
this._msalSubject.next(message);
|
|
60
|
-
const status = EventMessageUtils.getInteractionStatusFromEvent(
|
|
61
|
-
message,
|
|
62
|
-
this._inProgress.value
|
|
63
|
-
);
|
|
64
|
-
if (status !== null) {
|
|
65
|
-
this.msalInstance
|
|
66
|
-
.getLogger()
|
|
67
|
-
.clone(name, version)
|
|
68
|
-
.verbose(
|
|
69
|
-
`BroadcastService - ${message.eventType} results in setting inProgress from ${this._inProgress.value} to ${status}`
|
|
70
|
-
);
|
|
71
|
-
this._inProgress.next(status);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Resets inProgress state to None
|
|
78
|
-
*/
|
|
79
|
-
resetInProgressEvent(): void {
|
|
80
|
-
if (this._inProgress.value === InteractionStatus.Startup) {
|
|
81
|
-
this._inProgress.next(InteractionStatus.None);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
package/src/msal.guard.config.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { RouterStateSnapshot } from "@angular/router";
|
|
7
|
-
import {
|
|
8
|
-
PopupRequest,
|
|
9
|
-
RedirectRequest,
|
|
10
|
-
InteractionType,
|
|
11
|
-
} from "@azure/msal-browser";
|
|
12
|
-
import { MsalService } from "./msal.service";
|
|
13
|
-
|
|
14
|
-
export declare type MsalGuardAuthRequest =
|
|
15
|
-
| Partial<PopupRequest>
|
|
16
|
-
| Partial<Omit<RedirectRequest, "redirectStartPage">>;
|
|
17
|
-
|
|
18
|
-
export type MsalGuardConfiguration = {
|
|
19
|
-
interactionType: InteractionType.Popup | InteractionType.Redirect;
|
|
20
|
-
authRequest?:
|
|
21
|
-
| MsalGuardAuthRequest
|
|
22
|
-
| ((
|
|
23
|
-
authService: MsalService,
|
|
24
|
-
state: RouterStateSnapshot
|
|
25
|
-
) => MsalGuardAuthRequest);
|
|
26
|
-
loginFailedRoute?: string;
|
|
27
|
-
};
|