@azure/msal-node 1.14.4 → 1.14.6
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/dist/cache/serializer/Deserializer.d.ts.map +1 -1
- package/dist/cache/serializer/Serializer.d.ts.map +1 -1
- package/dist/cache/serializer/SerializerTypes.d.ts +1 -0
- package/dist/cache/serializer/SerializerTypes.d.ts.map +1 -1
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/msal-node.cjs.development.js +138 -504
- package/dist/msal-node.cjs.development.js.map +1 -1
- package/dist/msal-node.cjs.production.min.js +1 -1
- package/dist/msal-node.cjs.production.min.js.map +1 -1
- package/dist/msal-node.esm.js +138 -504
- package/dist/msal-node.esm.js.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/package.json +3 -3
|
@@ -16,19 +16,15 @@ var jsonwebtoken = require('jsonwebtoken');
|
|
|
16
16
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
17
17
|
* Licensed under the MIT License.
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
19
|
/**
|
|
21
20
|
* http methods
|
|
22
21
|
*/
|
|
23
22
|
var HttpMethod;
|
|
24
|
-
|
|
25
23
|
(function (HttpMethod) {
|
|
26
24
|
HttpMethod["GET"] = "get";
|
|
27
25
|
HttpMethod["POST"] = "post";
|
|
28
26
|
})(HttpMethod || (HttpMethod = {}));
|
|
29
|
-
|
|
30
27
|
var HttpStatus;
|
|
31
|
-
|
|
32
28
|
(function (HttpStatus) {
|
|
33
29
|
HttpStatus[HttpStatus["SUCCESS_RANGE_START"] = 200] = "SUCCESS_RANGE_START";
|
|
34
30
|
HttpStatus[HttpStatus["SUCCESS_RANGE_END"] = 299] = "SUCCESS_RANGE_END";
|
|
@@ -38,9 +34,7 @@ var HttpStatus;
|
|
|
38
34
|
HttpStatus[HttpStatus["SERVER_ERROR_RANGE_START"] = 500] = "SERVER_ERROR_RANGE_START";
|
|
39
35
|
HttpStatus[HttpStatus["SERVER_ERROR_RANGE_END"] = 599] = "SERVER_ERROR_RANGE_END";
|
|
40
36
|
})(HttpStatus || (HttpStatus = {}));
|
|
41
|
-
|
|
42
37
|
var ProxyStatus;
|
|
43
|
-
|
|
44
38
|
(function (ProxyStatus) {
|
|
45
39
|
ProxyStatus[ProxyStatus["SUCCESS_RANGE_START"] = 200] = "SUCCESS_RANGE_START";
|
|
46
40
|
ProxyStatus[ProxyStatus["SUCCESS_RANGE_END"] = 299] = "SUCCESS_RANGE_END";
|
|
@@ -49,32 +43,26 @@ var ProxyStatus;
|
|
|
49
43
|
/**
|
|
50
44
|
* Constants used for region discovery
|
|
51
45
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
46
|
const REGION_ENVIRONMENT_VARIABLE = "REGION_NAME";
|
|
55
47
|
/**
|
|
56
48
|
* Constant used for PKCE
|
|
57
49
|
*/
|
|
58
|
-
|
|
59
50
|
const RANDOM_OCTET_SIZE = 32;
|
|
60
51
|
/**
|
|
61
52
|
* Constants used in PKCE
|
|
62
53
|
*/
|
|
63
|
-
|
|
64
54
|
const Hash = {
|
|
65
55
|
SHA256: "sha256"
|
|
66
56
|
};
|
|
67
57
|
/**
|
|
68
58
|
* Constants for encoding schemes
|
|
69
59
|
*/
|
|
70
|
-
|
|
71
60
|
const CharSet = {
|
|
72
61
|
CV_CHARSET: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
|
|
73
62
|
};
|
|
74
63
|
/**
|
|
75
64
|
* Constants
|
|
76
65
|
*/
|
|
77
|
-
|
|
78
66
|
const Constants = {
|
|
79
67
|
MSAL_SKU: "msal.js.node",
|
|
80
68
|
JWT_BEARER_ASSERTION_TYPE: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
|
|
@@ -89,9 +77,7 @@ const Constants = {
|
|
|
89
77
|
* 600-699 Device Code Flow
|
|
90
78
|
* 800-899 Auth Code Flow
|
|
91
79
|
*/
|
|
92
|
-
|
|
93
80
|
var ApiId;
|
|
94
|
-
|
|
95
81
|
(function (ApiId) {
|
|
96
82
|
ApiId[ApiId["acquireTokenSilent"] = 62] = "acquireTokenSilent";
|
|
97
83
|
ApiId[ApiId["acquireTokenByUsernamePassword"] = 371] = "acquireTokenByUsernamePassword";
|
|
@@ -103,8 +89,6 @@ var ApiId;
|
|
|
103
89
|
/**
|
|
104
90
|
* JWT constants
|
|
105
91
|
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
92
|
const JwtConstants = {
|
|
109
93
|
ALGORITHM: "alg",
|
|
110
94
|
RSA_256: "RS256",
|
|
@@ -134,7 +118,6 @@ class NetworkUtils {
|
|
|
134
118
|
status: statusCode
|
|
135
119
|
};
|
|
136
120
|
}
|
|
137
|
-
|
|
138
121
|
}
|
|
139
122
|
|
|
140
123
|
/*
|
|
@@ -144,7 +127,6 @@ class NetworkUtils {
|
|
|
144
127
|
/**
|
|
145
128
|
* This class implements the API for network requests.
|
|
146
129
|
*/
|
|
147
|
-
|
|
148
130
|
class HttpClient {
|
|
149
131
|
/**
|
|
150
132
|
* Http Get request
|
|
@@ -163,8 +145,6 @@ class HttpClient {
|
|
|
163
145
|
* @param url
|
|
164
146
|
* @param options
|
|
165
147
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
148
|
async sendPostRequestAsync(url, options, cancellationToken) {
|
|
169
149
|
if (options != null && options.proxyUrl) {
|
|
170
150
|
return networkRequestViaProxy(url, HttpMethod.POST, options, cancellationToken);
|
|
@@ -172,14 +152,12 @@ class HttpClient {
|
|
|
172
152
|
return networkRequestViaHttps(url, HttpMethod.POST, options, cancellationToken);
|
|
173
153
|
}
|
|
174
154
|
}
|
|
175
|
-
|
|
176
155
|
}
|
|
177
|
-
|
|
178
156
|
const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
|
|
179
157
|
const headers = (options == null ? void 0 : options.headers) || {};
|
|
180
158
|
const proxyUrl = new URL((options == null ? void 0 : options.proxyUrl) || "");
|
|
181
|
-
const destinationUrl = new URL(url);
|
|
182
|
-
|
|
159
|
+
const destinationUrl = new URL(url);
|
|
160
|
+
// "method: connect" must be used to establish a connection to the proxy
|
|
183
161
|
const tunnelRequestOptions = {
|
|
184
162
|
host: proxyUrl.hostname,
|
|
185
163
|
port: proxyUrl.port,
|
|
@@ -187,41 +165,33 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
|
|
|
187
165
|
path: destinationUrl.hostname,
|
|
188
166
|
headers: headers
|
|
189
167
|
};
|
|
190
|
-
|
|
191
168
|
if (timeout) {
|
|
192
169
|
tunnelRequestOptions.timeout = timeout;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
170
|
+
}
|
|
171
|
+
// compose a request string for the socket
|
|
196
172
|
let postRequestStringContent = "";
|
|
197
|
-
|
|
198
173
|
if (httpMethod === HttpMethod.POST) {
|
|
199
174
|
const body = (options == null ? void 0 : options.body) || "";
|
|
200
175
|
postRequestStringContent = "Content-Type: application/x-www-form-urlencoded\r\n" + `Content-Length: ${body.length}\r\n` + `\r\n${body}`;
|
|
201
176
|
}
|
|
202
|
-
|
|
203
177
|
const outgoingRequestString = `${httpMethod.toUpperCase()} ${destinationUrl.href} HTTP/1.1\r\n` + `Host: ${destinationUrl.host}\r\n` + "Connection: close\r\n" + postRequestStringContent + "\r\n";
|
|
204
178
|
return new Promise((resolve, reject) => {
|
|
205
179
|
const request = http__default.request(tunnelRequestOptions);
|
|
206
|
-
|
|
207
180
|
if (tunnelRequestOptions.timeout) {
|
|
208
181
|
request.on("timeout", () => {
|
|
209
182
|
request.destroy();
|
|
210
183
|
reject(new Error("Request time out"));
|
|
211
184
|
});
|
|
212
185
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
186
|
+
request.end();
|
|
187
|
+
// establish connection to the proxy
|
|
216
188
|
request.on("connect", (response, socket) => {
|
|
217
189
|
const proxyStatusCode = (response == null ? void 0 : response.statusCode) || ProxyStatus.SERVER_ERROR;
|
|
218
|
-
|
|
219
190
|
if (proxyStatusCode < ProxyStatus.SUCCESS_RANGE_START || proxyStatusCode > ProxyStatus.SUCCESS_RANGE_END) {
|
|
220
191
|
request.destroy();
|
|
221
192
|
socket.destroy();
|
|
222
193
|
reject(new Error(`Error connecting to proxy. Http status code: ${response.statusCode}. Http status message: ${(response == null ? void 0 : response.statusMessage) || "Unknown"}`));
|
|
223
194
|
}
|
|
224
|
-
|
|
225
195
|
if (tunnelRequestOptions.timeout) {
|
|
226
196
|
socket.setTimeout(tunnelRequestOptions.timeout);
|
|
227
197
|
socket.on("timeout", () => {
|
|
@@ -229,9 +199,8 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
|
|
|
229
199
|
socket.destroy();
|
|
230
200
|
reject(new Error("Request time out"));
|
|
231
201
|
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
202
|
+
}
|
|
203
|
+
// make a request over an HTTP tunnel
|
|
235
204
|
socket.write(outgoingRequestString);
|
|
236
205
|
const data = [];
|
|
237
206
|
socket.on("data", chunk => {
|
|
@@ -239,18 +208,18 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
|
|
|
239
208
|
});
|
|
240
209
|
socket.on("end", () => {
|
|
241
210
|
// combine all received buffer streams into one buffer, and then into a string
|
|
242
|
-
const dataString = Buffer.concat([...data]).toString();
|
|
243
|
-
|
|
244
|
-
const dataStringArray = dataString.split("\r\n");
|
|
245
|
-
|
|
246
|
-
const httpStatusCode = parseInt(dataStringArray[0].split(" ")[1]);
|
|
247
|
-
|
|
248
|
-
const statusMessage = dataStringArray[0].split(" ").slice(2).join(" ");
|
|
249
|
-
|
|
250
|
-
const body = dataStringArray[dataStringArray.length - 1];
|
|
251
|
-
|
|
252
|
-
const headersArray = dataStringArray.slice(1, dataStringArray.length - 2);
|
|
253
|
-
|
|
211
|
+
const dataString = Buffer.concat([...data]).toString();
|
|
212
|
+
// separate each line into it's own entry in an arry
|
|
213
|
+
const dataStringArray = dataString.split("\r\n");
|
|
214
|
+
// the first entry will contain the statusCode and statusMessage
|
|
215
|
+
const httpStatusCode = parseInt(dataStringArray[0].split(" ")[1]);
|
|
216
|
+
// remove "HTTP/1.1" and the status code to get the status message
|
|
217
|
+
const statusMessage = dataStringArray[0].split(" ").slice(2).join(" ");
|
|
218
|
+
// the last entry will contain the body
|
|
219
|
+
const body = dataStringArray[dataStringArray.length - 1];
|
|
220
|
+
// everything in between the first and last entries are the headers
|
|
221
|
+
const headersArray = dataStringArray.slice(1, dataStringArray.length - 2);
|
|
222
|
+
// build an object out of all the headers
|
|
254
223
|
const entries = new Map();
|
|
255
224
|
headersArray.forEach(header => {
|
|
256
225
|
/**
|
|
@@ -261,28 +230,27 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
|
|
|
261
230
|
*/
|
|
262
231
|
const headerKeyValue = header.split(new RegExp(/:\s(.*)/s));
|
|
263
232
|
const headerKey = headerKeyValue[0];
|
|
264
|
-
let headerValue = headerKeyValue[1];
|
|
265
|
-
|
|
233
|
+
let headerValue = headerKeyValue[1];
|
|
234
|
+
// check if the value of the header is supposed to be a JSON object
|
|
266
235
|
try {
|
|
267
|
-
const object = JSON.parse(headerValue);
|
|
268
|
-
|
|
236
|
+
const object = JSON.parse(headerValue);
|
|
237
|
+
// if it is, then convert it from a string to a JSON object
|
|
269
238
|
if (object && typeof object === "object") {
|
|
270
239
|
headerValue = object;
|
|
271
240
|
}
|
|
272
|
-
} catch (e) {
|
|
241
|
+
} catch (e) {
|
|
242
|
+
// otherwise, leave it as a string
|
|
273
243
|
}
|
|
274
|
-
|
|
275
244
|
entries.set(headerKey, headerValue);
|
|
276
245
|
});
|
|
277
246
|
const headers = Object.fromEntries(entries);
|
|
278
247
|
const parsedHeaders = headers;
|
|
279
248
|
const networkResponse = NetworkUtils.getNetworkResponse(parsedHeaders, parseBody(httpStatusCode, statusMessage, parsedHeaders, body), httpStatusCode);
|
|
280
|
-
|
|
281
|
-
|
|
249
|
+
if ((httpStatusCode < HttpStatus.SUCCESS_RANGE_START || httpStatusCode > HttpStatus.SUCCESS_RANGE_END) &&
|
|
250
|
+
// do not destroy the request for the device code flow
|
|
282
251
|
networkResponse.body["error"] !== Constants.AUTHORIZATION_PENDING) {
|
|
283
252
|
request.destroy();
|
|
284
253
|
}
|
|
285
|
-
|
|
286
254
|
resolve(networkResponse);
|
|
287
255
|
});
|
|
288
256
|
socket.on("error", chunk => {
|
|
@@ -297,7 +265,6 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
|
|
|
297
265
|
});
|
|
298
266
|
});
|
|
299
267
|
};
|
|
300
|
-
|
|
301
268
|
const networkRequestViaHttps = (url, httpMethod, options, timeout) => {
|
|
302
269
|
const isPostRequest = httpMethod === HttpMethod.POST;
|
|
303
270
|
const body = (options == null ? void 0 : options.body) || "";
|
|
@@ -306,32 +273,27 @@ const networkRequestViaHttps = (url, httpMethod, options, timeout) => {
|
|
|
306
273
|
method: httpMethod,
|
|
307
274
|
headers: (options == null ? void 0 : options.headers) || emptyHeaders
|
|
308
275
|
};
|
|
309
|
-
|
|
310
276
|
if (timeout) {
|
|
311
277
|
customOptions.timeout = timeout;
|
|
312
278
|
}
|
|
313
|
-
|
|
314
279
|
if (isPostRequest) {
|
|
315
280
|
// needed for post request to work
|
|
316
|
-
customOptions.headers = {
|
|
281
|
+
customOptions.headers = {
|
|
282
|
+
...customOptions.headers,
|
|
317
283
|
"Content-Length": body.length
|
|
318
284
|
};
|
|
319
285
|
}
|
|
320
|
-
|
|
321
286
|
return new Promise((resolve, reject) => {
|
|
322
287
|
const request = https.request(url, customOptions);
|
|
323
|
-
|
|
324
288
|
if (timeout) {
|
|
325
289
|
request.on("timeout", () => {
|
|
326
290
|
request.destroy();
|
|
327
291
|
reject(new Error("Request time out"));
|
|
328
292
|
});
|
|
329
293
|
}
|
|
330
|
-
|
|
331
294
|
if (isPostRequest) {
|
|
332
295
|
request.write(body);
|
|
333
296
|
}
|
|
334
|
-
|
|
335
297
|
request.end();
|
|
336
298
|
request.on("response", response => {
|
|
337
299
|
const headers = response.headers;
|
|
@@ -346,12 +308,11 @@ const networkRequestViaHttps = (url, httpMethod, options, timeout) => {
|
|
|
346
308
|
const body = Buffer.concat([...data]).toString();
|
|
347
309
|
const parsedHeaders = headers;
|
|
348
310
|
const networkResponse = NetworkUtils.getNetworkResponse(parsedHeaders, parseBody(statusCode, statusMessage, parsedHeaders, body), statusCode);
|
|
349
|
-
|
|
350
|
-
|
|
311
|
+
if ((statusCode < HttpStatus.SUCCESS_RANGE_START || statusCode > HttpStatus.SUCCESS_RANGE_END) &&
|
|
312
|
+
// do not destroy the request for the device code flow
|
|
351
313
|
networkResponse.body["error"] !== Constants.AUTHORIZATION_PENDING) {
|
|
352
314
|
request.destroy();
|
|
353
315
|
}
|
|
354
|
-
|
|
355
316
|
resolve(networkResponse);
|
|
356
317
|
});
|
|
357
318
|
});
|
|
@@ -369,8 +330,6 @@ const networkRequestViaHttps = (url, httpMethod, options, timeout) => {
|
|
|
369
330
|
* @param body {string} the body from the response of the server
|
|
370
331
|
* @returns {Object} JSON parsed body or error object
|
|
371
332
|
*/
|
|
372
|
-
|
|
373
|
-
|
|
374
333
|
const parseBody = (statusCode, statusMessage, headers, body) => {
|
|
375
334
|
/*
|
|
376
335
|
* Informational responses (100 – 199)
|
|
@@ -380,13 +339,11 @@ const parseBody = (statusCode, statusMessage, headers, body) => {
|
|
|
380
339
|
* Server error responses (500 – 599)
|
|
381
340
|
*/
|
|
382
341
|
let parsedBody;
|
|
383
|
-
|
|
384
342
|
try {
|
|
385
343
|
parsedBody = JSON.parse(body);
|
|
386
344
|
} catch (error) {
|
|
387
345
|
let errorType;
|
|
388
346
|
let errorDescriptionHelper;
|
|
389
|
-
|
|
390
347
|
if (statusCode >= HttpStatus.CLIENT_ERROR_RANGE_START && statusCode <= HttpStatus.CLIENT_ERROR_RANGE_END) {
|
|
391
348
|
errorType = "client_error";
|
|
392
349
|
errorDescriptionHelper = "A client";
|
|
@@ -397,13 +354,11 @@ const parseBody = (statusCode, statusMessage, headers, body) => {
|
|
|
397
354
|
errorType = "unknown_error";
|
|
398
355
|
errorDescriptionHelper = "An unknown";
|
|
399
356
|
}
|
|
400
|
-
|
|
401
357
|
parsedBody = {
|
|
402
358
|
error: errorType,
|
|
403
359
|
error_description: `${errorDescriptionHelper} error occured.\nHttp status code: ${statusCode}\nHttp status message: ${statusMessage || "Unknown"}\nHeaders: ${JSON.stringify(headers)}`
|
|
404
360
|
};
|
|
405
361
|
}
|
|
406
|
-
|
|
407
362
|
return parsedBody;
|
|
408
363
|
};
|
|
409
364
|
|
|
@@ -434,7 +389,8 @@ const DEFAULT_AUTH_OPTIONS = {
|
|
|
434
389
|
};
|
|
435
390
|
const DEFAULT_CACHE_OPTIONS = {};
|
|
436
391
|
const DEFAULT_LOGGER_OPTIONS = {
|
|
437
|
-
loggerCallback: () => {
|
|
392
|
+
loggerCallback: () => {
|
|
393
|
+
// allow users to not set logger call back
|
|
438
394
|
},
|
|
439
395
|
piiLoggingEnabled: false,
|
|
440
396
|
logLevel: msalCommon.LogLevel.Info
|
|
@@ -461,24 +417,31 @@ const DEFAULT_TELEMETRY_OPTIONS = {
|
|
|
461
417
|
* @returns Configuration
|
|
462
418
|
* @public
|
|
463
419
|
*/
|
|
464
|
-
|
|
465
420
|
function buildAppConfiguration({
|
|
466
421
|
auth,
|
|
467
422
|
cache,
|
|
468
423
|
system,
|
|
469
424
|
telemetry
|
|
470
425
|
}) {
|
|
426
|
+
const providedSystemOptions = {
|
|
427
|
+
...system,
|
|
428
|
+
loggerOptions: (system == null ? void 0 : system.loggerOptions) || DEFAULT_LOGGER_OPTIONS
|
|
429
|
+
};
|
|
471
430
|
return {
|
|
472
|
-
auth: {
|
|
431
|
+
auth: {
|
|
432
|
+
...DEFAULT_AUTH_OPTIONS,
|
|
473
433
|
...auth
|
|
474
434
|
},
|
|
475
|
-
cache: {
|
|
435
|
+
cache: {
|
|
436
|
+
...DEFAULT_CACHE_OPTIONS,
|
|
476
437
|
...cache
|
|
477
438
|
},
|
|
478
|
-
system: {
|
|
479
|
-
...
|
|
439
|
+
system: {
|
|
440
|
+
...DEFAULT_SYSTEM_OPTIONS,
|
|
441
|
+
...providedSystemOptions
|
|
480
442
|
},
|
|
481
|
-
telemetry: {
|
|
443
|
+
telemetry: {
|
|
444
|
+
...DEFAULT_TELEMETRY_OPTIONS,
|
|
482
445
|
...telemetry
|
|
483
446
|
}
|
|
484
447
|
};
|
|
@@ -501,13 +464,10 @@ class GuidGenerator {
|
|
|
501
464
|
* verifies if a string is GUID
|
|
502
465
|
* @param guid
|
|
503
466
|
*/
|
|
504
|
-
|
|
505
|
-
|
|
506
467
|
isGuid(guid) {
|
|
507
468
|
const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
508
469
|
return regexGuid.test(guid);
|
|
509
470
|
}
|
|
510
|
-
|
|
511
471
|
}
|
|
512
472
|
|
|
513
473
|
/*
|
|
@@ -528,8 +488,6 @@ class EncodingUtils {
|
|
|
528
488
|
* encode a URL
|
|
529
489
|
* @param str
|
|
530
490
|
*/
|
|
531
|
-
|
|
532
|
-
|
|
533
491
|
static base64EncodeUrl(str, encoding) {
|
|
534
492
|
return EncodingUtils.base64Encode(str, encoding).replace(/=/g, msalCommon.Constants.EMPTY_STRING).replace(/\+/g, "-").replace(/\//g, "_");
|
|
535
493
|
}
|
|
@@ -539,26 +497,19 @@ class EncodingUtils {
|
|
|
539
497
|
*
|
|
540
498
|
* @param base64Str Base64 encoded text
|
|
541
499
|
*/
|
|
542
|
-
|
|
543
|
-
|
|
544
500
|
static base64Decode(base64Str) {
|
|
545
501
|
return Buffer.from(base64Str, "base64").toString("utf8");
|
|
546
502
|
}
|
|
547
503
|
/**
|
|
548
504
|
* @param base64Str Base64 encoded Url
|
|
549
505
|
*/
|
|
550
|
-
|
|
551
|
-
|
|
552
506
|
static base64DecodeUrl(base64Str) {
|
|
553
507
|
let str = base64Str.replace(/-/g, "+").replace(/_/g, "/");
|
|
554
|
-
|
|
555
508
|
while (str.length % 4) {
|
|
556
509
|
str += "=";
|
|
557
510
|
}
|
|
558
|
-
|
|
559
511
|
return EncodingUtils.base64Decode(str);
|
|
560
512
|
}
|
|
561
|
-
|
|
562
513
|
}
|
|
563
514
|
|
|
564
515
|
/*
|
|
@@ -573,7 +524,6 @@ class HashUtils {
|
|
|
573
524
|
sha256(buffer) {
|
|
574
525
|
return crypto.createHash(Hash.SHA256).update(buffer).digest();
|
|
575
526
|
}
|
|
576
|
-
|
|
577
527
|
}
|
|
578
528
|
|
|
579
529
|
/*
|
|
@@ -583,7 +533,6 @@ class HashUtils {
|
|
|
583
533
|
/**
|
|
584
534
|
* https://tools.ietf.org/html/rfc7636#page-8
|
|
585
535
|
*/
|
|
586
|
-
|
|
587
536
|
class PkceGenerator {
|
|
588
537
|
constructor() {
|
|
589
538
|
this.hashUtils = new HashUtils();
|
|
@@ -592,8 +541,6 @@ class PkceGenerator {
|
|
|
592
541
|
* generates the codeVerfier and the challenge from the codeVerfier
|
|
593
542
|
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
|
|
594
543
|
*/
|
|
595
|
-
|
|
596
|
-
|
|
597
544
|
async generatePkceCodes() {
|
|
598
545
|
const verifier = this.generateCodeVerifier();
|
|
599
546
|
const challenge = this.generateCodeChallengeFromVerifier(verifier);
|
|
@@ -605,15 +552,11 @@ class PkceGenerator {
|
|
|
605
552
|
/**
|
|
606
553
|
* generates the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.1
|
|
607
554
|
*/
|
|
608
|
-
|
|
609
|
-
|
|
610
555
|
generateCodeVerifier() {
|
|
611
556
|
const charArr = [];
|
|
612
557
|
const maxNumber = 256 - 256 % CharSet.CV_CHARSET.length;
|
|
613
|
-
|
|
614
558
|
while (charArr.length <= RANDOM_OCTET_SIZE) {
|
|
615
559
|
const byte = crypto.randomBytes(1)[0];
|
|
616
|
-
|
|
617
560
|
if (byte >= maxNumber) {
|
|
618
561
|
/*
|
|
619
562
|
* Ignore this number to maintain randomness.
|
|
@@ -621,11 +564,9 @@ class PkceGenerator {
|
|
|
621
564
|
*/
|
|
622
565
|
continue;
|
|
623
566
|
}
|
|
624
|
-
|
|
625
567
|
const index = byte % CharSet.CV_CHARSET.length;
|
|
626
568
|
charArr.push(CharSet.CV_CHARSET[index]);
|
|
627
569
|
}
|
|
628
|
-
|
|
629
570
|
const verifier = charArr.join(msalCommon.Constants.EMPTY_STRING);
|
|
630
571
|
return EncodingUtils.base64EncodeUrl(verifier);
|
|
631
572
|
}
|
|
@@ -633,12 +574,9 @@ class PkceGenerator {
|
|
|
633
574
|
* generate the challenge from the codeVerfier; reference: https://tools.ietf.org/html/rfc7636#section-4.2
|
|
634
575
|
* @param codeVerifier
|
|
635
576
|
*/
|
|
636
|
-
|
|
637
|
-
|
|
638
577
|
generateCodeChallengeFromVerifier(codeVerifier) {
|
|
639
578
|
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString("base64"), "base64");
|
|
640
579
|
}
|
|
641
|
-
|
|
642
580
|
}
|
|
643
581
|
|
|
644
582
|
/*
|
|
@@ -650,7 +588,6 @@ class PkceGenerator {
|
|
|
650
588
|
* implementing Proof Key for Code Exchange specs for the OAuth Authorization Code Flow using PKCE (rfc here: https://tools.ietf.org/html/rfc7636).
|
|
651
589
|
* @public
|
|
652
590
|
*/
|
|
653
|
-
|
|
654
591
|
class CryptoProvider {
|
|
655
592
|
constructor() {
|
|
656
593
|
// Browser crypto needs to be validated first before any other classes can be set.
|
|
@@ -662,8 +599,6 @@ class CryptoProvider {
|
|
|
662
599
|
* Creates a new random GUID - used to populate state and nonce.
|
|
663
600
|
* @returns string (GUID)
|
|
664
601
|
*/
|
|
665
|
-
|
|
666
|
-
|
|
667
602
|
createNewGuid() {
|
|
668
603
|
return this.guidGenerator.generateGuid();
|
|
669
604
|
}
|
|
@@ -671,8 +606,6 @@ class CryptoProvider {
|
|
|
671
606
|
* Encodes input string to base64.
|
|
672
607
|
* @param input - string to be encoded
|
|
673
608
|
*/
|
|
674
|
-
|
|
675
|
-
|
|
676
609
|
base64Encode(input) {
|
|
677
610
|
return EncodingUtils.base64Encode(input);
|
|
678
611
|
}
|
|
@@ -680,24 +613,18 @@ class CryptoProvider {
|
|
|
680
613
|
* Decodes input string from base64.
|
|
681
614
|
* @param input - string to be decoded
|
|
682
615
|
*/
|
|
683
|
-
|
|
684
|
-
|
|
685
616
|
base64Decode(input) {
|
|
686
617
|
return EncodingUtils.base64Decode(input);
|
|
687
618
|
}
|
|
688
619
|
/**
|
|
689
620
|
* Generates PKCE codes used in Authorization Code Flow.
|
|
690
621
|
*/
|
|
691
|
-
|
|
692
|
-
|
|
693
622
|
generatePkceCodes() {
|
|
694
623
|
return this.pkceGenerator.generatePkceCodes();
|
|
695
624
|
}
|
|
696
625
|
/**
|
|
697
626
|
* Generates a keypair, stores it and returns a thumbprint - not yet implemented for node
|
|
698
627
|
*/
|
|
699
|
-
|
|
700
|
-
|
|
701
628
|
getPublicKeyThumbprint() {
|
|
702
629
|
throw new Error("Method not implemented.");
|
|
703
630
|
}
|
|
@@ -705,36 +632,27 @@ class CryptoProvider {
|
|
|
705
632
|
* Removes cryptographic keypair from key store matching the keyId passed in
|
|
706
633
|
* @param kid
|
|
707
634
|
*/
|
|
708
|
-
|
|
709
|
-
|
|
710
635
|
removeTokenBindingKey() {
|
|
711
636
|
throw new Error("Method not implemented.");
|
|
712
637
|
}
|
|
713
638
|
/**
|
|
714
639
|
* Removes all cryptographic keys from Keystore
|
|
715
640
|
*/
|
|
716
|
-
|
|
717
|
-
|
|
718
641
|
clearKeystore() {
|
|
719
642
|
throw new Error("Method not implemented.");
|
|
720
643
|
}
|
|
721
644
|
/**
|
|
722
645
|
* Signs the given object as a jwt payload with private key retrieved by given kid - currently not implemented for node
|
|
723
646
|
*/
|
|
724
|
-
|
|
725
|
-
|
|
726
647
|
signJwt() {
|
|
727
648
|
throw new Error("Method not implemented.");
|
|
728
649
|
}
|
|
729
650
|
/**
|
|
730
651
|
* Returns the SHA-256 hash of an input string
|
|
731
652
|
*/
|
|
732
|
-
|
|
733
|
-
|
|
734
653
|
async hashString(plainText) {
|
|
735
654
|
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(plainText).toString("base64"), "base64");
|
|
736
655
|
}
|
|
737
|
-
|
|
738
656
|
}
|
|
739
657
|
|
|
740
658
|
/*
|
|
@@ -744,7 +662,6 @@ class CryptoProvider {
|
|
|
744
662
|
/**
|
|
745
663
|
* This class deserializes cache entities read from the file into in memory object types defined internally
|
|
746
664
|
*/
|
|
747
|
-
|
|
748
665
|
class Deserializer {
|
|
749
666
|
/**
|
|
750
667
|
* Parse the JSON blob in memory and deserialize the content
|
|
@@ -758,11 +675,8 @@ class Deserializer {
|
|
|
758
675
|
* Deserializes accounts to AccountEntity objects
|
|
759
676
|
* @param accounts
|
|
760
677
|
*/
|
|
761
|
-
|
|
762
|
-
|
|
763
678
|
static deserializeAccounts(accounts) {
|
|
764
679
|
const accountObjects = {};
|
|
765
|
-
|
|
766
680
|
if (accounts) {
|
|
767
681
|
Object.keys(accounts).map(function (key) {
|
|
768
682
|
const serializedAcc = accounts[key];
|
|
@@ -783,18 +697,14 @@ class Deserializer {
|
|
|
783
697
|
accountObjects[key] = account;
|
|
784
698
|
});
|
|
785
699
|
}
|
|
786
|
-
|
|
787
700
|
return accountObjects;
|
|
788
701
|
}
|
|
789
702
|
/**
|
|
790
703
|
* Deserializes id tokens to IdTokenEntity objects
|
|
791
704
|
* @param idTokens
|
|
792
705
|
*/
|
|
793
|
-
|
|
794
|
-
|
|
795
706
|
static deserializeIdTokens(idTokens) {
|
|
796
707
|
const idObjects = {};
|
|
797
|
-
|
|
798
708
|
if (idTokens) {
|
|
799
709
|
Object.keys(idTokens).map(function (key) {
|
|
800
710
|
const serializedIdT = idTokens[key];
|
|
@@ -811,18 +721,14 @@ class Deserializer {
|
|
|
811
721
|
idObjects[key] = idToken;
|
|
812
722
|
});
|
|
813
723
|
}
|
|
814
|
-
|
|
815
724
|
return idObjects;
|
|
816
725
|
}
|
|
817
726
|
/**
|
|
818
727
|
* Deserializes access tokens to AccessTokenEntity objects
|
|
819
728
|
* @param accessTokens
|
|
820
729
|
*/
|
|
821
|
-
|
|
822
|
-
|
|
823
730
|
static deserializeAccessTokens(accessTokens) {
|
|
824
731
|
const atObjects = {};
|
|
825
|
-
|
|
826
732
|
if (accessTokens) {
|
|
827
733
|
Object.keys(accessTokens).map(function (key) {
|
|
828
734
|
const serializedAT = accessTokens[key];
|
|
@@ -841,25 +747,22 @@ class Deserializer {
|
|
|
841
747
|
keyId: serializedAT.key_id,
|
|
842
748
|
tokenType: serializedAT.token_type,
|
|
843
749
|
requestedClaims: serializedAT.requestedClaims,
|
|
844
|
-
requestedClaimsHash: serializedAT.requestedClaimsHash
|
|
750
|
+
requestedClaimsHash: serializedAT.requestedClaimsHash,
|
|
751
|
+
userAssertionHash: serializedAT.userAssertionHash
|
|
845
752
|
};
|
|
846
753
|
const accessToken = new msalCommon.AccessTokenEntity();
|
|
847
754
|
msalCommon.CacheManager.toObject(accessToken, mappedAT);
|
|
848
755
|
atObjects[key] = accessToken;
|
|
849
756
|
});
|
|
850
757
|
}
|
|
851
|
-
|
|
852
758
|
return atObjects;
|
|
853
759
|
}
|
|
854
760
|
/**
|
|
855
761
|
* Deserializes refresh tokens to RefreshTokenEntity objects
|
|
856
762
|
* @param refreshTokens
|
|
857
763
|
*/
|
|
858
|
-
|
|
859
|
-
|
|
860
764
|
static deserializeRefreshTokens(refreshTokens) {
|
|
861
765
|
const rtObjects = {};
|
|
862
|
-
|
|
863
766
|
if (refreshTokens) {
|
|
864
767
|
Object.keys(refreshTokens).map(function (key) {
|
|
865
768
|
const serializedRT = refreshTokens[key];
|
|
@@ -878,18 +781,14 @@ class Deserializer {
|
|
|
878
781
|
rtObjects[key] = refreshToken;
|
|
879
782
|
});
|
|
880
783
|
}
|
|
881
|
-
|
|
882
784
|
return rtObjects;
|
|
883
785
|
}
|
|
884
786
|
/**
|
|
885
787
|
* Deserializes appMetadata to AppMetaData objects
|
|
886
788
|
* @param appMetadata
|
|
887
789
|
*/
|
|
888
|
-
|
|
889
|
-
|
|
890
790
|
static deserializeAppMetadata(appMetadata) {
|
|
891
791
|
const appMetadataObjects = {};
|
|
892
|
-
|
|
893
792
|
if (appMetadata) {
|
|
894
793
|
Object.keys(appMetadata).map(function (key) {
|
|
895
794
|
const serializedAmdt = appMetadata[key];
|
|
@@ -903,15 +802,12 @@ class Deserializer {
|
|
|
903
802
|
appMetadataObjects[key] = amd;
|
|
904
803
|
});
|
|
905
804
|
}
|
|
906
|
-
|
|
907
805
|
return appMetadataObjects;
|
|
908
806
|
}
|
|
909
807
|
/**
|
|
910
808
|
* Deserialize an inMemory Cache
|
|
911
809
|
* @param jsonCache
|
|
912
810
|
*/
|
|
913
|
-
|
|
914
|
-
|
|
915
811
|
static deserializeAllCache(jsonCache) {
|
|
916
812
|
return {
|
|
917
813
|
accounts: jsonCache.Account ? this.deserializeAccounts(jsonCache.Account) : {},
|
|
@@ -921,7 +817,6 @@ class Deserializer {
|
|
|
921
817
|
appMetadata: jsonCache.AppMetadata ? this.deserializeAppMetadata(jsonCache.AppMetadata) : {}
|
|
922
818
|
};
|
|
923
819
|
}
|
|
924
|
-
|
|
925
820
|
}
|
|
926
821
|
|
|
927
822
|
/*
|
|
@@ -940,8 +835,6 @@ class Serializer {
|
|
|
940
835
|
* Serialize Accounts
|
|
941
836
|
* @param accCache
|
|
942
837
|
*/
|
|
943
|
-
|
|
944
|
-
|
|
945
838
|
static serializeAccounts(accCache) {
|
|
946
839
|
const accounts = {};
|
|
947
840
|
Object.keys(accCache).map(function (key) {
|
|
@@ -965,8 +858,6 @@ class Serializer {
|
|
|
965
858
|
* Serialize IdTokens
|
|
966
859
|
* @param idTCache
|
|
967
860
|
*/
|
|
968
|
-
|
|
969
|
-
|
|
970
861
|
static serializeIdTokens(idTCache) {
|
|
971
862
|
const idTokens = {};
|
|
972
863
|
Object.keys(idTCache).map(function (key) {
|
|
@@ -986,8 +877,6 @@ class Serializer {
|
|
|
986
877
|
* Serializes AccessTokens
|
|
987
878
|
* @param atCache
|
|
988
879
|
*/
|
|
989
|
-
|
|
990
|
-
|
|
991
880
|
static serializeAccessTokens(atCache) {
|
|
992
881
|
const accessTokens = {};
|
|
993
882
|
Object.keys(atCache).map(function (key) {
|
|
@@ -1007,7 +896,8 @@ class Serializer {
|
|
|
1007
896
|
key_id: atEntity.keyId,
|
|
1008
897
|
token_type: atEntity.tokenType,
|
|
1009
898
|
requestedClaims: atEntity.requestedClaims,
|
|
1010
|
-
requestedClaimsHash: atEntity.requestedClaimsHash
|
|
899
|
+
requestedClaimsHash: atEntity.requestedClaimsHash,
|
|
900
|
+
userAssertionHash: atEntity.userAssertionHash
|
|
1011
901
|
};
|
|
1012
902
|
});
|
|
1013
903
|
return accessTokens;
|
|
@@ -1016,8 +906,6 @@ class Serializer {
|
|
|
1016
906
|
* Serialize refreshTokens
|
|
1017
907
|
* @param rtCache
|
|
1018
908
|
*/
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
909
|
static serializeRefreshTokens(rtCache) {
|
|
1022
910
|
const refreshTokens = {};
|
|
1023
911
|
Object.keys(rtCache).map(function (key) {
|
|
@@ -1039,8 +927,6 @@ class Serializer {
|
|
|
1039
927
|
* Serialize amdtCache
|
|
1040
928
|
* @param amdtCache
|
|
1041
929
|
*/
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
930
|
static serializeAppMetadata(amdtCache) {
|
|
1045
931
|
const appMetadata = {};
|
|
1046
932
|
Object.keys(amdtCache).map(function (key) {
|
|
@@ -1057,8 +943,6 @@ class Serializer {
|
|
|
1057
943
|
* Serialize the cache
|
|
1058
944
|
* @param jsonContent
|
|
1059
945
|
*/
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
946
|
static serializeAllCache(inMemCache) {
|
|
1063
947
|
return {
|
|
1064
948
|
Account: this.serializeAccounts(inMemCache.accounts),
|
|
@@ -1068,7 +952,6 @@ class Serializer {
|
|
|
1068
952
|
AppMetadata: this.serializeAppMetadata(inMemCache.appMetadata)
|
|
1069
953
|
};
|
|
1070
954
|
}
|
|
1071
|
-
|
|
1072
955
|
}
|
|
1073
956
|
|
|
1074
957
|
/*
|
|
@@ -1079,7 +962,6 @@ class Serializer {
|
|
|
1079
962
|
* This class implements Storage for node, reading cache from user specified storage location or an extension library
|
|
1080
963
|
* @public
|
|
1081
964
|
*/
|
|
1082
|
-
|
|
1083
965
|
class NodeStorage extends msalCommon.CacheManager {
|
|
1084
966
|
constructor(logger, clientId, cryptoImpl) {
|
|
1085
967
|
super(clientId, cryptoImpl);
|
|
@@ -1091,16 +973,12 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1091
973
|
* Queue up callbacks
|
|
1092
974
|
* @param func - a callback function for cache change indication
|
|
1093
975
|
*/
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
976
|
registerChangeEmitter(func) {
|
|
1097
977
|
this.changeEmitters.push(func);
|
|
1098
978
|
}
|
|
1099
979
|
/**
|
|
1100
980
|
* Invoke the callback when cache changes
|
|
1101
981
|
*/
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
982
|
emitChange() {
|
|
1105
983
|
this.changeEmitters.forEach(func => func.call(null));
|
|
1106
984
|
}
|
|
@@ -1108,8 +986,6 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1108
986
|
* Converts cacheKVStore to InMemoryCache
|
|
1109
987
|
* @param cache - key value store
|
|
1110
988
|
*/
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
989
|
cacheToInMemoryCache(cache) {
|
|
1114
990
|
const inMemoryCache = {
|
|
1115
991
|
accounts: {},
|
|
@@ -1118,7 +994,6 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1118
994
|
refreshTokens: {},
|
|
1119
995
|
appMetadata: {}
|
|
1120
996
|
};
|
|
1121
|
-
|
|
1122
997
|
for (const key in cache) {
|
|
1123
998
|
if (cache[key] instanceof msalCommon.AccountEntity) {
|
|
1124
999
|
inMemoryCache.accounts[key] = cache[key];
|
|
@@ -1134,36 +1009,32 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1134
1009
|
continue;
|
|
1135
1010
|
}
|
|
1136
1011
|
}
|
|
1137
|
-
|
|
1138
1012
|
return inMemoryCache;
|
|
1139
1013
|
}
|
|
1140
1014
|
/**
|
|
1141
1015
|
* converts inMemoryCache to CacheKVStore
|
|
1142
1016
|
* @param inMemoryCache - kvstore map for inmemory
|
|
1143
1017
|
*/
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
1018
|
inMemoryCacheToCache(inMemoryCache) {
|
|
1147
1019
|
// convert in memory cache to a flat Key-Value map
|
|
1148
1020
|
let cache = this.getCache();
|
|
1149
|
-
cache = {
|
|
1021
|
+
cache = {
|
|
1022
|
+
...cache,
|
|
1150
1023
|
...inMemoryCache.accounts,
|
|
1151
1024
|
...inMemoryCache.idTokens,
|
|
1152
1025
|
...inMemoryCache.accessTokens,
|
|
1153
1026
|
...inMemoryCache.refreshTokens,
|
|
1154
1027
|
...inMemoryCache.appMetadata
|
|
1155
|
-
};
|
|
1156
|
-
|
|
1028
|
+
};
|
|
1029
|
+
// convert in memory cache to a flat Key-Value map
|
|
1157
1030
|
return cache;
|
|
1158
1031
|
}
|
|
1159
1032
|
/**
|
|
1160
1033
|
* gets the current in memory cache for the client
|
|
1161
1034
|
*/
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
1035
|
getInMemoryCache() {
|
|
1165
|
-
this.logger.trace("Getting in-memory cache");
|
|
1166
|
-
|
|
1036
|
+
this.logger.trace("Getting in-memory cache");
|
|
1037
|
+
// convert the cache key value store to inMemoryCache
|
|
1167
1038
|
const inMemoryCache = this.cacheToInMemoryCache(this.getCache());
|
|
1168
1039
|
return inMemoryCache;
|
|
1169
1040
|
}
|
|
@@ -1171,11 +1042,9 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1171
1042
|
* sets the current in memory cache for the client
|
|
1172
1043
|
* @param inMemoryCache - key value map in memory
|
|
1173
1044
|
*/
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
1045
|
setInMemoryCache(inMemoryCache) {
|
|
1177
|
-
this.logger.trace("Setting in-memory cache");
|
|
1178
|
-
|
|
1046
|
+
this.logger.trace("Setting in-memory cache");
|
|
1047
|
+
// convert and append the inMemoryCache to cacheKVStore
|
|
1179
1048
|
const cache = this.inMemoryCacheToCache(inMemoryCache);
|
|
1180
1049
|
this.setCache(cache);
|
|
1181
1050
|
this.emitChange();
|
|
@@ -1183,8 +1052,6 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1183
1052
|
/**
|
|
1184
1053
|
* get the current cache key-value store
|
|
1185
1054
|
*/
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
1055
|
getCache() {
|
|
1189
1056
|
this.logger.trace("Getting cache key-value store");
|
|
1190
1057
|
return this.cache;
|
|
@@ -1193,23 +1060,19 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1193
1060
|
* sets the current cache (key value store)
|
|
1194
1061
|
* @param cacheMap - key value map
|
|
1195
1062
|
*/
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
1063
|
setCache(cache) {
|
|
1199
1064
|
this.logger.trace("Setting cache key value store");
|
|
1200
|
-
this.cache = cache;
|
|
1201
|
-
|
|
1065
|
+
this.cache = cache;
|
|
1066
|
+
// mark change in cache
|
|
1202
1067
|
this.emitChange();
|
|
1203
1068
|
}
|
|
1204
1069
|
/**
|
|
1205
1070
|
* Gets cache item with given key.
|
|
1206
1071
|
* @param key - lookup key for the cache entry
|
|
1207
1072
|
*/
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
1073
|
getItem(key) {
|
|
1211
|
-
this.logger.tracePii(`Item key: ${key}`);
|
|
1212
|
-
|
|
1074
|
+
this.logger.tracePii(`Item key: ${key}`);
|
|
1075
|
+
// read cache
|
|
1213
1076
|
const cache = this.getCache();
|
|
1214
1077
|
return cache[key];
|
|
1215
1078
|
}
|
|
@@ -1218,37 +1081,29 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1218
1081
|
* @param key - lookup key for the cache entry
|
|
1219
1082
|
* @param value - value of the cache entry
|
|
1220
1083
|
*/
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
1084
|
setItem(key, value) {
|
|
1224
|
-
this.logger.tracePii(`Item key: ${key}`);
|
|
1225
|
-
|
|
1085
|
+
this.logger.tracePii(`Item key: ${key}`);
|
|
1086
|
+
// read cache
|
|
1226
1087
|
const cache = this.getCache();
|
|
1227
|
-
cache[key] = value;
|
|
1228
|
-
|
|
1088
|
+
cache[key] = value;
|
|
1089
|
+
// write to cache
|
|
1229
1090
|
this.setCache(cache);
|
|
1230
1091
|
}
|
|
1231
1092
|
/**
|
|
1232
1093
|
* fetch the account entity
|
|
1233
1094
|
* @param accountKey - lookup key to fetch cache type AccountEntity
|
|
1234
1095
|
*/
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
1096
|
getAccount(accountKey) {
|
|
1238
1097
|
const account = this.getItem(accountKey);
|
|
1239
|
-
|
|
1240
1098
|
if (msalCommon.AccountEntity.isAccountEntity(account)) {
|
|
1241
1099
|
return account;
|
|
1242
1100
|
}
|
|
1243
|
-
|
|
1244
1101
|
return null;
|
|
1245
1102
|
}
|
|
1246
1103
|
/**
|
|
1247
1104
|
* set account entity
|
|
1248
1105
|
* @param account - cache value to be set of type AccountEntity
|
|
1249
1106
|
*/
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
1107
|
setAccount(account) {
|
|
1253
1108
|
const accountKey = account.generateAccountKey();
|
|
1254
1109
|
this.setItem(accountKey, account);
|
|
@@ -1257,23 +1112,17 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1257
1112
|
* fetch the idToken credential
|
|
1258
1113
|
* @param idTokenKey - lookup key to fetch cache type IdTokenEntity
|
|
1259
1114
|
*/
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
1115
|
getIdTokenCredential(idTokenKey) {
|
|
1263
1116
|
const idToken = this.getItem(idTokenKey);
|
|
1264
|
-
|
|
1265
1117
|
if (msalCommon.IdTokenEntity.isIdTokenEntity(idToken)) {
|
|
1266
1118
|
return idToken;
|
|
1267
1119
|
}
|
|
1268
|
-
|
|
1269
1120
|
return null;
|
|
1270
1121
|
}
|
|
1271
1122
|
/**
|
|
1272
1123
|
* set idToken credential
|
|
1273
1124
|
* @param idToken - cache value to be set of type IdTokenEntity
|
|
1274
1125
|
*/
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
1126
|
setIdTokenCredential(idToken) {
|
|
1278
1127
|
const idTokenKey = idToken.generateCredentialKey();
|
|
1279
1128
|
this.setItem(idTokenKey, idToken);
|
|
@@ -1282,23 +1131,17 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1282
1131
|
* fetch the accessToken credential
|
|
1283
1132
|
* @param accessTokenKey - lookup key to fetch cache type AccessTokenEntity
|
|
1284
1133
|
*/
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
1134
|
getAccessTokenCredential(accessTokenKey) {
|
|
1288
1135
|
const accessToken = this.getItem(accessTokenKey);
|
|
1289
|
-
|
|
1290
1136
|
if (msalCommon.AccessTokenEntity.isAccessTokenEntity(accessToken)) {
|
|
1291
1137
|
return accessToken;
|
|
1292
1138
|
}
|
|
1293
|
-
|
|
1294
1139
|
return null;
|
|
1295
1140
|
}
|
|
1296
1141
|
/**
|
|
1297
1142
|
* set accessToken credential
|
|
1298
1143
|
* @param accessToken - cache value to be set of type AccessTokenEntity
|
|
1299
1144
|
*/
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
1145
|
setAccessTokenCredential(accessToken) {
|
|
1303
1146
|
const accessTokenKey = accessToken.generateCredentialKey();
|
|
1304
1147
|
this.setItem(accessTokenKey, accessToken);
|
|
@@ -1307,23 +1150,17 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1307
1150
|
* fetch the refreshToken credential
|
|
1308
1151
|
* @param refreshTokenKey - lookup key to fetch cache type RefreshTokenEntity
|
|
1309
1152
|
*/
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
1153
|
getRefreshTokenCredential(refreshTokenKey) {
|
|
1313
1154
|
const refreshToken = this.getItem(refreshTokenKey);
|
|
1314
|
-
|
|
1315
1155
|
if (msalCommon.RefreshTokenEntity.isRefreshTokenEntity(refreshToken)) {
|
|
1316
1156
|
return refreshToken;
|
|
1317
1157
|
}
|
|
1318
|
-
|
|
1319
1158
|
return null;
|
|
1320
1159
|
}
|
|
1321
1160
|
/**
|
|
1322
1161
|
* set refreshToken credential
|
|
1323
1162
|
* @param refreshToken - cache value to be set of type RefreshTokenEntity
|
|
1324
1163
|
*/
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
1164
|
setRefreshTokenCredential(refreshToken) {
|
|
1328
1165
|
const refreshTokenKey = refreshToken.generateCredentialKey();
|
|
1329
1166
|
this.setItem(refreshTokenKey, refreshToken);
|
|
@@ -1332,23 +1169,17 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1332
1169
|
* fetch appMetadata entity from the platform cache
|
|
1333
1170
|
* @param appMetadataKey - lookup key to fetch cache type AppMetadataEntity
|
|
1334
1171
|
*/
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
1172
|
getAppMetadata(appMetadataKey) {
|
|
1338
1173
|
const appMetadata = this.getItem(appMetadataKey);
|
|
1339
|
-
|
|
1340
1174
|
if (msalCommon.AppMetadataEntity.isAppMetadataEntity(appMetadataKey, appMetadata)) {
|
|
1341
1175
|
return appMetadata;
|
|
1342
1176
|
}
|
|
1343
|
-
|
|
1344
1177
|
return null;
|
|
1345
1178
|
}
|
|
1346
1179
|
/**
|
|
1347
1180
|
* set appMetadata entity to the platform cache
|
|
1348
1181
|
* @param appMetadata - cache value to be set of type AppMetadataEntity
|
|
1349
1182
|
*/
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
1183
|
setAppMetadata(appMetadata) {
|
|
1353
1184
|
const appMetadataKey = appMetadata.generateAppMetadataKey();
|
|
1354
1185
|
this.setItem(appMetadataKey, appMetadata);
|
|
@@ -1357,15 +1188,11 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1357
1188
|
* fetch server telemetry entity from the platform cache
|
|
1358
1189
|
* @param serverTelemetrykey - lookup key to fetch cache type ServerTelemetryEntity
|
|
1359
1190
|
*/
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
1191
|
getServerTelemetry(serverTelemetrykey) {
|
|
1363
1192
|
const serverTelemetryEntity = this.getItem(serverTelemetrykey);
|
|
1364
|
-
|
|
1365
1193
|
if (serverTelemetryEntity && msalCommon.ServerTelemetryEntity.isServerTelemetryEntity(serverTelemetrykey, serverTelemetryEntity)) {
|
|
1366
1194
|
return serverTelemetryEntity;
|
|
1367
1195
|
}
|
|
1368
|
-
|
|
1369
1196
|
return null;
|
|
1370
1197
|
}
|
|
1371
1198
|
/**
|
|
@@ -1373,8 +1200,6 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1373
1200
|
* @param serverTelemetryKey - lookup key to fetch cache type ServerTelemetryEntity
|
|
1374
1201
|
* @param serverTelemetry - cache value to be set of type ServerTelemetryEntity
|
|
1375
1202
|
*/
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
1203
|
setServerTelemetry(serverTelemetryKey, serverTelemetry) {
|
|
1379
1204
|
this.setItem(serverTelemetryKey, serverTelemetry);
|
|
1380
1205
|
}
|
|
@@ -1382,22 +1207,16 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1382
1207
|
* fetch authority metadata entity from the platform cache
|
|
1383
1208
|
* @param key - lookup key to fetch cache type AuthorityMetadataEntity
|
|
1384
1209
|
*/
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
1210
|
getAuthorityMetadata(key) {
|
|
1388
1211
|
const authorityMetadataEntity = this.getItem(key);
|
|
1389
|
-
|
|
1390
1212
|
if (authorityMetadataEntity && msalCommon.AuthorityMetadataEntity.isAuthorityMetadataEntity(key, authorityMetadataEntity)) {
|
|
1391
1213
|
return authorityMetadataEntity;
|
|
1392
1214
|
}
|
|
1393
|
-
|
|
1394
1215
|
return null;
|
|
1395
1216
|
}
|
|
1396
1217
|
/**
|
|
1397
1218
|
* Get all authority metadata keys
|
|
1398
1219
|
*/
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
1220
|
getAuthorityMetadataKeys() {
|
|
1402
1221
|
return this.getKeys().filter(key => {
|
|
1403
1222
|
return this.isAuthorityMetadata(key);
|
|
@@ -1408,8 +1227,6 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1408
1227
|
* @param key - lookup key to fetch cache type AuthorityMetadataEntity
|
|
1409
1228
|
* @param metadata - cache value to be set of type AuthorityMetadataEntity
|
|
1410
1229
|
*/
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
1230
|
setAuthorityMetadata(key, metadata) {
|
|
1414
1231
|
this.setItem(key, metadata);
|
|
1415
1232
|
}
|
|
@@ -1417,15 +1234,11 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1417
1234
|
* fetch throttling entity from the platform cache
|
|
1418
1235
|
* @param throttlingCacheKey - lookup key to fetch cache type ThrottlingEntity
|
|
1419
1236
|
*/
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
1237
|
getThrottlingCache(throttlingCacheKey) {
|
|
1423
1238
|
const throttlingCache = this.getItem(throttlingCacheKey);
|
|
1424
|
-
|
|
1425
1239
|
if (throttlingCache && msalCommon.ThrottlingEntity.isThrottlingEntity(throttlingCacheKey, throttlingCache)) {
|
|
1426
1240
|
return throttlingCache;
|
|
1427
1241
|
}
|
|
1428
|
-
|
|
1429
1242
|
return null;
|
|
1430
1243
|
}
|
|
1431
1244
|
/**
|
|
@@ -1433,8 +1246,6 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1433
1246
|
* @param throttlingCacheKey - lookup key to fetch cache type ThrottlingEntity
|
|
1434
1247
|
* @param throttlingCache - cache value to be set of type ThrottlingEntity
|
|
1435
1248
|
*/
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
1249
|
setThrottlingCache(throttlingCacheKey, throttlingCache) {
|
|
1439
1250
|
this.setItem(throttlingCacheKey, throttlingCache);
|
|
1440
1251
|
}
|
|
@@ -1443,57 +1254,46 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1443
1254
|
* @param key - lookup key to remove a cache entity
|
|
1444
1255
|
* @param inMemory - key value map of the cache
|
|
1445
1256
|
*/
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
1257
|
removeItem(key) {
|
|
1449
|
-
this.logger.tracePii(`Item key: ${key}`);
|
|
1450
|
-
|
|
1258
|
+
this.logger.tracePii(`Item key: ${key}`);
|
|
1259
|
+
// read inMemoryCache
|
|
1451
1260
|
let result = false;
|
|
1452
1261
|
const cache = this.getCache();
|
|
1453
|
-
|
|
1454
1262
|
if (!!cache[key]) {
|
|
1455
1263
|
delete cache[key];
|
|
1456
1264
|
result = true;
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1265
|
+
}
|
|
1266
|
+
// write to the cache after removal
|
|
1460
1267
|
if (result) {
|
|
1461
1268
|
this.setCache(cache);
|
|
1462
1269
|
this.emitChange();
|
|
1463
1270
|
}
|
|
1464
|
-
|
|
1465
1271
|
return result;
|
|
1466
1272
|
}
|
|
1467
1273
|
/**
|
|
1468
1274
|
* Checks whether key is in cache.
|
|
1469
1275
|
* @param key - look up key for a cache entity
|
|
1470
1276
|
*/
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
1277
|
containsKey(key) {
|
|
1474
1278
|
return this.getKeys().includes(key);
|
|
1475
1279
|
}
|
|
1476
1280
|
/**
|
|
1477
1281
|
* Gets all keys in window.
|
|
1478
1282
|
*/
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
1283
|
getKeys() {
|
|
1482
|
-
this.logger.trace("Retrieving all cache keys");
|
|
1483
|
-
|
|
1284
|
+
this.logger.trace("Retrieving all cache keys");
|
|
1285
|
+
// read cache
|
|
1484
1286
|
const cache = this.getCache();
|
|
1485
1287
|
return [...Object.keys(cache)];
|
|
1486
1288
|
}
|
|
1487
1289
|
/**
|
|
1488
1290
|
* Clears all cache entries created by MSAL (except tokens).
|
|
1489
1291
|
*/
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
1292
|
async clear() {
|
|
1493
|
-
this.logger.trace("Clearing cache entries created by MSAL");
|
|
1494
|
-
|
|
1495
|
-
const cacheKeys = this.getKeys();
|
|
1496
|
-
|
|
1293
|
+
this.logger.trace("Clearing cache entries created by MSAL");
|
|
1294
|
+
// read inMemoryCache
|
|
1295
|
+
const cacheKeys = this.getKeys();
|
|
1296
|
+
// delete each element
|
|
1497
1297
|
cacheKeys.forEach(key => {
|
|
1498
1298
|
this.removeItem(key);
|
|
1499
1299
|
});
|
|
@@ -1503,8 +1303,6 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1503
1303
|
* Initialize in memory cache from an exisiting cache vault
|
|
1504
1304
|
* @param cache - blob formatted cache (JSON)
|
|
1505
1305
|
*/
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
1306
|
static generateInMemoryCache(cache) {
|
|
1509
1307
|
return Deserializer.deserializeAllCache(Deserializer.deserializeJSONBlob(cache));
|
|
1510
1308
|
}
|
|
@@ -1512,22 +1310,16 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1512
1310
|
* retrieves the final JSON
|
|
1513
1311
|
* @param inMemoryCache - itemised cache read from the JSON
|
|
1514
1312
|
*/
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
1313
|
static generateJsonCache(inMemoryCache) {
|
|
1518
1314
|
return Serializer.serializeAllCache(inMemoryCache);
|
|
1519
1315
|
}
|
|
1520
1316
|
/**
|
|
1521
1317
|
* Updates a credential's cache key if the current cache key is outdated
|
|
1522
1318
|
*/
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
1319
|
updateCredentialCacheKey(currentCacheKey, credential) {
|
|
1526
1320
|
const updatedCacheKey = credential.generateCredentialKey();
|
|
1527
|
-
|
|
1528
1321
|
if (currentCacheKey !== updatedCacheKey) {
|
|
1529
1322
|
const cacheItem = this.getItem(currentCacheKey);
|
|
1530
|
-
|
|
1531
1323
|
if (cacheItem) {
|
|
1532
1324
|
this.removeItem(currentCacheKey);
|
|
1533
1325
|
this.setItem(updatedCacheKey, cacheItem);
|
|
@@ -1537,10 +1329,8 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1537
1329
|
this.logger.error(`Attempted to update an outdated ${credential.credentialType} cache key but no item matching the outdated key was found in storage`);
|
|
1538
1330
|
}
|
|
1539
1331
|
}
|
|
1540
|
-
|
|
1541
1332
|
return currentCacheKey;
|
|
1542
1333
|
}
|
|
1543
|
-
|
|
1544
1334
|
}
|
|
1545
1335
|
|
|
1546
1336
|
/*
|
|
@@ -1558,43 +1348,35 @@ const defaultSerializedCache = {
|
|
|
1558
1348
|
* In-memory token cache manager
|
|
1559
1349
|
* @public
|
|
1560
1350
|
*/
|
|
1561
|
-
|
|
1562
1351
|
class TokenCache {
|
|
1563
1352
|
constructor(storage, logger, cachePlugin) {
|
|
1564
1353
|
this.cacheHasChanged = false;
|
|
1565
1354
|
this.storage = storage;
|
|
1566
1355
|
this.storage.registerChangeEmitter(this.handleChangeEvent.bind(this));
|
|
1567
|
-
|
|
1568
1356
|
if (cachePlugin) {
|
|
1569
1357
|
this.persistence = cachePlugin;
|
|
1570
1358
|
}
|
|
1571
|
-
|
|
1572
1359
|
this.logger = logger;
|
|
1573
1360
|
}
|
|
1574
1361
|
/**
|
|
1575
1362
|
* Set to true if cache state has changed since last time serialize or writeToPersistence was called
|
|
1576
1363
|
*/
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
1364
|
hasChanged() {
|
|
1580
1365
|
return this.cacheHasChanged;
|
|
1581
1366
|
}
|
|
1582
1367
|
/**
|
|
1583
1368
|
* Serializes in memory cache to JSON
|
|
1584
1369
|
*/
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
1370
|
serialize() {
|
|
1588
1371
|
this.logger.trace("Serializing in-memory cache");
|
|
1589
|
-
let finalState = Serializer.serializeAllCache(this.storage.getInMemoryCache());
|
|
1590
|
-
|
|
1372
|
+
let finalState = Serializer.serializeAllCache(this.storage.getInMemoryCache());
|
|
1373
|
+
// if cacheSnapshot not null or empty, merge
|
|
1591
1374
|
if (!msalCommon.StringUtils.isEmpty(this.cacheSnapshot)) {
|
|
1592
1375
|
this.logger.trace("Reading cache snapshot from disk");
|
|
1593
1376
|
finalState = this.mergeState(JSON.parse(this.cacheSnapshot), finalState);
|
|
1594
1377
|
} else {
|
|
1595
1378
|
this.logger.trace("No cache snapshot to merge");
|
|
1596
1379
|
}
|
|
1597
|
-
|
|
1598
1380
|
this.cacheHasChanged = false;
|
|
1599
1381
|
return JSON.stringify(finalState);
|
|
1600
1382
|
}
|
|
@@ -1602,12 +1384,9 @@ class TokenCache {
|
|
|
1602
1384
|
* Deserializes JSON to in-memory cache. JSON should be in MSAL cache schema format
|
|
1603
1385
|
* @param cache - blob formatted cache
|
|
1604
1386
|
*/
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
1387
|
deserialize(cache) {
|
|
1608
1388
|
this.logger.trace("Deserializing JSON to in-memory cache");
|
|
1609
1389
|
this.cacheSnapshot = cache;
|
|
1610
|
-
|
|
1611
1390
|
if (!msalCommon.StringUtils.isEmpty(this.cacheSnapshot)) {
|
|
1612
1391
|
this.logger.trace("Reading cache snapshot from disk");
|
|
1613
1392
|
const deserializedCache = Deserializer.deserializeAllCache(this.overlayDefaults(JSON.parse(this.cacheSnapshot)));
|
|
@@ -1619,26 +1398,20 @@ class TokenCache {
|
|
|
1619
1398
|
/**
|
|
1620
1399
|
* Fetches the cache key-value map
|
|
1621
1400
|
*/
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
1401
|
getKVStore() {
|
|
1625
1402
|
return this.storage.getCache();
|
|
1626
1403
|
}
|
|
1627
1404
|
/**
|
|
1628
1405
|
* API that retrieves all accounts currently in cache to the user
|
|
1629
1406
|
*/
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
1407
|
async getAllAccounts() {
|
|
1633
1408
|
this.logger.trace("getAllAccounts called");
|
|
1634
1409
|
let cacheContext;
|
|
1635
|
-
|
|
1636
1410
|
try {
|
|
1637
1411
|
if (this.persistence) {
|
|
1638
1412
|
cacheContext = new msalCommon.TokenCacheContext(this, false);
|
|
1639
1413
|
await this.persistence.beforeCacheAccess(cacheContext);
|
|
1640
1414
|
}
|
|
1641
|
-
|
|
1642
1415
|
return this.storage.getAllAccounts();
|
|
1643
1416
|
} finally {
|
|
1644
1417
|
if (this.persistence && cacheContext) {
|
|
@@ -1652,11 +1425,8 @@ class TokenCache {
|
|
|
1652
1425
|
* or null when no matching account is found
|
|
1653
1426
|
* @param homeAccountId - unique identifier for an account (uid.utid)
|
|
1654
1427
|
*/
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
1428
|
async getAccountByHomeId(homeAccountId) {
|
|
1658
1429
|
const allAccounts = await this.getAllAccounts();
|
|
1659
|
-
|
|
1660
1430
|
if (!msalCommon.StringUtils.isEmpty(homeAccountId) && allAccounts && allAccounts.length) {
|
|
1661
1431
|
return allAccounts.filter(accountObj => accountObj.homeAccountId === homeAccountId)[0] || null;
|
|
1662
1432
|
} else {
|
|
@@ -1669,11 +1439,8 @@ class TokenCache {
|
|
|
1669
1439
|
* or null when no matching account is found
|
|
1670
1440
|
* @param localAccountId - unique identifier of an account (sub/obj when homeAccountId cannot be populated)
|
|
1671
1441
|
*/
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
1442
|
async getAccountByLocalId(localAccountId) {
|
|
1675
1443
|
const allAccounts = await this.getAllAccounts();
|
|
1676
|
-
|
|
1677
1444
|
if (!msalCommon.StringUtils.isEmpty(localAccountId) && allAccounts && allAccounts.length) {
|
|
1678
1445
|
return allAccounts.filter(accountObj => accountObj.localAccountId === localAccountId)[0] || null;
|
|
1679
1446
|
} else {
|
|
@@ -1684,18 +1451,14 @@ class TokenCache {
|
|
|
1684
1451
|
* API to remove a specific account and the relevant data from cache
|
|
1685
1452
|
* @param account - AccountInfo passed by the user
|
|
1686
1453
|
*/
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
1454
|
async removeAccount(account) {
|
|
1690
1455
|
this.logger.trace("removeAccount called");
|
|
1691
1456
|
let cacheContext;
|
|
1692
|
-
|
|
1693
1457
|
try {
|
|
1694
1458
|
if (this.persistence) {
|
|
1695
1459
|
cacheContext = new msalCommon.TokenCacheContext(this, true);
|
|
1696
1460
|
await this.persistence.beforeCacheAccess(cacheContext);
|
|
1697
1461
|
}
|
|
1698
|
-
|
|
1699
1462
|
await this.storage.removeAccount(msalCommon.AccountEntity.generateAccountCacheKey(account));
|
|
1700
1463
|
} finally {
|
|
1701
1464
|
if (this.persistence && cacheContext) {
|
|
@@ -1706,8 +1469,6 @@ class TokenCache {
|
|
|
1706
1469
|
/**
|
|
1707
1470
|
* Called when the cache has changed state.
|
|
1708
1471
|
*/
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
1472
|
handleChangeEvent() {
|
|
1712
1473
|
this.cacheHasChanged = true;
|
|
1713
1474
|
}
|
|
@@ -1716,8 +1477,6 @@ class TokenCache {
|
|
|
1716
1477
|
* @param oldState - cache before changes
|
|
1717
1478
|
* @param currentState - current cache state in the library
|
|
1718
1479
|
*/
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
1480
|
mergeState(oldState, currentState) {
|
|
1722
1481
|
this.logger.trace("Merging in-memory cache with cache snapshot");
|
|
1723
1482
|
const stateAfterRemoval = this.mergeRemovals(oldState, currentState);
|
|
@@ -1728,12 +1487,10 @@ class TokenCache {
|
|
|
1728
1487
|
* @param oldState - cache before changes
|
|
1729
1488
|
* @param newState - updated cache
|
|
1730
1489
|
*/
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
1490
|
mergeUpdates(oldState, newState) {
|
|
1734
1491
|
Object.keys(newState).forEach(newKey => {
|
|
1735
|
-
const newValue = newState[newKey];
|
|
1736
|
-
|
|
1492
|
+
const newValue = newState[newKey];
|
|
1493
|
+
// if oldState does not contain value but newValue does, add it
|
|
1737
1494
|
if (!oldState.hasOwnProperty(newKey)) {
|
|
1738
1495
|
if (newValue !== null) {
|
|
1739
1496
|
oldState[newKey] = newValue;
|
|
@@ -1744,7 +1501,6 @@ class TokenCache {
|
|
|
1744
1501
|
const newValueIsObject = typeof newValue === "object";
|
|
1745
1502
|
const newValueIsNotArray = !Array.isArray(newValue);
|
|
1746
1503
|
const oldStateNotUndefinedOrNull = typeof oldState[newKey] !== "undefined" && oldState[newKey] !== null;
|
|
1747
|
-
|
|
1748
1504
|
if (newValueNotNull && newValueIsObject && newValueIsNotArray && oldStateNotUndefinedOrNull) {
|
|
1749
1505
|
this.mergeUpdates(oldState[newKey], newValue);
|
|
1750
1506
|
} else {
|
|
@@ -1760,8 +1516,6 @@ class TokenCache {
|
|
|
1760
1516
|
* @param oldState - cache before changes
|
|
1761
1517
|
* @param newState - updated cache
|
|
1762
1518
|
*/
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
1519
|
mergeRemovals(oldState, newState) {
|
|
1766
1520
|
this.logger.trace("Remove updated entries in cache");
|
|
1767
1521
|
const accounts = oldState.Account ? this.mergeRemovalsDict(oldState.Account, newState.Account) : oldState.Account;
|
|
@@ -1769,7 +1523,8 @@ class TokenCache {
|
|
|
1769
1523
|
const refreshTokens = oldState.RefreshToken ? this.mergeRemovalsDict(oldState.RefreshToken, newState.RefreshToken) : oldState.RefreshToken;
|
|
1770
1524
|
const idTokens = oldState.IdToken ? this.mergeRemovalsDict(oldState.IdToken, newState.IdToken) : oldState.IdToken;
|
|
1771
1525
|
const appMetadata = oldState.AppMetadata ? this.mergeRemovalsDict(oldState.AppMetadata, newState.AppMetadata) : oldState.AppMetadata;
|
|
1772
|
-
return {
|
|
1526
|
+
return {
|
|
1527
|
+
...oldState,
|
|
1773
1528
|
Account: accounts,
|
|
1774
1529
|
AccessToken: accessTokens,
|
|
1775
1530
|
RefreshToken: refreshTokens,
|
|
@@ -1782,10 +1537,9 @@ class TokenCache {
|
|
|
1782
1537
|
* @param oldState - cache before changes
|
|
1783
1538
|
* @param newState - updated cache
|
|
1784
1539
|
*/
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
1540
|
mergeRemovalsDict(oldState, newState) {
|
|
1788
|
-
const finalState = {
|
|
1541
|
+
const finalState = {
|
|
1542
|
+
...oldState
|
|
1789
1543
|
};
|
|
1790
1544
|
Object.keys(oldState).forEach(oldKey => {
|
|
1791
1545
|
if (!newState || !newState.hasOwnProperty(oldKey)) {
|
|
@@ -1798,34 +1552,36 @@ class TokenCache {
|
|
|
1798
1552
|
* Helper to overlay as a part of cache merge
|
|
1799
1553
|
* @param passedInCache - cache read from the blob
|
|
1800
1554
|
*/
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
1555
|
overlayDefaults(passedInCache) {
|
|
1804
1556
|
this.logger.trace("Overlaying input cache with the default cache");
|
|
1805
1557
|
return {
|
|
1806
|
-
Account: {
|
|
1558
|
+
Account: {
|
|
1559
|
+
...defaultSerializedCache.Account,
|
|
1807
1560
|
...passedInCache.Account
|
|
1808
1561
|
},
|
|
1809
|
-
IdToken: {
|
|
1562
|
+
IdToken: {
|
|
1563
|
+
...defaultSerializedCache.IdToken,
|
|
1810
1564
|
...passedInCache.IdToken
|
|
1811
1565
|
},
|
|
1812
|
-
AccessToken: {
|
|
1566
|
+
AccessToken: {
|
|
1567
|
+
...defaultSerializedCache.AccessToken,
|
|
1813
1568
|
...passedInCache.AccessToken
|
|
1814
1569
|
},
|
|
1815
|
-
RefreshToken: {
|
|
1570
|
+
RefreshToken: {
|
|
1571
|
+
...defaultSerializedCache.RefreshToken,
|
|
1816
1572
|
...passedInCache.RefreshToken
|
|
1817
1573
|
},
|
|
1818
|
-
AppMetadata: {
|
|
1574
|
+
AppMetadata: {
|
|
1575
|
+
...defaultSerializedCache.AppMetadata,
|
|
1819
1576
|
...passedInCache.AppMetadata
|
|
1820
1577
|
}
|
|
1821
1578
|
};
|
|
1822
1579
|
}
|
|
1823
|
-
|
|
1824
1580
|
}
|
|
1825
1581
|
|
|
1826
1582
|
/* eslint-disable header/header */
|
|
1827
1583
|
const name = "@azure/msal-node";
|
|
1828
|
-
const version = "1.14.
|
|
1584
|
+
const version = "1.14.6";
|
|
1829
1585
|
|
|
1830
1586
|
/*
|
|
1831
1587
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1834,7 +1590,6 @@ const version = "1.14.4";
|
|
|
1834
1590
|
/**
|
|
1835
1591
|
* NodeAuthErrorMessage class containing string constants used by error codes and messages.
|
|
1836
1592
|
*/
|
|
1837
|
-
|
|
1838
1593
|
const NodeAuthErrorMessage = {
|
|
1839
1594
|
invalidLoopbackAddressType: {
|
|
1840
1595
|
code: "invalid_loopback_server_address_type",
|
|
@@ -1873,60 +1628,45 @@ class NodeAuthError extends msalCommon.AuthError {
|
|
|
1873
1628
|
/**
|
|
1874
1629
|
* Creates an error thrown if loopback server address is of type string.
|
|
1875
1630
|
*/
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
1631
|
static createInvalidLoopbackAddressTypeError() {
|
|
1879
1632
|
return new NodeAuthError(NodeAuthErrorMessage.invalidLoopbackAddressType.code, `${NodeAuthErrorMessage.invalidLoopbackAddressType.desc}`);
|
|
1880
1633
|
}
|
|
1881
1634
|
/**
|
|
1882
1635
|
* Creates an error thrown if the loopback server is unable to get a url.
|
|
1883
1636
|
*/
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
1637
|
static createUnableToLoadRedirectUrlError() {
|
|
1887
1638
|
return new NodeAuthError(NodeAuthErrorMessage.unableToLoadRedirectUri.code, `${NodeAuthErrorMessage.unableToLoadRedirectUri.desc}`);
|
|
1888
1639
|
}
|
|
1889
1640
|
/**
|
|
1890
1641
|
* Creates an error thrown if the server response does not contain an auth code.
|
|
1891
1642
|
*/
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
1643
|
static createNoAuthCodeInResponseError() {
|
|
1895
1644
|
return new NodeAuthError(NodeAuthErrorMessage.noAuthCodeInResponse.code, `${NodeAuthErrorMessage.noAuthCodeInResponse.desc}`);
|
|
1896
1645
|
}
|
|
1897
1646
|
/**
|
|
1898
1647
|
* Creates an error thrown if the loopback server has not been spun up yet.
|
|
1899
1648
|
*/
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
1649
|
static createNoLoopbackServerExistsError() {
|
|
1903
1650
|
return new NodeAuthError(NodeAuthErrorMessage.noLoopbackServerExists.code, `${NodeAuthErrorMessage.noLoopbackServerExists.desc}`);
|
|
1904
1651
|
}
|
|
1905
1652
|
/**
|
|
1906
1653
|
* Creates an error thrown if a loopback server already exists when attempting to create another one.
|
|
1907
1654
|
*/
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
1655
|
static createLoopbackServerAlreadyExistsError() {
|
|
1911
1656
|
return new NodeAuthError(NodeAuthErrorMessage.loopbackServerAlreadyExists.code, `${NodeAuthErrorMessage.loopbackServerAlreadyExists.desc}`);
|
|
1912
1657
|
}
|
|
1913
1658
|
/**
|
|
1914
1659
|
* Creates an error thrown if the loopback server times out registering the auth code listener.
|
|
1915
1660
|
*/
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
1661
|
static createLoopbackServerTimeoutError() {
|
|
1919
1662
|
return new NodeAuthError(NodeAuthErrorMessage.loopbackServerTimeout.code, `${NodeAuthErrorMessage.loopbackServerTimeout.desc}`);
|
|
1920
1663
|
}
|
|
1921
1664
|
/**
|
|
1922
1665
|
* Creates an error thrown when the state is not present.
|
|
1923
1666
|
*/
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
1667
|
static createStateNotFoundError() {
|
|
1927
1668
|
return new NodeAuthError(NodeAuthErrorMessage.stateNotFoundError.code, NodeAuthErrorMessage.stateNotFoundError.desc);
|
|
1928
1669
|
}
|
|
1929
|
-
|
|
1930
1670
|
}
|
|
1931
1671
|
|
|
1932
1672
|
/*
|
|
@@ -1937,7 +1677,6 @@ class NodeAuthError extends msalCommon.AuthError {
|
|
|
1937
1677
|
* Base abstract class for all ClientApplications - public and confidential
|
|
1938
1678
|
* @public
|
|
1939
1679
|
*/
|
|
1940
|
-
|
|
1941
1680
|
class ClientApplication {
|
|
1942
1681
|
/**
|
|
1943
1682
|
* Constructor for the ClientApplication
|
|
@@ -1958,11 +1697,10 @@ class ClientApplication {
|
|
|
1958
1697
|
* sent in the request and should contain an authorization code, which can then be used to acquire tokens via
|
|
1959
1698
|
* `acquireTokenByCode(AuthorizationCodeRequest)`.
|
|
1960
1699
|
*/
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
1700
|
async getAuthCodeUrl(request) {
|
|
1964
1701
|
this.logger.info("getAuthCodeUrl called", request.correlationId);
|
|
1965
|
-
const validRequest = {
|
|
1702
|
+
const validRequest = {
|
|
1703
|
+
...request,
|
|
1966
1704
|
...(await this.initializeBaseRequest(request)),
|
|
1967
1705
|
responseMode: request.responseMode || msalCommon.ResponseMode.QUERY,
|
|
1968
1706
|
authenticationScheme: msalCommon.AuthenticationScheme.BEARER
|
|
@@ -1980,26 +1718,23 @@ class ClientApplication {
|
|
|
1980
1718
|
* Authorization Code flow. Ensure that values for redirectUri and scopes in AuthorizationCodeUrlRequest and
|
|
1981
1719
|
* AuthorizationCodeRequest are the same.
|
|
1982
1720
|
*/
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
1721
|
async acquireTokenByCode(request, authCodePayLoad) {
|
|
1986
1722
|
this.logger.info("acquireTokenByCode called");
|
|
1987
|
-
|
|
1988
1723
|
if (request.state && authCodePayLoad) {
|
|
1989
1724
|
this.logger.info("acquireTokenByCode - validating state");
|
|
1990
|
-
this.validateState(request.state, authCodePayLoad.state || "");
|
|
1991
|
-
|
|
1992
|
-
authCodePayLoad = {
|
|
1725
|
+
this.validateState(request.state, authCodePayLoad.state || "");
|
|
1726
|
+
// eslint-disable-next-line no-param-reassign
|
|
1727
|
+
authCodePayLoad = {
|
|
1728
|
+
...authCodePayLoad,
|
|
1993
1729
|
state: ""
|
|
1994
1730
|
};
|
|
1995
1731
|
}
|
|
1996
|
-
|
|
1997
|
-
|
|
1732
|
+
const validRequest = {
|
|
1733
|
+
...request,
|
|
1998
1734
|
...(await this.initializeBaseRequest(request)),
|
|
1999
1735
|
authenticationScheme: msalCommon.AuthenticationScheme.BEARER
|
|
2000
1736
|
};
|
|
2001
1737
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByCode, validRequest.correlationId);
|
|
2002
|
-
|
|
2003
1738
|
try {
|
|
2004
1739
|
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
2005
1740
|
const authorizationCodeClient = new msalCommon.AuthorizationCodeClient(authClientConfig);
|
|
@@ -2009,7 +1744,6 @@ class ClientApplication {
|
|
|
2009
1744
|
if (e instanceof msalCommon.AuthError) {
|
|
2010
1745
|
e.setCorrelationId(validRequest.correlationId);
|
|
2011
1746
|
}
|
|
2012
|
-
|
|
2013
1747
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2014
1748
|
throw e;
|
|
2015
1749
|
}
|
|
@@ -2021,16 +1755,14 @@ class ClientApplication {
|
|
|
2021
1755
|
* recommended that you use `acquireTokenSilent()` for silent scenarios. When using `acquireTokenSilent()`, MSAL will
|
|
2022
1756
|
* handle the caching and refreshing of tokens automatically.
|
|
2023
1757
|
*/
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
1758
|
async acquireTokenByRefreshToken(request) {
|
|
2027
1759
|
this.logger.info("acquireTokenByRefreshToken called", request.correlationId);
|
|
2028
|
-
const validRequest = {
|
|
1760
|
+
const validRequest = {
|
|
1761
|
+
...request,
|
|
2029
1762
|
...(await this.initializeBaseRequest(request)),
|
|
2030
1763
|
authenticationScheme: msalCommon.AuthenticationScheme.BEARER
|
|
2031
1764
|
};
|
|
2032
1765
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByRefreshToken, validRequest.correlationId);
|
|
2033
|
-
|
|
2034
1766
|
try {
|
|
2035
1767
|
const refreshTokenClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
2036
1768
|
const refreshTokenClient = new msalCommon.RefreshTokenClient(refreshTokenClientConfig);
|
|
@@ -2040,7 +1772,6 @@ class ClientApplication {
|
|
|
2040
1772
|
if (e instanceof msalCommon.AuthError) {
|
|
2041
1773
|
e.setCorrelationId(validRequest.correlationId);
|
|
2042
1774
|
}
|
|
2043
|
-
|
|
2044
1775
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2045
1776
|
throw e;
|
|
2046
1777
|
}
|
|
@@ -2053,15 +1784,13 @@ class ClientApplication {
|
|
|
2053
1784
|
* In case the refresh_token is expired or not found, an error is thrown
|
|
2054
1785
|
* and the guidance is for the user to call any interactive token acquisition API (eg: `acquireTokenByCode()`).
|
|
2055
1786
|
*/
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
1787
|
async acquireTokenSilent(request) {
|
|
2059
|
-
const validRequest = {
|
|
1788
|
+
const validRequest = {
|
|
1789
|
+
...request,
|
|
2060
1790
|
...(await this.initializeBaseRequest(request)),
|
|
2061
1791
|
forceRefresh: request.forceRefresh || false
|
|
2062
1792
|
};
|
|
2063
1793
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent, validRequest.correlationId, validRequest.forceRefresh);
|
|
2064
|
-
|
|
2065
1794
|
try {
|
|
2066
1795
|
const silentFlowClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
2067
1796
|
const silentFlowClient = new msalCommon.SilentFlowClient(silentFlowClientConfig);
|
|
@@ -2071,7 +1800,6 @@ class ClientApplication {
|
|
|
2071
1800
|
if (e instanceof msalCommon.AuthError) {
|
|
2072
1801
|
e.setCorrelationId(validRequest.correlationId);
|
|
2073
1802
|
}
|
|
2074
|
-
|
|
2075
1803
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2076
1804
|
throw e;
|
|
2077
1805
|
}
|
|
@@ -2086,15 +1814,13 @@ class ClientApplication {
|
|
|
2086
1814
|
*
|
|
2087
1815
|
* @param request - UsenamePasswordRequest
|
|
2088
1816
|
*/
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
1817
|
async acquireTokenByUsernamePassword(request) {
|
|
2092
1818
|
this.logger.info("acquireTokenByUsernamePassword called", request.correlationId);
|
|
2093
|
-
const validRequest = {
|
|
1819
|
+
const validRequest = {
|
|
1820
|
+
...request,
|
|
2094
1821
|
...(await this.initializeBaseRequest(request))
|
|
2095
1822
|
};
|
|
2096
1823
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByUsernamePassword, validRequest.correlationId);
|
|
2097
|
-
|
|
2098
1824
|
try {
|
|
2099
1825
|
const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
2100
1826
|
const usernamePasswordClient = new msalCommon.UsernamePasswordClient(usernamePasswordClientConfig);
|
|
@@ -2104,7 +1830,6 @@ class ClientApplication {
|
|
|
2104
1830
|
if (e instanceof msalCommon.AuthError) {
|
|
2105
1831
|
e.setCorrelationId(validRequest.correlationId);
|
|
2106
1832
|
}
|
|
2107
|
-
|
|
2108
1833
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2109
1834
|
throw e;
|
|
2110
1835
|
}
|
|
@@ -2112,8 +1837,6 @@ class ClientApplication {
|
|
|
2112
1837
|
/**
|
|
2113
1838
|
* Gets the token cache for the application.
|
|
2114
1839
|
*/
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
1840
|
getTokenCache() {
|
|
2118
1841
|
this.logger.info("getTokenCache called");
|
|
2119
1842
|
return this.tokenCache;
|
|
@@ -2127,13 +1850,10 @@ class ClientApplication {
|
|
|
2127
1850
|
* @param state
|
|
2128
1851
|
* @param cachedState
|
|
2129
1852
|
*/
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
1853
|
validateState(state, cachedState) {
|
|
2133
1854
|
if (!state) {
|
|
2134
1855
|
throw NodeAuthError.createStateNotFoundError();
|
|
2135
1856
|
}
|
|
2136
|
-
|
|
2137
1857
|
if (state !== cachedState) {
|
|
2138
1858
|
throw msalCommon.ClientAuthError.createStateMismatchError();
|
|
2139
1859
|
}
|
|
@@ -2141,8 +1861,6 @@ class ClientApplication {
|
|
|
2141
1861
|
/**
|
|
2142
1862
|
* Returns the logger instance
|
|
2143
1863
|
*/
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
1864
|
getLogger() {
|
|
2147
1865
|
return this.logger;
|
|
2148
1866
|
}
|
|
@@ -2150,8 +1868,6 @@ class ClientApplication {
|
|
|
2150
1868
|
* Replaces the default logger set in configurations with new Logger with new configurations
|
|
2151
1869
|
* @param logger - Logger instance
|
|
2152
1870
|
*/
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
1871
|
setLogger(logger) {
|
|
2156
1872
|
this.logger = logger;
|
|
2157
1873
|
}
|
|
@@ -2160,13 +1876,11 @@ class ClientApplication {
|
|
|
2160
1876
|
* @param authority - user passed authority in configuration
|
|
2161
1877
|
* @param serverTelemetryManager - initializes servertelemetry if passed
|
|
2162
1878
|
*/
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
1879
|
async buildOauthClientConfiguration(authority, requestCorrelationId, serverTelemetryManager, azureRegionConfiguration, azureCloudOptions) {
|
|
2166
|
-
this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId);
|
|
2167
|
-
|
|
2168
|
-
const userAzureCloudOptions = azureCloudOptions ? azureCloudOptions : this.config.auth.azureCloudOptions;
|
|
2169
|
-
|
|
1880
|
+
this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId);
|
|
1881
|
+
// precedence - azureCloudInstance + tenant >> authority and request >> config
|
|
1882
|
+
const userAzureCloudOptions = azureCloudOptions ? azureCloudOptions : this.config.auth.azureCloudOptions;
|
|
1883
|
+
// using null assertion operator as we ensure that all config values have default values in buildConfiguration()
|
|
2170
1884
|
this.logger.verbose(`building oauth client configuration with the authority: ${authority}`, requestCorrelationId);
|
|
2171
1885
|
const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId, userAzureCloudOptions);
|
|
2172
1886
|
serverTelemetryManager == null ? void 0 : serverTelemetryManager.updateRegionDiscoveryMetadata(discoveredAuthority.regionDiscoveryMetadata);
|
|
@@ -2205,7 +1919,6 @@ class ClientApplication {
|
|
|
2205
1919
|
};
|
|
2206
1920
|
return clientConfiguration;
|
|
2207
1921
|
}
|
|
2208
|
-
|
|
2209
1922
|
getClientAssertion(authority) {
|
|
2210
1923
|
return {
|
|
2211
1924
|
assertion: this.clientAssertion.getJwt(this.cryptoProvider, this.config.auth.clientId, authority.tokenEndpoint),
|
|
@@ -2216,22 +1929,19 @@ class ClientApplication {
|
|
|
2216
1929
|
* Generates a request with the default scopes & generates a correlationId.
|
|
2217
1930
|
* @param authRequest - BaseAuthRequest for initialization
|
|
2218
1931
|
*/
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
1932
|
async initializeBaseRequest(authRequest) {
|
|
2222
|
-
this.logger.verbose("initializeRequestScopes called", authRequest.correlationId);
|
|
2223
|
-
|
|
1933
|
+
this.logger.verbose("initializeRequestScopes called", authRequest.correlationId);
|
|
1934
|
+
// Default authenticationScheme to Bearer, log that POP isn't supported yet
|
|
2224
1935
|
if (authRequest.authenticationScheme && authRequest.authenticationScheme === msalCommon.AuthenticationScheme.POP) {
|
|
2225
1936
|
this.logger.verbose("Authentication Scheme 'pop' is not supported yet, setting Authentication Scheme to 'Bearer' for request", authRequest.correlationId);
|
|
2226
1937
|
}
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
1938
|
+
authRequest.authenticationScheme = msalCommon.AuthenticationScheme.BEARER;
|
|
1939
|
+
// Set requested claims hash if claims were requested
|
|
2230
1940
|
if (authRequest.claims && !msalCommon.StringUtils.isEmpty(authRequest.claims)) {
|
|
2231
1941
|
authRequest.requestedClaimsHash = await this.cryptoProvider.hashString(authRequest.claims);
|
|
2232
1942
|
}
|
|
2233
|
-
|
|
2234
|
-
|
|
1943
|
+
return {
|
|
1944
|
+
...authRequest,
|
|
2235
1945
|
scopes: [...(authRequest && authRequest.scopes || []), ...msalCommon.OIDC_DEFAULT_SCOPES],
|
|
2236
1946
|
correlationId: authRequest && authRequest.correlationId || this.cryptoProvider.createNewGuid(),
|
|
2237
1947
|
authority: authRequest.authority || this.config.auth.authority
|
|
@@ -2243,8 +1953,6 @@ class ClientApplication {
|
|
|
2243
1953
|
* @param correlationId - GUID
|
|
2244
1954
|
* @param forceRefresh - boolean to indicate network call
|
|
2245
1955
|
*/
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
1956
|
initializeServerTelemetryManager(apiId, correlationId, forceRefresh) {
|
|
2249
1957
|
const telemetryPayload = {
|
|
2250
1958
|
clientId: this.config.auth.clientId,
|
|
@@ -2259,11 +1967,9 @@ class ClientApplication {
|
|
|
2259
1967
|
* object. If no authority set in application object, then default to common authority.
|
|
2260
1968
|
* @param authorityString - authority from user configuration
|
|
2261
1969
|
*/
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
1970
|
async createAuthority(authorityString, azureRegionConfiguration, requestCorrelationId, azureCloudOptions) {
|
|
2265
|
-
this.logger.verbose("createAuthority called", requestCorrelationId);
|
|
2266
|
-
|
|
1971
|
+
this.logger.verbose("createAuthority called", requestCorrelationId);
|
|
1972
|
+
// build authority string based on auth params - azureCloudInstance is prioritized if provided
|
|
2267
1973
|
const authorityUrl = msalCommon.Authority.generateAuthority(authorityString, azureCloudOptions);
|
|
2268
1974
|
const authorityOptions = {
|
|
2269
1975
|
protocolMode: this.config.auth.protocolMode,
|
|
@@ -2278,12 +1984,9 @@ class ClientApplication {
|
|
|
2278
1984
|
/**
|
|
2279
1985
|
* Clear the cache
|
|
2280
1986
|
*/
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
1987
|
clearCache() {
|
|
2284
1988
|
this.storage.clear();
|
|
2285
1989
|
}
|
|
2286
|
-
|
|
2287
1990
|
}
|
|
2288
1991
|
|
|
2289
1992
|
/*
|
|
@@ -2301,11 +2004,9 @@ class LoopbackClient {
|
|
|
2301
2004
|
if (!!this.server) {
|
|
2302
2005
|
throw NodeAuthError.createLoopbackServerAlreadyExistsError();
|
|
2303
2006
|
}
|
|
2304
|
-
|
|
2305
2007
|
const authCodeListener = new Promise((resolve, reject) => {
|
|
2306
2008
|
this.server = http.createServer(async (req, res) => {
|
|
2307
2009
|
const url = req.url;
|
|
2308
|
-
|
|
2309
2010
|
if (!url) {
|
|
2310
2011
|
res.end(errorTemplate || "Error occurred loading redirectUrl");
|
|
2311
2012
|
reject(NodeAuthError.createUnableToLoadRedirectUrlError());
|
|
@@ -2314,35 +2015,29 @@ class LoopbackClient {
|
|
|
2314
2015
|
res.end(successTemplate || "Auth code was successfully acquired. You can close this window now.");
|
|
2315
2016
|
return;
|
|
2316
2017
|
}
|
|
2317
|
-
|
|
2318
2018
|
const authCodeResponse = msalCommon.UrlString.getDeserializedQueryString(url);
|
|
2319
|
-
|
|
2320
2019
|
if (authCodeResponse.code) {
|
|
2321
2020
|
const redirectUri = await this.getRedirectUri();
|
|
2322
2021
|
res.writeHead(HttpStatus.REDIRECT, {
|
|
2323
2022
|
location: redirectUri
|
|
2324
2023
|
}); // Prevent auth code from being saved in the browser history
|
|
2325
|
-
|
|
2326
2024
|
res.end();
|
|
2327
2025
|
}
|
|
2328
|
-
|
|
2329
2026
|
resolve(authCodeResponse);
|
|
2330
2027
|
});
|
|
2331
2028
|
this.server.listen(0); // Listen on any available port
|
|
2332
|
-
});
|
|
2333
|
-
|
|
2029
|
+
});
|
|
2030
|
+
// Wait for server to be listening
|
|
2334
2031
|
await new Promise(resolve => {
|
|
2335
2032
|
let ticks = 0;
|
|
2336
2033
|
const id = setInterval(() => {
|
|
2337
2034
|
if (LOOPBACK_SERVER_CONSTANTS.TIMEOUT_MS / LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS < ticks) {
|
|
2338
2035
|
throw NodeAuthError.createLoopbackServerTimeoutError();
|
|
2339
2036
|
}
|
|
2340
|
-
|
|
2341
2037
|
if (this.server.listening) {
|
|
2342
2038
|
clearInterval(id);
|
|
2343
2039
|
resolve();
|
|
2344
2040
|
}
|
|
2345
|
-
|
|
2346
2041
|
ticks++;
|
|
2347
2042
|
}, LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS);
|
|
2348
2043
|
});
|
|
@@ -2352,34 +2047,26 @@ class LoopbackClient {
|
|
|
2352
2047
|
* Get the port that the loopback server is running on
|
|
2353
2048
|
* @returns
|
|
2354
2049
|
*/
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
2050
|
getRedirectUri() {
|
|
2358
2051
|
if (!this.server) {
|
|
2359
2052
|
throw NodeAuthError.createNoLoopbackServerExistsError();
|
|
2360
2053
|
}
|
|
2361
|
-
|
|
2362
2054
|
const address = this.server.address();
|
|
2363
|
-
|
|
2364
2055
|
if (!address || typeof address === "string" || !address.port) {
|
|
2365
2056
|
this.closeServer();
|
|
2366
2057
|
throw NodeAuthError.createInvalidLoopbackAddressTypeError();
|
|
2367
2058
|
}
|
|
2368
|
-
|
|
2369
2059
|
const port = address && address.port;
|
|
2370
2060
|
return `${Constants.HTTP_PROTOCOL}${Constants.LOCALHOST}:${port}`;
|
|
2371
2061
|
}
|
|
2372
2062
|
/**
|
|
2373
2063
|
* Close the loopback server
|
|
2374
2064
|
*/
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
2065
|
closeServer() {
|
|
2378
2066
|
if (!!this.server) {
|
|
2379
2067
|
this.server.close();
|
|
2380
2068
|
}
|
|
2381
2069
|
}
|
|
2382
|
-
|
|
2383
2070
|
}
|
|
2384
2071
|
|
|
2385
2072
|
/*
|
|
@@ -2391,7 +2078,6 @@ class LoopbackClient {
|
|
|
2391
2078
|
* are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
|
|
2392
2079
|
* @public
|
|
2393
2080
|
*/
|
|
2394
|
-
|
|
2395
2081
|
class PublicClientApplication extends ClientApplication {
|
|
2396
2082
|
/**
|
|
2397
2083
|
* Important attributes in the Configuration object for auth are:
|
|
@@ -2422,13 +2108,10 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2422
2108
|
* Since the client cannot receive incoming requests, it polls the authorization server repeatedly
|
|
2423
2109
|
* until the end-user completes input of credentials.
|
|
2424
2110
|
*/
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
2111
|
async acquireTokenByDeviceCode(request) {
|
|
2428
2112
|
this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
|
|
2429
2113
|
const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
|
|
2430
2114
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
|
|
2431
|
-
|
|
2432
2115
|
try {
|
|
2433
2116
|
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
2434
2117
|
const deviceCodeClient = new msalCommon.DeviceCodeClient(deviceCodeConfig);
|
|
@@ -2438,7 +2121,6 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2438
2121
|
if (e instanceof msalCommon.AuthError) {
|
|
2439
2122
|
e.setCorrelationId(validRequest.correlationId);
|
|
2440
2123
|
}
|
|
2441
|
-
|
|
2442
2124
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2443
2125
|
throw e;
|
|
2444
2126
|
}
|
|
@@ -2446,8 +2128,6 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2446
2128
|
/**
|
|
2447
2129
|
* Acquires a token by requesting an Authorization code then exchanging it for a token.
|
|
2448
2130
|
*/
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
2131
|
async acquireTokenInteractive(request) {
|
|
2452
2132
|
const {
|
|
2453
2133
|
verifier,
|
|
@@ -2462,7 +2142,8 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2462
2142
|
const loopbackClient = new LoopbackClient();
|
|
2463
2143
|
const authCodeListener = loopbackClient.listenForAuthCode(successTemplate, errorTemplate);
|
|
2464
2144
|
const redirectUri = loopbackClient.getRedirectUri();
|
|
2465
|
-
const validRequest = {
|
|
2145
|
+
const validRequest = {
|
|
2146
|
+
...remainingProperties,
|
|
2466
2147
|
scopes: request.scopes || msalCommon.OIDC_DEFAULT_SCOPES,
|
|
2467
2148
|
redirectUri: redirectUri,
|
|
2468
2149
|
responseMode: msalCommon.ResponseMode.QUERY,
|
|
@@ -2474,13 +2155,11 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2474
2155
|
const authCodeResponse = await authCodeListener.finally(() => {
|
|
2475
2156
|
loopbackClient.closeServer();
|
|
2476
2157
|
});
|
|
2477
|
-
|
|
2478
2158
|
if (authCodeResponse.error) {
|
|
2479
2159
|
throw new msalCommon.ServerError(authCodeResponse.error, authCodeResponse.error_description, authCodeResponse.suberror);
|
|
2480
2160
|
} else if (!authCodeResponse.code) {
|
|
2481
2161
|
throw NodeAuthError.createNoAuthCodeInResponseError();
|
|
2482
2162
|
}
|
|
2483
|
-
|
|
2484
2163
|
const clientInfo = authCodeResponse.client_info;
|
|
2485
2164
|
const tokenRequest = {
|
|
2486
2165
|
code: authCodeResponse.code,
|
|
@@ -2490,7 +2169,6 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2490
2169
|
};
|
|
2491
2170
|
return this.acquireTokenByCode(tokenRequest);
|
|
2492
2171
|
}
|
|
2493
|
-
|
|
2494
2172
|
}
|
|
2495
2173
|
|
|
2496
2174
|
/*
|
|
@@ -2501,7 +2179,6 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2501
2179
|
* Client assertion of type jwt-bearer used in confidential client flows
|
|
2502
2180
|
* @public
|
|
2503
2181
|
*/
|
|
2504
|
-
|
|
2505
2182
|
class ClientAssertion {
|
|
2506
2183
|
/**
|
|
2507
2184
|
* Initialize the ClientAssertion class from the clientAssertion passed by the user
|
|
@@ -2518,17 +2195,13 @@ class ClientAssertion {
|
|
|
2518
2195
|
* @param privateKey - secret key
|
|
2519
2196
|
* @param publicCertificate - electronic document provided to prove the ownership of the public key
|
|
2520
2197
|
*/
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
2198
|
static fromCertificate(thumbprint, privateKey, publicCertificate) {
|
|
2524
2199
|
const clientAssertion = new ClientAssertion();
|
|
2525
2200
|
clientAssertion.privateKey = privateKey;
|
|
2526
2201
|
clientAssertion.thumbprint = thumbprint;
|
|
2527
|
-
|
|
2528
2202
|
if (publicCertificate) {
|
|
2529
2203
|
clientAssertion.publicCertificate = this.parseCertificate(publicCertificate);
|
|
2530
2204
|
}
|
|
2531
|
-
|
|
2532
2205
|
return clientAssertion;
|
|
2533
2206
|
}
|
|
2534
2207
|
/**
|
|
@@ -2537,34 +2210,26 @@ class ClientAssertion {
|
|
|
2537
2210
|
* @param issuer - iss claim
|
|
2538
2211
|
* @param jwtAudience - aud claim
|
|
2539
2212
|
*/
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
2213
|
getJwt(cryptoProvider, issuer, jwtAudience) {
|
|
2543
2214
|
// if assertion was created from certificate, check if jwt is expired and create new one.
|
|
2544
2215
|
if (this.privateKey && this.thumbprint) {
|
|
2545
2216
|
if (this.jwt && !this.isExpired() && issuer === this.issuer && jwtAudience === this.jwtAudience) {
|
|
2546
2217
|
return this.jwt;
|
|
2547
2218
|
}
|
|
2548
|
-
|
|
2549
2219
|
return this.createJwt(cryptoProvider, issuer, jwtAudience);
|
|
2550
2220
|
}
|
|
2551
2221
|
/*
|
|
2552
2222
|
* if assertion was created by caller, then we just append it. It is up to the caller to
|
|
2553
2223
|
* ensure that it contains necessary claims and that it is not expired.
|
|
2554
2224
|
*/
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
2225
|
if (this.jwt) {
|
|
2558
2226
|
return this.jwt;
|
|
2559
2227
|
}
|
|
2560
|
-
|
|
2561
2228
|
throw msalCommon.ClientAuthError.createInvalidAssertionError();
|
|
2562
2229
|
}
|
|
2563
2230
|
/**
|
|
2564
2231
|
* JWT format and required claims specified: https://tools.ietf.org/html/rfc7523#section-3
|
|
2565
2232
|
*/
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
2233
|
createJwt(cryptoProvider, issuer, jwtAudience) {
|
|
2569
2234
|
this.issuer = issuer;
|
|
2570
2235
|
this.jwtAudience = jwtAudience;
|
|
@@ -2574,13 +2239,11 @@ class ClientAssertion {
|
|
|
2574
2239
|
alg: JwtConstants.RSA_256,
|
|
2575
2240
|
x5t: EncodingUtils.base64EncodeUrl(this.thumbprint, "hex")
|
|
2576
2241
|
};
|
|
2577
|
-
|
|
2578
2242
|
if (this.publicCertificate) {
|
|
2579
2243
|
Object.assign(header, {
|
|
2580
2244
|
x5c: this.publicCertificate
|
|
2581
2245
|
});
|
|
2582
2246
|
}
|
|
2583
|
-
|
|
2584
2247
|
const payload = {
|
|
2585
2248
|
[JwtConstants.AUDIENCE]: this.jwtAudience,
|
|
2586
2249
|
[JwtConstants.EXPIRATION_TIME]: this.expirationTime,
|
|
@@ -2597,8 +2260,6 @@ class ClientAssertion {
|
|
|
2597
2260
|
/**
|
|
2598
2261
|
* Utility API to check expiration
|
|
2599
2262
|
*/
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
2263
|
isExpired() {
|
|
2603
2264
|
return this.expirationTime < msalCommon.TimeUtils.nowSeconds();
|
|
2604
2265
|
}
|
|
@@ -2606,8 +2267,6 @@ class ClientAssertion {
|
|
|
2606
2267
|
* Extracts the raw certs from a given certificate string and returns them in an array.
|
|
2607
2268
|
* @param publicCertificate - electronic document provided to prove the ownership of the public key
|
|
2608
2269
|
*/
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
2270
|
static parseCertificate(publicCertificate) {
|
|
2612
2271
|
/**
|
|
2613
2272
|
* This is regex to identify the certs in a given certificate string.
|
|
@@ -2619,15 +2278,12 @@ class ClientAssertion {
|
|
|
2619
2278
|
const regexToFindCerts = /-----BEGIN CERTIFICATE-----\r*\n(.+?)\r*\n-----END CERTIFICATE-----/gs;
|
|
2620
2279
|
const certs = [];
|
|
2621
2280
|
let matches;
|
|
2622
|
-
|
|
2623
2281
|
while ((matches = regexToFindCerts.exec(publicCertificate)) !== null) {
|
|
2624
2282
|
// matches[1] represents the first parens capture group in the regex.
|
|
2625
2283
|
certs.push(matches[1].replace(/\r*\n/g, msalCommon.Constants.EMPTY_STRING));
|
|
2626
2284
|
}
|
|
2627
|
-
|
|
2628
2285
|
return certs;
|
|
2629
2286
|
}
|
|
2630
|
-
|
|
2631
2287
|
}
|
|
2632
2288
|
|
|
2633
2289
|
/*
|
|
@@ -2639,7 +2295,6 @@ class ClientAssertion {
|
|
|
2639
2295
|
* will configure application secrets, client certificates/assertions as applicable
|
|
2640
2296
|
* @public
|
|
2641
2297
|
*/
|
|
2642
|
-
|
|
2643
2298
|
class ConfidentialClientApplication extends ClientApplication {
|
|
2644
2299
|
/**
|
|
2645
2300
|
* Constructor for the ConfidentialClientApplication
|
|
@@ -2671,34 +2326,30 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2671
2326
|
*
|
|
2672
2327
|
* @param IAppTokenProvider - Extensibility interface, which allows the app developer to return a token from a custom source.
|
|
2673
2328
|
*/
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
2329
|
SetAppTokenProvider(provider) {
|
|
2677
2330
|
this.appTokenProvider = provider;
|
|
2678
2331
|
}
|
|
2679
2332
|
/**
|
|
2680
2333
|
* Acquires tokens from the authority for the application (not for an end user).
|
|
2681
2334
|
*/
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
2335
|
async acquireTokenByClientCredential(request) {
|
|
2685
|
-
this.logger.info("acquireTokenByClientCredential called", request.correlationId);
|
|
2686
|
-
|
|
2336
|
+
this.logger.info("acquireTokenByClientCredential called", request.correlationId);
|
|
2337
|
+
// If there is a client assertion present in the request, it overrides the one present in the client configuration
|
|
2687
2338
|
let clientAssertion;
|
|
2688
|
-
|
|
2689
2339
|
if (request.clientAssertion) {
|
|
2690
2340
|
clientAssertion = {
|
|
2691
2341
|
assertion: request.clientAssertion,
|
|
2692
2342
|
assertionType: Constants.JWT_BEARER_ASSERTION_TYPE
|
|
2693
2343
|
};
|
|
2694
2344
|
}
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2345
|
+
const baseRequest = await this.initializeBaseRequest(request);
|
|
2346
|
+
// valid base request should not contain oidc scopes in this grant type
|
|
2347
|
+
const validBaseRequest = {
|
|
2348
|
+
...baseRequest,
|
|
2699
2349
|
scopes: baseRequest.scopes.filter(scope => !msalCommon.OIDC_DEFAULT_SCOPES.includes(scope))
|
|
2700
2350
|
};
|
|
2701
|
-
const validRequest = {
|
|
2351
|
+
const validRequest = {
|
|
2352
|
+
...request,
|
|
2702
2353
|
...validBaseRequest,
|
|
2703
2354
|
clientAssertion
|
|
2704
2355
|
};
|
|
@@ -2707,7 +2358,6 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2707
2358
|
environmentRegion: process.env[REGION_ENVIRONMENT_VARIABLE]
|
|
2708
2359
|
};
|
|
2709
2360
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByClientCredential, validRequest.correlationId, validRequest.skipCache);
|
|
2710
|
-
|
|
2711
2361
|
try {
|
|
2712
2362
|
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration, request.azureCloudOptions);
|
|
2713
2363
|
const clientCredentialClient = new msalCommon.ClientCredentialClient(clientCredentialConfig, this.appTokenProvider);
|
|
@@ -2717,7 +2367,6 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2717
2367
|
if (e instanceof msalCommon.AuthError) {
|
|
2718
2368
|
e.setCorrelationId(validRequest.correlationId);
|
|
2719
2369
|
}
|
|
2720
|
-
|
|
2721
2370
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2722
2371
|
throw e;
|
|
2723
2372
|
}
|
|
@@ -2733,14 +2382,12 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2733
2382
|
* See how to gain consent upfront for your middle-tier app from this article.
|
|
2734
2383
|
* https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow#gaining-consent-for-the-middle-tier-application
|
|
2735
2384
|
*/
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
2385
|
async acquireTokenOnBehalfOf(request) {
|
|
2739
2386
|
this.logger.info("acquireTokenOnBehalfOf called", request.correlationId);
|
|
2740
|
-
const validRequest = {
|
|
2387
|
+
const validRequest = {
|
|
2388
|
+
...request,
|
|
2741
2389
|
...(await this.initializeBaseRequest(request))
|
|
2742
2390
|
};
|
|
2743
|
-
|
|
2744
2391
|
try {
|
|
2745
2392
|
const onBehalfOfConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
|
|
2746
2393
|
const oboClient = new msalCommon.OnBehalfOfClient(onBehalfOfConfig);
|
|
@@ -2750,11 +2397,9 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2750
2397
|
if (e instanceof msalCommon.AuthError) {
|
|
2751
2398
|
e.setCorrelationId(validRequest.correlationId);
|
|
2752
2399
|
}
|
|
2753
|
-
|
|
2754
2400
|
throw e;
|
|
2755
2401
|
}
|
|
2756
2402
|
}
|
|
2757
|
-
|
|
2758
2403
|
setClientCredential(configuration) {
|
|
2759
2404
|
const clientSecretNotEmpty = !msalCommon.StringUtils.isEmpty(configuration.auth.clientSecret);
|
|
2760
2405
|
const clientAssertionNotEmpty = !msalCommon.StringUtils.isEmpty(configuration.auth.clientAssertion);
|
|
@@ -2767,35 +2412,28 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2767
2412
|
* If app developer configures this callback, they don't need a credential
|
|
2768
2413
|
* i.e. AzureSDK can get token from Managed Identity without a cert / secret
|
|
2769
2414
|
*/
|
|
2770
|
-
|
|
2771
2415
|
if (this.appTokenProvider) {
|
|
2772
2416
|
return;
|
|
2773
|
-
}
|
|
2774
|
-
|
|
2775
|
-
|
|
2417
|
+
}
|
|
2418
|
+
// Check that at most one credential is set on the application
|
|
2776
2419
|
if (clientSecretNotEmpty && clientAssertionNotEmpty || clientAssertionNotEmpty && certificateNotEmpty || clientSecretNotEmpty && certificateNotEmpty) {
|
|
2777
2420
|
throw msalCommon.ClientAuthError.createInvalidCredentialError();
|
|
2778
2421
|
}
|
|
2779
|
-
|
|
2780
2422
|
if (configuration.auth.clientSecret) {
|
|
2781
2423
|
this.clientSecret = configuration.auth.clientSecret;
|
|
2782
2424
|
return;
|
|
2783
2425
|
}
|
|
2784
|
-
|
|
2785
2426
|
if (configuration.auth.clientAssertion) {
|
|
2786
2427
|
this.clientAssertion = ClientAssertion.fromAssertion(configuration.auth.clientAssertion);
|
|
2787
2428
|
return;
|
|
2788
2429
|
}
|
|
2789
|
-
|
|
2790
2430
|
if (!certificateNotEmpty) {
|
|
2791
2431
|
throw msalCommon.ClientAuthError.createInvalidCredentialError();
|
|
2792
2432
|
} else {
|
|
2793
2433
|
var _configuration$auth$c;
|
|
2794
|
-
|
|
2795
2434
|
this.clientAssertion = ClientAssertion.fromCertificate(certificate.thumbprint, certificate.privateKey, (_configuration$auth$c = configuration.auth.clientCertificate) == null ? void 0 : _configuration$auth$c.x5c);
|
|
2796
2435
|
}
|
|
2797
2436
|
}
|
|
2798
|
-
|
|
2799
2437
|
}
|
|
2800
2438
|
|
|
2801
2439
|
/*
|
|
@@ -2807,18 +2445,15 @@ class DistributedCachePlugin {
|
|
|
2807
2445
|
this.client = client;
|
|
2808
2446
|
this.partitionManager = partitionManager;
|
|
2809
2447
|
}
|
|
2810
|
-
|
|
2811
2448
|
async beforeCacheAccess(cacheContext) {
|
|
2812
2449
|
const partitionKey = await this.partitionManager.getKey();
|
|
2813
2450
|
const cacheData = await this.client.get(partitionKey);
|
|
2814
2451
|
cacheContext.tokenCache.deserialize(cacheData);
|
|
2815
2452
|
}
|
|
2816
|
-
|
|
2817
2453
|
async afterCacheAccess(cacheContext) {
|
|
2818
2454
|
if (cacheContext.cacheHasChanged) {
|
|
2819
2455
|
const kvStore = cacheContext.tokenCache.getKVStore();
|
|
2820
2456
|
const accountEntities = Object.values(kvStore).filter(value => msalCommon.AccountEntity.isAccountEntity(value));
|
|
2821
|
-
|
|
2822
2457
|
if (accountEntities.length > 0) {
|
|
2823
2458
|
const accountEntity = accountEntities[0];
|
|
2824
2459
|
const partitionKey = await this.partitionManager.extractKey(accountEntity);
|
|
@@ -2826,7 +2461,6 @@ class DistributedCachePlugin {
|
|
|
2826
2461
|
}
|
|
2827
2462
|
}
|
|
2828
2463
|
}
|
|
2829
|
-
|
|
2830
2464
|
}
|
|
2831
2465
|
|
|
2832
2466
|
Object.defineProperty(exports, 'AuthError', {
|