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