@azure/msal-angular 4.0.11 → 4.0.13
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/.beachballrc +3 -0
- package/.editorconfig +16 -0
- package/.eslintrc.json +3 -0
- package/CHANGELOG.json +2315 -0
- package/CHANGELOG.md +869 -0
- package/FAQ.md +182 -0
- package/angular.json +51 -0
- package/docs/angular-universal.md +64 -0
- package/docs/configuration.md +609 -0
- package/docs/errors.md +89 -0
- package/docs/events.md +262 -0
- package/docs/initialization.md +206 -0
- package/docs/known-issues.md +19 -0
- package/docs/logging.md +47 -0
- package/docs/msal-guard.md +208 -0
- package/docs/msal-interceptor.md +160 -0
- package/docs/multi-tenant.md +90 -0
- package/docs/performance.md +50 -0
- package/docs/public-apis.md +29 -0
- package/docs/redirects.md +257 -0
- package/docs/security.md +4 -0
- package/docs/ssosilent.md +84 -0
- package/docs/v0-v1-upgrade-guide.md +61 -0
- package/docs/v1-v2-upgrade-guide.md +70 -0
- package/docs/v2-v3-upgrade-guide.md +52 -0
- package/docs/v3-v4-upgrade-guide.md +36 -0
- package/karma.conf.js +44 -0
- package/ng-package.json +7 -0
- package/package.json +56 -26
- package/src/IMsalService.ts +34 -0
- package/src/constants.ts +20 -0
- package/src/msal.broadcast.config.ts +8 -0
- package/src/msal.broadcast.service.spec.ts +471 -0
- package/src/msal.broadcast.service.ts +84 -0
- package/src/msal.guard.config.ts +27 -0
- package/src/msal.guard.spec.ts +525 -0
- package/src/msal.guard.ts +290 -0
- package/src/msal.interceptor.config.ts +39 -0
- package/src/msal.interceptor.spec.ts +1168 -0
- package/src/msal.interceptor.ts +388 -0
- package/src/msal.module.ts +51 -0
- package/src/msal.navigation.client.spec.ts +96 -0
- package/src/msal.navigation.client.ts +59 -0
- package/src/msal.redirect.component.spec.ts +64 -0
- package/src/msal.redirect.component.ts +26 -0
- package/src/msal.service.spec.ts +468 -0
- package/src/msal.service.ts +104 -0
- package/src/packageMetadata.ts +3 -0
- package/{public-api.d.ts → src/public-api.ts} +35 -17
- package/src/test.ts +19 -0
- package/tsconfig.json +25 -0
- package/tsconfig.lib.json +27 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +17 -0
- package/typedoc.json +10 -0
- package/IMsalService.d.ts +0 -17
- package/constants.d.ts +0 -5
- package/esm2020/IMsalService.mjs +0 -6
- package/esm2020/azure-msal-angular.mjs +0 -5
- package/esm2020/constants.mjs +0 -10
- package/esm2020/msal.broadcast.config.mjs +0 -6
- package/esm2020/msal.broadcast.service.mjs +0 -66
- package/esm2020/msal.guard.config.mjs +0 -6
- package/esm2020/msal.guard.mjs +0 -218
- package/esm2020/msal.interceptor.config.mjs +0 -6
- package/esm2020/msal.interceptor.mjs +0 -270
- package/esm2020/msal.module.mjs +0 -46
- package/esm2020/msal.navigation.client.mjs +0 -53
- package/esm2020/msal.redirect.component.mjs +0 -31
- package/esm2020/msal.service.mjs +0 -88
- package/esm2020/packageMetadata.mjs +0 -4
- package/esm2020/public-api.mjs +0 -18
- package/fesm2015/azure-msal-angular.mjs +0 -762
- package/fesm2015/azure-msal-angular.mjs.map +0 -1
- package/fesm2020/azure-msal-angular.mjs +0 -758
- package/fesm2020/azure-msal-angular.mjs.map +0 -1
- package/index.d.ts +0 -5
- package/msal.broadcast.config.d.ts +0 -3
- package/msal.broadcast.service.d.ts +0 -19
- package/msal.guard.config.d.ts +0 -9
- package/msal.guard.d.ts +0 -43
- package/msal.interceptor.config.d.ts +0 -13
- package/msal.interceptor.d.ts +0 -70
- package/msal.module.d.ts +0 -13
- package/msal.navigation.client.d.ts +0 -19
- package/msal.redirect.component.d.ts +0 -15
- package/msal.service.d.ts +0 -33
- package/packageMetadata.d.ts +0 -2
|
@@ -0,0 +1,468 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
}
|
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
* @module @azure/msal-angular
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export { MsalService } from "./msal.service";
|
|
12
|
+
export { IMsalService } from "./IMsalService";
|
|
13
|
+
export { MsalGuard } from "./msal.guard";
|
|
14
|
+
export {
|
|
15
|
+
MsalGuardConfiguration,
|
|
16
|
+
MsalGuardAuthRequest,
|
|
17
|
+
} from "./msal.guard.config";
|
|
18
|
+
export { MsalInterceptor } from "./msal.interceptor";
|
|
19
|
+
export {
|
|
20
|
+
MsalInterceptorConfiguration,
|
|
21
|
+
MsalInterceptorAuthRequest,
|
|
22
|
+
ProtectedResourceScopes,
|
|
23
|
+
} from "./msal.interceptor.config";
|
|
24
|
+
export {
|
|
25
|
+
MSAL_INSTANCE,
|
|
26
|
+
MSAL_GUARD_CONFIG,
|
|
27
|
+
MSAL_INTERCEPTOR_CONFIG,
|
|
28
|
+
MSAL_BROADCAST_CONFIG,
|
|
29
|
+
} from "./constants";
|
|
30
|
+
export { MsalBroadcastService } from "./msal.broadcast.service";
|
|
31
|
+
export { MsalBroadcastConfiguration } from "./msal.broadcast.config";
|
|
32
|
+
export { MsalModule } from "./msal.module";
|
|
33
|
+
export { MsalRedirectComponent } from "./msal.redirect.component";
|
|
34
|
+
export { MsalCustomNavigationClient } from "./msal.navigation.client";
|
|
35
|
+
export { version } from "./packageMetadata";
|
package/src/test.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|