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