@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/msal.service.spec.ts
DELETED
|
@@ -1,468 +0,0 @@
|
|
|
1
|
-
import { TestBed } from "@angular/core/testing";
|
|
2
|
-
import {
|
|
3
|
-
AuthenticationResult,
|
|
4
|
-
AuthError,
|
|
5
|
-
InteractionStatus,
|
|
6
|
-
InteractionType,
|
|
7
|
-
Logger,
|
|
8
|
-
PublicClientApplication,
|
|
9
|
-
SilentRequest,
|
|
10
|
-
} from "@azure/msal-browser";
|
|
11
|
-
import { MsalModule, MsalBroadcastService, MsalService } from "./public-api";
|
|
12
|
-
import { takeLast } from "rxjs/operators";
|
|
13
|
-
|
|
14
|
-
let authService: MsalService;
|
|
15
|
-
let broadcastService: MsalBroadcastService;
|
|
16
|
-
|
|
17
|
-
const msalInstance = new PublicClientApplication({
|
|
18
|
-
auth: {
|
|
19
|
-
clientId: "b5c2e510-4a17-4feb-b219-e55aa5b74144",
|
|
20
|
-
redirectUri: "http://localhost:4200",
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
function initializeMsal() {
|
|
25
|
-
TestBed.resetTestingModule();
|
|
26
|
-
|
|
27
|
-
TestBed.configureTestingModule({
|
|
28
|
-
imports: [
|
|
29
|
-
MsalModule.forRoot(msalInstance, null, {
|
|
30
|
-
interactionType: InteractionType.Popup,
|
|
31
|
-
protectedResourceMap: new Map(),
|
|
32
|
-
}),
|
|
33
|
-
],
|
|
34
|
-
providers: [MsalService, MsalBroadcastService],
|
|
35
|
-
teardown: { destroyAfterEach: false },
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
authService = TestBed.inject(MsalService);
|
|
39
|
-
broadcastService = TestBed.inject(MsalBroadcastService);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe("MsalService", () => {
|
|
43
|
-
beforeEach(initializeMsal);
|
|
44
|
-
|
|
45
|
-
describe("loginPopup", () => {
|
|
46
|
-
it("success", (done) => {
|
|
47
|
-
const sampleIdToken = {
|
|
48
|
-
idToken: "123abc",
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
spyOn(PublicClientApplication.prototype, "loginPopup").and.returnValue(
|
|
52
|
-
new Promise((resolve) => {
|
|
53
|
-
//@ts-ignore
|
|
54
|
-
resolve(sampleIdToken);
|
|
55
|
-
})
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const request = {
|
|
59
|
-
scopes: ["user.read"],
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
authService
|
|
63
|
-
.loginPopup(request)
|
|
64
|
-
.subscribe((response: AuthenticationResult) => {
|
|
65
|
-
expect(response.idToken).toBe(sampleIdToken.idToken);
|
|
66
|
-
expect(
|
|
67
|
-
PublicClientApplication.prototype.loginPopup
|
|
68
|
-
).toHaveBeenCalledWith(request);
|
|
69
|
-
done();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("failure", (done) => {
|
|
74
|
-
const sampleError = new AuthError("123", "message");
|
|
75
|
-
|
|
76
|
-
spyOn(PublicClientApplication.prototype, "loginPopup").and.returnValue(
|
|
77
|
-
new Promise((resolve, reject) => {
|
|
78
|
-
reject(sampleError);
|
|
79
|
-
})
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const request = {
|
|
83
|
-
scopes: ["wrong.scope"],
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
authService.loginPopup(request).subscribe({
|
|
87
|
-
error: (error: AuthError) => {
|
|
88
|
-
expect(error.message).toBe(sampleError.message);
|
|
89
|
-
expect(
|
|
90
|
-
PublicClientApplication.prototype.loginPopup
|
|
91
|
-
).toHaveBeenCalledWith(request);
|
|
92
|
-
done();
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe("loginRedirect", () => {
|
|
99
|
-
it("success", async () => {
|
|
100
|
-
spyOn(PublicClientApplication.prototype, "loginRedirect").and.returnValue(
|
|
101
|
-
new Promise((resolve) => {
|
|
102
|
-
resolve();
|
|
103
|
-
})
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const request = {
|
|
107
|
-
scopes: ["user.read"],
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
await authService.loginRedirect(request);
|
|
111
|
-
|
|
112
|
-
expect(
|
|
113
|
-
PublicClientApplication.prototype.loginRedirect
|
|
114
|
-
).toHaveBeenCalled();
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe("logout", () => {
|
|
119
|
-
it("calls logout on msalService", async () => {
|
|
120
|
-
spyOn(PublicClientApplication.prototype, "logout").and.returnValue(
|
|
121
|
-
new Promise((resolve) => {
|
|
122
|
-
resolve();
|
|
123
|
-
})
|
|
124
|
-
);
|
|
125
|
-
await authService.logout();
|
|
126
|
-
expect(PublicClientApplication.prototype.logout).toHaveBeenCalled();
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe("logoutPopup", () => {
|
|
131
|
-
it("calls logoutPopup on msalService", async () => {
|
|
132
|
-
spyOn(PublicClientApplication.prototype, "logoutPopup").and.returnValue(
|
|
133
|
-
new Promise((resolve) => {
|
|
134
|
-
resolve();
|
|
135
|
-
})
|
|
136
|
-
);
|
|
137
|
-
await authService.logoutPopup();
|
|
138
|
-
expect(PublicClientApplication.prototype.logoutPopup).toHaveBeenCalled();
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe("logoutRedirect", () => {
|
|
143
|
-
it("calls logoutRedirect on msalService", async () => {
|
|
144
|
-
spyOn(
|
|
145
|
-
PublicClientApplication.prototype,
|
|
146
|
-
"logoutRedirect"
|
|
147
|
-
).and.returnValue(
|
|
148
|
-
new Promise((resolve) => {
|
|
149
|
-
resolve();
|
|
150
|
-
})
|
|
151
|
-
);
|
|
152
|
-
await authService.logoutRedirect();
|
|
153
|
-
expect(
|
|
154
|
-
PublicClientApplication.prototype.logoutRedirect
|
|
155
|
-
).toHaveBeenCalled();
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
describe("ssoSilent", () => {
|
|
160
|
-
it("success", (done) => {
|
|
161
|
-
const sampleIdToken = {
|
|
162
|
-
idToken: "id-token",
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
spyOn(PublicClientApplication.prototype, "ssoSilent").and.returnValue(
|
|
166
|
-
new Promise((resolve) => {
|
|
167
|
-
//@ts-ignore
|
|
168
|
-
resolve(sampleIdToken);
|
|
169
|
-
})
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
const request = {
|
|
173
|
-
scopes: ["user.read"],
|
|
174
|
-
loginHint: "name@example.com",
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
authService
|
|
178
|
-
.ssoSilent(request)
|
|
179
|
-
.subscribe((response: AuthenticationResult) => {
|
|
180
|
-
expect(response.idToken).toBe(sampleIdToken.idToken);
|
|
181
|
-
expect(
|
|
182
|
-
PublicClientApplication.prototype.ssoSilent
|
|
183
|
-
).toHaveBeenCalledWith(request);
|
|
184
|
-
done();
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it("failure", (done) => {
|
|
189
|
-
const sampleError = new AuthError("123", "message");
|
|
190
|
-
|
|
191
|
-
spyOn(PublicClientApplication.prototype, "ssoSilent").and.returnValue(
|
|
192
|
-
new Promise((resolve, reject) => {
|
|
193
|
-
reject(sampleError);
|
|
194
|
-
})
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
const request = {
|
|
198
|
-
scopes: ["user.read"],
|
|
199
|
-
loginHint: "name@example.com",
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
authService.ssoSilent(request).subscribe({
|
|
203
|
-
error: (error: AuthError) => {
|
|
204
|
-
expect(error.errorMessage).toBe(sampleError.errorMessage);
|
|
205
|
-
expect(
|
|
206
|
-
PublicClientApplication.prototype.ssoSilent
|
|
207
|
-
).toHaveBeenCalledWith(request);
|
|
208
|
-
done();
|
|
209
|
-
},
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
describe("acquireTokenSilent", () => {
|
|
215
|
-
it("success", (done) => {
|
|
216
|
-
const sampleAccessToken = {
|
|
217
|
-
accessToken: "123abc",
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
spyOn(
|
|
221
|
-
PublicClientApplication.prototype,
|
|
222
|
-
"acquireTokenSilent"
|
|
223
|
-
).and.returnValue(
|
|
224
|
-
new Promise((resolve) => {
|
|
225
|
-
//@ts-ignore
|
|
226
|
-
resolve(sampleAccessToken);
|
|
227
|
-
})
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
const request: SilentRequest = {
|
|
231
|
-
scopes: ["user.read"],
|
|
232
|
-
account: null,
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
authService
|
|
236
|
-
.acquireTokenSilent(request)
|
|
237
|
-
.subscribe((response: AuthenticationResult) => {
|
|
238
|
-
expect(response.accessToken).toBe(sampleAccessToken.accessToken);
|
|
239
|
-
expect(
|
|
240
|
-
PublicClientApplication.prototype.acquireTokenSilent
|
|
241
|
-
).toHaveBeenCalledWith(request);
|
|
242
|
-
done();
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it("failure", (done) => {
|
|
247
|
-
const sampleError = new AuthError("123", "message");
|
|
248
|
-
|
|
249
|
-
spyOn(
|
|
250
|
-
PublicClientApplication.prototype,
|
|
251
|
-
"acquireTokenSilent"
|
|
252
|
-
).and.returnValue(
|
|
253
|
-
new Promise((resolve, reject) => {
|
|
254
|
-
reject(sampleError);
|
|
255
|
-
})
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
const request: SilentRequest = {
|
|
259
|
-
scopes: ["wrong.scope"],
|
|
260
|
-
account: null,
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
authService.acquireTokenSilent(request).subscribe({
|
|
264
|
-
error: (error: AuthError) => {
|
|
265
|
-
expect(error.errorMessage).toBe(sampleError.errorMessage);
|
|
266
|
-
expect(
|
|
267
|
-
PublicClientApplication.prototype.acquireTokenSilent
|
|
268
|
-
).toHaveBeenCalledWith(request);
|
|
269
|
-
done();
|
|
270
|
-
},
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
describe("acquireTokenRedirect", () => {
|
|
276
|
-
it("success", async () => {
|
|
277
|
-
spyOn(
|
|
278
|
-
PublicClientApplication.prototype,
|
|
279
|
-
"acquireTokenRedirect"
|
|
280
|
-
).and.returnValue(
|
|
281
|
-
new Promise((resolve) => {
|
|
282
|
-
resolve();
|
|
283
|
-
})
|
|
284
|
-
);
|
|
285
|
-
|
|
286
|
-
await authService.acquireTokenRedirect({
|
|
287
|
-
scopes: ["user.read"],
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
expect(
|
|
291
|
-
PublicClientApplication.prototype.acquireTokenRedirect
|
|
292
|
-
).toHaveBeenCalled();
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
describe("acquireTokenPopup", () => {
|
|
297
|
-
it("success", (done) => {
|
|
298
|
-
const sampleAccessToken = {
|
|
299
|
-
accessToken: "123abc",
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
spyOn(
|
|
303
|
-
PublicClientApplication.prototype,
|
|
304
|
-
"acquireTokenPopup"
|
|
305
|
-
).and.returnValue(
|
|
306
|
-
new Promise((resolve) => {
|
|
307
|
-
//@ts-ignore
|
|
308
|
-
resolve(sampleAccessToken);
|
|
309
|
-
})
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
const request = {
|
|
313
|
-
scopes: ["user.read"],
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
authService
|
|
317
|
-
.acquireTokenPopup(request)
|
|
318
|
-
.subscribe((response: AuthenticationResult) => {
|
|
319
|
-
expect(response.accessToken).toBe(sampleAccessToken.accessToken);
|
|
320
|
-
expect(
|
|
321
|
-
PublicClientApplication.prototype.acquireTokenPopup
|
|
322
|
-
).toHaveBeenCalledWith(request);
|
|
323
|
-
done();
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
it("failure", (done) => {
|
|
328
|
-
const sampleError = new AuthError("123", "message");
|
|
329
|
-
|
|
330
|
-
spyOn(
|
|
331
|
-
PublicClientApplication.prototype,
|
|
332
|
-
"acquireTokenPopup"
|
|
333
|
-
).and.returnValue(
|
|
334
|
-
new Promise((resolve, reject) => {
|
|
335
|
-
reject(sampleError);
|
|
336
|
-
})
|
|
337
|
-
);
|
|
338
|
-
|
|
339
|
-
const request = {
|
|
340
|
-
scopes: ["wrong.scope"],
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
authService.acquireTokenPopup(request).subscribe({
|
|
344
|
-
error: (error: AuthError) => {
|
|
345
|
-
expect(error.errorMessage).toBe(sampleError.errorMessage);
|
|
346
|
-
expect(
|
|
347
|
-
PublicClientApplication.prototype.acquireTokenPopup
|
|
348
|
-
).toHaveBeenCalledWith(request);
|
|
349
|
-
done();
|
|
350
|
-
},
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
describe("handleRedirectObservable", () => {
|
|
356
|
-
it("success and resets inProgress event to none", (done) => {
|
|
357
|
-
const sampleAccessToken = {
|
|
358
|
-
accessToken: "123abc",
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
//@ts-ignore
|
|
362
|
-
broadcastService._inProgress.next(InteractionStatus.Startup);
|
|
363
|
-
|
|
364
|
-
spyOn(PublicClientApplication.prototype, "initialize").and.returnValue(
|
|
365
|
-
Promise.resolve()
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
spyOn(
|
|
369
|
-
PublicClientApplication.prototype,
|
|
370
|
-
"handleRedirectPromise"
|
|
371
|
-
).and.returnValue(
|
|
372
|
-
new Promise((resolve) => {
|
|
373
|
-
//@ts-ignore
|
|
374
|
-
resolve(sampleAccessToken);
|
|
375
|
-
})
|
|
376
|
-
);
|
|
377
|
-
|
|
378
|
-
authService
|
|
379
|
-
.handleRedirectObservable()
|
|
380
|
-
.subscribe((response: AuthenticationResult) => {
|
|
381
|
-
expect(response.accessToken).toBe(sampleAccessToken.accessToken);
|
|
382
|
-
expect(
|
|
383
|
-
PublicClientApplication.prototype.initialize
|
|
384
|
-
).toHaveBeenCalled();
|
|
385
|
-
expect(
|
|
386
|
-
PublicClientApplication.prototype.handleRedirectPromise
|
|
387
|
-
).toHaveBeenCalled();
|
|
388
|
-
broadcastService.inProgress$.subscribe((result) => {
|
|
389
|
-
expect(result).toBe(InteractionStatus.None);
|
|
390
|
-
});
|
|
391
|
-
done();
|
|
392
|
-
});
|
|
393
|
-
});
|
|
394
|
-
|
|
395
|
-
it("failure and also resets inProgress event to none", (done) => {
|
|
396
|
-
const sampleError = new AuthError("123", "message");
|
|
397
|
-
|
|
398
|
-
//@ts-ignore
|
|
399
|
-
broadcastService._inProgress.next(InteractionStatus.Startup);
|
|
400
|
-
|
|
401
|
-
spyOn(PublicClientApplication.prototype, "initialize").and.returnValue(
|
|
402
|
-
Promise.resolve()
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
spyOn(
|
|
406
|
-
PublicClientApplication.prototype,
|
|
407
|
-
"handleRedirectPromise"
|
|
408
|
-
).and.returnValue(
|
|
409
|
-
new Promise((resolve, reject) => {
|
|
410
|
-
reject(sampleError);
|
|
411
|
-
})
|
|
412
|
-
);
|
|
413
|
-
|
|
414
|
-
authService.handleRedirectObservable().subscribe({
|
|
415
|
-
error: (error: AuthError) => {
|
|
416
|
-
expect(error.message).toBe(sampleError.message);
|
|
417
|
-
expect(
|
|
418
|
-
PublicClientApplication.prototype.initialize
|
|
419
|
-
).toHaveBeenCalled();
|
|
420
|
-
expect(
|
|
421
|
-
PublicClientApplication.prototype.handleRedirectPromise
|
|
422
|
-
).toHaveBeenCalled();
|
|
423
|
-
broadcastService.inProgress$.pipe(takeLast(1)).subscribe((result) => {
|
|
424
|
-
console.log("failure result", result);
|
|
425
|
-
expect(result).toBe(InteractionStatus.None);
|
|
426
|
-
});
|
|
427
|
-
done();
|
|
428
|
-
},
|
|
429
|
-
});
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
it("called with hash", (done) => {
|
|
433
|
-
const sampleAccessToken = {
|
|
434
|
-
accessToken: "123abc",
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
const hash = "#/test";
|
|
438
|
-
|
|
439
|
-
spyOn(
|
|
440
|
-
PublicClientApplication.prototype,
|
|
441
|
-
"handleRedirectPromise"
|
|
442
|
-
).and.returnValue(
|
|
443
|
-
new Promise((resolve) => {
|
|
444
|
-
//@ts-ignore
|
|
445
|
-
resolve(sampleAccessToken);
|
|
446
|
-
})
|
|
447
|
-
);
|
|
448
|
-
|
|
449
|
-
authService
|
|
450
|
-
.handleRedirectObservable(hash)
|
|
451
|
-
.subscribe((response: AuthenticationResult) => {
|
|
452
|
-
expect(response.accessToken).toBe(sampleAccessToken.accessToken);
|
|
453
|
-
expect(
|
|
454
|
-
PublicClientApplication.prototype.handleRedirectPromise
|
|
455
|
-
).toHaveBeenCalledWith(hash);
|
|
456
|
-
done();
|
|
457
|
-
});
|
|
458
|
-
});
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
describe("setLogger", () => {
|
|
462
|
-
it("works", () => {
|
|
463
|
-
spyOn(PublicClientApplication.prototype, "setLogger");
|
|
464
|
-
authService.setLogger(new Logger({}));
|
|
465
|
-
expect(PublicClientApplication.prototype.setLogger).toHaveBeenCalled();
|
|
466
|
-
});
|
|
467
|
-
});
|
|
468
|
-
});
|
package/src/msal.service.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Inject, Injectable, Injector } from "@angular/core";
|
|
7
|
-
import { Location } from "@angular/common";
|
|
8
|
-
import {
|
|
9
|
-
IPublicClientApplication,
|
|
10
|
-
EndSessionRequest,
|
|
11
|
-
EndSessionPopupRequest,
|
|
12
|
-
AuthenticationResult,
|
|
13
|
-
RedirectRequest,
|
|
14
|
-
SilentRequest,
|
|
15
|
-
PopupRequest,
|
|
16
|
-
SsoSilentRequest,
|
|
17
|
-
Logger,
|
|
18
|
-
WrapperSKU,
|
|
19
|
-
} from "@azure/msal-browser";
|
|
20
|
-
import { Observable, from } from "rxjs";
|
|
21
|
-
import { IMsalService } from "./IMsalService";
|
|
22
|
-
import { name, version } from "./packageMetadata";
|
|
23
|
-
import { MSAL_INSTANCE } from "./constants";
|
|
24
|
-
import { MsalBroadcastService } from "./msal.broadcast.service";
|
|
25
|
-
|
|
26
|
-
@Injectable()
|
|
27
|
-
export class MsalService implements IMsalService {
|
|
28
|
-
private redirectHash: string;
|
|
29
|
-
private logger: Logger;
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
32
|
-
@Inject(MSAL_INSTANCE) public instance: IPublicClientApplication,
|
|
33
|
-
private location: Location,
|
|
34
|
-
private injector: Injector
|
|
35
|
-
) {
|
|
36
|
-
const hash = this.location.path(true).split("#").pop();
|
|
37
|
-
if (hash) {
|
|
38
|
-
this.redirectHash = `#${hash}`;
|
|
39
|
-
}
|
|
40
|
-
this.instance.initializeWrapperLibrary(WrapperSKU.Angular, version);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
initialize(): Observable<void> {
|
|
44
|
-
return from(this.instance.initialize());
|
|
45
|
-
}
|
|
46
|
-
acquireTokenPopup(request: PopupRequest): Observable<AuthenticationResult> {
|
|
47
|
-
return from(this.instance.acquireTokenPopup(request));
|
|
48
|
-
}
|
|
49
|
-
acquireTokenRedirect(request: RedirectRequest): Observable<void> {
|
|
50
|
-
return from(this.instance.acquireTokenRedirect(request));
|
|
51
|
-
}
|
|
52
|
-
acquireTokenSilent(
|
|
53
|
-
silentRequest: SilentRequest
|
|
54
|
-
): Observable<AuthenticationResult> {
|
|
55
|
-
return from(this.instance.acquireTokenSilent(silentRequest));
|
|
56
|
-
}
|
|
57
|
-
handleRedirectObservable(hash?: string): Observable<AuthenticationResult> {
|
|
58
|
-
return from(
|
|
59
|
-
this.instance
|
|
60
|
-
.initialize()
|
|
61
|
-
.then(() =>
|
|
62
|
-
this.instance.handleRedirectPromise(hash || this.redirectHash)
|
|
63
|
-
)
|
|
64
|
-
.finally(() => {
|
|
65
|
-
// update inProgress state to none
|
|
66
|
-
this.injector.get(MsalBroadcastService).resetInProgressEvent();
|
|
67
|
-
})
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
loginPopup(request?: PopupRequest): Observable<AuthenticationResult> {
|
|
71
|
-
return from(this.instance.loginPopup(request));
|
|
72
|
-
}
|
|
73
|
-
loginRedirect(request?: RedirectRequest): Observable<void> {
|
|
74
|
-
return from(this.instance.loginRedirect(request));
|
|
75
|
-
}
|
|
76
|
-
// @deprecated: Use logoutRedirect or logoutPopup
|
|
77
|
-
logout(logoutRequest?: EndSessionRequest): Observable<void> {
|
|
78
|
-
return from(this.instance.logout(logoutRequest));
|
|
79
|
-
}
|
|
80
|
-
logoutRedirect(logoutRequest?: EndSessionRequest): Observable<void> {
|
|
81
|
-
return from(this.instance.logoutRedirect(logoutRequest));
|
|
82
|
-
}
|
|
83
|
-
logoutPopup(logoutRequest?: EndSessionPopupRequest): Observable<void> {
|
|
84
|
-
return from(this.instance.logoutPopup(logoutRequest));
|
|
85
|
-
}
|
|
86
|
-
ssoSilent(request: SsoSilentRequest): Observable<AuthenticationResult> {
|
|
87
|
-
return from(this.instance.ssoSilent(request));
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Gets logger for msal-angular.
|
|
91
|
-
* If no logger set, returns logger instance created with same options as msal-browser
|
|
92
|
-
*/
|
|
93
|
-
getLogger(): Logger {
|
|
94
|
-
if (!this.logger) {
|
|
95
|
-
this.logger = this.instance.getLogger().clone(name, version);
|
|
96
|
-
}
|
|
97
|
-
return this.logger;
|
|
98
|
-
}
|
|
99
|
-
// Create a logger instance for msal-angular with the same options as msal-browser
|
|
100
|
-
setLogger(logger: Logger): void {
|
|
101
|
-
this.logger = logger.clone(name, version);
|
|
102
|
-
this.instance.setLogger(logger);
|
|
103
|
-
}
|
|
104
|
-
}
|
package/src/packageMetadata.ts
DELETED
package/src/test.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import "zone.js/dist/zone";
|
|
7
|
-
import "zone.js/dist/zone-testing";
|
|
8
|
-
// eslint-disable-next-line import/no-unresolved
|
|
9
|
-
import { getTestBed } from "@angular/core/testing";
|
|
10
|
-
import {
|
|
11
|
-
BrowserDynamicTestingModule,
|
|
12
|
-
platformBrowserDynamicTesting,
|
|
13
|
-
} from "@angular/platform-browser-dynamic/testing"; // eslint-disable-line import/no-unresolved
|
|
14
|
-
|
|
15
|
-
// First, initialize the Angular testing environment.
|
|
16
|
-
getTestBed().initTestEnvironment(
|
|
17
|
-
BrowserDynamicTestingModule,
|
|
18
|
-
platformBrowserDynamicTesting()
|
|
19
|
-
);
|
package/tsconfig.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compileOnSave": false,
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"baseUrl": "./",
|
|
5
|
-
"outDir": "./dist/out-tsc",
|
|
6
|
-
"sourceMap": true,
|
|
7
|
-
"declaration": false,
|
|
8
|
-
"downlevelIteration": true,
|
|
9
|
-
"experimentalDecorators": true,
|
|
10
|
-
"moduleResolution": "node",
|
|
11
|
-
"importHelpers": true,
|
|
12
|
-
"target": "es2020",
|
|
13
|
-
"module": "es2020",
|
|
14
|
-
"lib": [
|
|
15
|
-
"ES2020",
|
|
16
|
-
"dom"
|
|
17
|
-
],
|
|
18
|
-
"paths": {
|
|
19
|
-
"msal-angular": [
|
|
20
|
-
"dist/msal-angular"
|
|
21
|
-
]
|
|
22
|
-
},
|
|
23
|
-
"useDefineForClassFields": false
|
|
24
|
-
}
|
|
25
|
-
}
|
package/tsconfig.lib.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "./tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "./out-tsc/lib",
|
|
6
|
-
"declarationMap": true,
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"inlineSources": true,
|
|
9
|
-
"types": [],
|
|
10
|
-
"lib": [
|
|
11
|
-
"dom",
|
|
12
|
-
"ES2020"
|
|
13
|
-
]
|
|
14
|
-
},
|
|
15
|
-
"angularCompilerOptions": {
|
|
16
|
-
"enableResourceInlining": true,
|
|
17
|
-
"genDir": "dist",
|
|
18
|
-
"debug": false,
|
|
19
|
-
"skipTemplateCodegen": true,
|
|
20
|
-
"skipMetadataEmit": false,
|
|
21
|
-
"strictMetadataEmit": true
|
|
22
|
-
},
|
|
23
|
-
"exclude": [
|
|
24
|
-
"src/test.ts",
|
|
25
|
-
"**/*.spec.ts"
|
|
26
|
-
]
|
|
27
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "./tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "./out-tsc/spec",
|
|
6
|
-
"types": [
|
|
7
|
-
"jasmine"
|
|
8
|
-
]
|
|
9
|
-
},
|
|
10
|
-
"files": [
|
|
11
|
-
"src/test.ts"
|
|
12
|
-
],
|
|
13
|
-
"include": [
|
|
14
|
-
"**/*.spec.ts",
|
|
15
|
-
"**/*.d.ts"
|
|
16
|
-
]
|
|
17
|
-
}
|