@azure/msal-node 1.14.4 → 1.14.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache/serializer/Deserializer.d.ts.map +1 -1
- package/dist/cache/serializer/Serializer.d.ts.map +1 -1
- package/dist/cache/serializer/SerializerTypes.d.ts +1 -0
- package/dist/cache/serializer/SerializerTypes.d.ts.map +1 -1
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/msal-node.cjs.development.js +138 -504
- package/dist/msal-node.cjs.development.js.map +1 -1
- package/dist/msal-node.cjs.production.min.js +1 -1
- package/dist/msal-node.cjs.production.min.js.map +1 -1
- package/dist/msal-node.esm.js +138 -504
- package/dist/msal-node.esm.js.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/package.json +3 -3
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];
|
|
@@ -835,25 +741,22 @@ class Deserializer {
|
|
|
835
741
|
keyId: serializedAT.key_id,
|
|
836
742
|
tokenType: serializedAT.token_type,
|
|
837
743
|
requestedClaims: serializedAT.requestedClaims,
|
|
838
|
-
requestedClaimsHash: serializedAT.requestedClaimsHash
|
|
744
|
+
requestedClaimsHash: serializedAT.requestedClaimsHash,
|
|
745
|
+
userAssertionHash: serializedAT.userAssertionHash
|
|
839
746
|
};
|
|
840
747
|
const accessToken = new AccessTokenEntity();
|
|
841
748
|
CacheManager.toObject(accessToken, mappedAT);
|
|
842
749
|
atObjects[key] = accessToken;
|
|
843
750
|
});
|
|
844
751
|
}
|
|
845
|
-
|
|
846
752
|
return atObjects;
|
|
847
753
|
}
|
|
848
754
|
/**
|
|
849
755
|
* Deserializes refresh tokens to RefreshTokenEntity objects
|
|
850
756
|
* @param refreshTokens
|
|
851
757
|
*/
|
|
852
|
-
|
|
853
|
-
|
|
854
758
|
static deserializeRefreshTokens(refreshTokens) {
|
|
855
759
|
const rtObjects = {};
|
|
856
|
-
|
|
857
760
|
if (refreshTokens) {
|
|
858
761
|
Object.keys(refreshTokens).map(function (key) {
|
|
859
762
|
const serializedRT = refreshTokens[key];
|
|
@@ -872,18 +775,14 @@ class Deserializer {
|
|
|
872
775
|
rtObjects[key] = refreshToken;
|
|
873
776
|
});
|
|
874
777
|
}
|
|
875
|
-
|
|
876
778
|
return rtObjects;
|
|
877
779
|
}
|
|
878
780
|
/**
|
|
879
781
|
* Deserializes appMetadata to AppMetaData objects
|
|
880
782
|
* @param appMetadata
|
|
881
783
|
*/
|
|
882
|
-
|
|
883
|
-
|
|
884
784
|
static deserializeAppMetadata(appMetadata) {
|
|
885
785
|
const appMetadataObjects = {};
|
|
886
|
-
|
|
887
786
|
if (appMetadata) {
|
|
888
787
|
Object.keys(appMetadata).map(function (key) {
|
|
889
788
|
const serializedAmdt = appMetadata[key];
|
|
@@ -897,15 +796,12 @@ class Deserializer {
|
|
|
897
796
|
appMetadataObjects[key] = amd;
|
|
898
797
|
});
|
|
899
798
|
}
|
|
900
|
-
|
|
901
799
|
return appMetadataObjects;
|
|
902
800
|
}
|
|
903
801
|
/**
|
|
904
802
|
* Deserialize an inMemory Cache
|
|
905
803
|
* @param jsonCache
|
|
906
804
|
*/
|
|
907
|
-
|
|
908
|
-
|
|
909
805
|
static deserializeAllCache(jsonCache) {
|
|
910
806
|
return {
|
|
911
807
|
accounts: jsonCache.Account ? this.deserializeAccounts(jsonCache.Account) : {},
|
|
@@ -915,7 +811,6 @@ class Deserializer {
|
|
|
915
811
|
appMetadata: jsonCache.AppMetadata ? this.deserializeAppMetadata(jsonCache.AppMetadata) : {}
|
|
916
812
|
};
|
|
917
813
|
}
|
|
918
|
-
|
|
919
814
|
}
|
|
920
815
|
|
|
921
816
|
/*
|
|
@@ -934,8 +829,6 @@ class Serializer {
|
|
|
934
829
|
* Serialize Accounts
|
|
935
830
|
* @param accCache
|
|
936
831
|
*/
|
|
937
|
-
|
|
938
|
-
|
|
939
832
|
static serializeAccounts(accCache) {
|
|
940
833
|
const accounts = {};
|
|
941
834
|
Object.keys(accCache).map(function (key) {
|
|
@@ -959,8 +852,6 @@ class Serializer {
|
|
|
959
852
|
* Serialize IdTokens
|
|
960
853
|
* @param idTCache
|
|
961
854
|
*/
|
|
962
|
-
|
|
963
|
-
|
|
964
855
|
static serializeIdTokens(idTCache) {
|
|
965
856
|
const idTokens = {};
|
|
966
857
|
Object.keys(idTCache).map(function (key) {
|
|
@@ -980,8 +871,6 @@ class Serializer {
|
|
|
980
871
|
* Serializes AccessTokens
|
|
981
872
|
* @param atCache
|
|
982
873
|
*/
|
|
983
|
-
|
|
984
|
-
|
|
985
874
|
static serializeAccessTokens(atCache) {
|
|
986
875
|
const accessTokens = {};
|
|
987
876
|
Object.keys(atCache).map(function (key) {
|
|
@@ -1001,7 +890,8 @@ class Serializer {
|
|
|
1001
890
|
key_id: atEntity.keyId,
|
|
1002
891
|
token_type: atEntity.tokenType,
|
|
1003
892
|
requestedClaims: atEntity.requestedClaims,
|
|
1004
|
-
requestedClaimsHash: atEntity.requestedClaimsHash
|
|
893
|
+
requestedClaimsHash: atEntity.requestedClaimsHash,
|
|
894
|
+
userAssertionHash: atEntity.userAssertionHash
|
|
1005
895
|
};
|
|
1006
896
|
});
|
|
1007
897
|
return accessTokens;
|
|
@@ -1010,8 +900,6 @@ class Serializer {
|
|
|
1010
900
|
* Serialize refreshTokens
|
|
1011
901
|
* @param rtCache
|
|
1012
902
|
*/
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
903
|
static serializeRefreshTokens(rtCache) {
|
|
1016
904
|
const refreshTokens = {};
|
|
1017
905
|
Object.keys(rtCache).map(function (key) {
|
|
@@ -1033,8 +921,6 @@ class Serializer {
|
|
|
1033
921
|
* Serialize amdtCache
|
|
1034
922
|
* @param amdtCache
|
|
1035
923
|
*/
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
924
|
static serializeAppMetadata(amdtCache) {
|
|
1039
925
|
const appMetadata = {};
|
|
1040
926
|
Object.keys(amdtCache).map(function (key) {
|
|
@@ -1051,8 +937,6 @@ class Serializer {
|
|
|
1051
937
|
* Serialize the cache
|
|
1052
938
|
* @param jsonContent
|
|
1053
939
|
*/
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
940
|
static serializeAllCache(inMemCache) {
|
|
1057
941
|
return {
|
|
1058
942
|
Account: this.serializeAccounts(inMemCache.accounts),
|
|
@@ -1062,7 +946,6 @@ class Serializer {
|
|
|
1062
946
|
AppMetadata: this.serializeAppMetadata(inMemCache.appMetadata)
|
|
1063
947
|
};
|
|
1064
948
|
}
|
|
1065
|
-
|
|
1066
949
|
}
|
|
1067
950
|
|
|
1068
951
|
/*
|
|
@@ -1073,7 +956,6 @@ class Serializer {
|
|
|
1073
956
|
* This class implements Storage for node, reading cache from user specified storage location or an extension library
|
|
1074
957
|
* @public
|
|
1075
958
|
*/
|
|
1076
|
-
|
|
1077
959
|
class NodeStorage extends CacheManager {
|
|
1078
960
|
constructor(logger, clientId, cryptoImpl) {
|
|
1079
961
|
super(clientId, cryptoImpl);
|
|
@@ -1085,16 +967,12 @@ class NodeStorage extends CacheManager {
|
|
|
1085
967
|
* Queue up callbacks
|
|
1086
968
|
* @param func - a callback function for cache change indication
|
|
1087
969
|
*/
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
970
|
registerChangeEmitter(func) {
|
|
1091
971
|
this.changeEmitters.push(func);
|
|
1092
972
|
}
|
|
1093
973
|
/**
|
|
1094
974
|
* Invoke the callback when cache changes
|
|
1095
975
|
*/
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
976
|
emitChange() {
|
|
1099
977
|
this.changeEmitters.forEach(func => func.call(null));
|
|
1100
978
|
}
|
|
@@ -1102,8 +980,6 @@ class NodeStorage extends CacheManager {
|
|
|
1102
980
|
* Converts cacheKVStore to InMemoryCache
|
|
1103
981
|
* @param cache - key value store
|
|
1104
982
|
*/
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
983
|
cacheToInMemoryCache(cache) {
|
|
1108
984
|
const inMemoryCache = {
|
|
1109
985
|
accounts: {},
|
|
@@ -1112,7 +988,6 @@ class NodeStorage extends CacheManager {
|
|
|
1112
988
|
refreshTokens: {},
|
|
1113
989
|
appMetadata: {}
|
|
1114
990
|
};
|
|
1115
|
-
|
|
1116
991
|
for (const key in cache) {
|
|
1117
992
|
if (cache[key] instanceof AccountEntity) {
|
|
1118
993
|
inMemoryCache.accounts[key] = cache[key];
|
|
@@ -1128,36 +1003,32 @@ class NodeStorage extends CacheManager {
|
|
|
1128
1003
|
continue;
|
|
1129
1004
|
}
|
|
1130
1005
|
}
|
|
1131
|
-
|
|
1132
1006
|
return inMemoryCache;
|
|
1133
1007
|
}
|
|
1134
1008
|
/**
|
|
1135
1009
|
* converts inMemoryCache to CacheKVStore
|
|
1136
1010
|
* @param inMemoryCache - kvstore map for inmemory
|
|
1137
1011
|
*/
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
1012
|
inMemoryCacheToCache(inMemoryCache) {
|
|
1141
1013
|
// convert in memory cache to a flat Key-Value map
|
|
1142
1014
|
let cache = this.getCache();
|
|
1143
|
-
cache = {
|
|
1015
|
+
cache = {
|
|
1016
|
+
...cache,
|
|
1144
1017
|
...inMemoryCache.accounts,
|
|
1145
1018
|
...inMemoryCache.idTokens,
|
|
1146
1019
|
...inMemoryCache.accessTokens,
|
|
1147
1020
|
...inMemoryCache.refreshTokens,
|
|
1148
1021
|
...inMemoryCache.appMetadata
|
|
1149
|
-
};
|
|
1150
|
-
|
|
1022
|
+
};
|
|
1023
|
+
// convert in memory cache to a flat Key-Value map
|
|
1151
1024
|
return cache;
|
|
1152
1025
|
}
|
|
1153
1026
|
/**
|
|
1154
1027
|
* gets the current in memory cache for the client
|
|
1155
1028
|
*/
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
1029
|
getInMemoryCache() {
|
|
1159
|
-
this.logger.trace("Getting in-memory cache");
|
|
1160
|
-
|
|
1030
|
+
this.logger.trace("Getting in-memory cache");
|
|
1031
|
+
// convert the cache key value store to inMemoryCache
|
|
1161
1032
|
const inMemoryCache = this.cacheToInMemoryCache(this.getCache());
|
|
1162
1033
|
return inMemoryCache;
|
|
1163
1034
|
}
|
|
@@ -1165,11 +1036,9 @@ class NodeStorage extends CacheManager {
|
|
|
1165
1036
|
* sets the current in memory cache for the client
|
|
1166
1037
|
* @param inMemoryCache - key value map in memory
|
|
1167
1038
|
*/
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
1039
|
setInMemoryCache(inMemoryCache) {
|
|
1171
|
-
this.logger.trace("Setting in-memory cache");
|
|
1172
|
-
|
|
1040
|
+
this.logger.trace("Setting in-memory cache");
|
|
1041
|
+
// convert and append the inMemoryCache to cacheKVStore
|
|
1173
1042
|
const cache = this.inMemoryCacheToCache(inMemoryCache);
|
|
1174
1043
|
this.setCache(cache);
|
|
1175
1044
|
this.emitChange();
|
|
@@ -1177,8 +1046,6 @@ class NodeStorage extends CacheManager {
|
|
|
1177
1046
|
/**
|
|
1178
1047
|
* get the current cache key-value store
|
|
1179
1048
|
*/
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
1049
|
getCache() {
|
|
1183
1050
|
this.logger.trace("Getting cache key-value store");
|
|
1184
1051
|
return this.cache;
|
|
@@ -1187,23 +1054,19 @@ class NodeStorage extends CacheManager {
|
|
|
1187
1054
|
* sets the current cache (key value store)
|
|
1188
1055
|
* @param cacheMap - key value map
|
|
1189
1056
|
*/
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
1057
|
setCache(cache) {
|
|
1193
1058
|
this.logger.trace("Setting cache key value store");
|
|
1194
|
-
this.cache = cache;
|
|
1195
|
-
|
|
1059
|
+
this.cache = cache;
|
|
1060
|
+
// mark change in cache
|
|
1196
1061
|
this.emitChange();
|
|
1197
1062
|
}
|
|
1198
1063
|
/**
|
|
1199
1064
|
* Gets cache item with given key.
|
|
1200
1065
|
* @param key - lookup key for the cache entry
|
|
1201
1066
|
*/
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
1067
|
getItem(key) {
|
|
1205
|
-
this.logger.tracePii(`Item key: ${key}`);
|
|
1206
|
-
|
|
1068
|
+
this.logger.tracePii(`Item key: ${key}`);
|
|
1069
|
+
// read cache
|
|
1207
1070
|
const cache = this.getCache();
|
|
1208
1071
|
return cache[key];
|
|
1209
1072
|
}
|
|
@@ -1212,37 +1075,29 @@ class NodeStorage extends CacheManager {
|
|
|
1212
1075
|
* @param key - lookup key for the cache entry
|
|
1213
1076
|
* @param value - value of the cache entry
|
|
1214
1077
|
*/
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
1078
|
setItem(key, value) {
|
|
1218
|
-
this.logger.tracePii(`Item key: ${key}`);
|
|
1219
|
-
|
|
1079
|
+
this.logger.tracePii(`Item key: ${key}`);
|
|
1080
|
+
// read cache
|
|
1220
1081
|
const cache = this.getCache();
|
|
1221
|
-
cache[key] = value;
|
|
1222
|
-
|
|
1082
|
+
cache[key] = value;
|
|
1083
|
+
// write to cache
|
|
1223
1084
|
this.setCache(cache);
|
|
1224
1085
|
}
|
|
1225
1086
|
/**
|
|
1226
1087
|
* fetch the account entity
|
|
1227
1088
|
* @param accountKey - lookup key to fetch cache type AccountEntity
|
|
1228
1089
|
*/
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
1090
|
getAccount(accountKey) {
|
|
1232
1091
|
const account = this.getItem(accountKey);
|
|
1233
|
-
|
|
1234
1092
|
if (AccountEntity.isAccountEntity(account)) {
|
|
1235
1093
|
return account;
|
|
1236
1094
|
}
|
|
1237
|
-
|
|
1238
1095
|
return null;
|
|
1239
1096
|
}
|
|
1240
1097
|
/**
|
|
1241
1098
|
* set account entity
|
|
1242
1099
|
* @param account - cache value to be set of type AccountEntity
|
|
1243
1100
|
*/
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
1101
|
setAccount(account) {
|
|
1247
1102
|
const accountKey = account.generateAccountKey();
|
|
1248
1103
|
this.setItem(accountKey, account);
|
|
@@ -1251,23 +1106,17 @@ class NodeStorage extends CacheManager {
|
|
|
1251
1106
|
* fetch the idToken credential
|
|
1252
1107
|
* @param idTokenKey - lookup key to fetch cache type IdTokenEntity
|
|
1253
1108
|
*/
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
1109
|
getIdTokenCredential(idTokenKey) {
|
|
1257
1110
|
const idToken = this.getItem(idTokenKey);
|
|
1258
|
-
|
|
1259
1111
|
if (IdTokenEntity.isIdTokenEntity(idToken)) {
|
|
1260
1112
|
return idToken;
|
|
1261
1113
|
}
|
|
1262
|
-
|
|
1263
1114
|
return null;
|
|
1264
1115
|
}
|
|
1265
1116
|
/**
|
|
1266
1117
|
* set idToken credential
|
|
1267
1118
|
* @param idToken - cache value to be set of type IdTokenEntity
|
|
1268
1119
|
*/
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
1120
|
setIdTokenCredential(idToken) {
|
|
1272
1121
|
const idTokenKey = idToken.generateCredentialKey();
|
|
1273
1122
|
this.setItem(idTokenKey, idToken);
|
|
@@ -1276,23 +1125,17 @@ class NodeStorage extends CacheManager {
|
|
|
1276
1125
|
* fetch the accessToken credential
|
|
1277
1126
|
* @param accessTokenKey - lookup key to fetch cache type AccessTokenEntity
|
|
1278
1127
|
*/
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
1128
|
getAccessTokenCredential(accessTokenKey) {
|
|
1282
1129
|
const accessToken = this.getItem(accessTokenKey);
|
|
1283
|
-
|
|
1284
1130
|
if (AccessTokenEntity.isAccessTokenEntity(accessToken)) {
|
|
1285
1131
|
return accessToken;
|
|
1286
1132
|
}
|
|
1287
|
-
|
|
1288
1133
|
return null;
|
|
1289
1134
|
}
|
|
1290
1135
|
/**
|
|
1291
1136
|
* set accessToken credential
|
|
1292
1137
|
* @param accessToken - cache value to be set of type AccessTokenEntity
|
|
1293
1138
|
*/
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
1139
|
setAccessTokenCredential(accessToken) {
|
|
1297
1140
|
const accessTokenKey = accessToken.generateCredentialKey();
|
|
1298
1141
|
this.setItem(accessTokenKey, accessToken);
|
|
@@ -1301,23 +1144,17 @@ class NodeStorage extends CacheManager {
|
|
|
1301
1144
|
* fetch the refreshToken credential
|
|
1302
1145
|
* @param refreshTokenKey - lookup key to fetch cache type RefreshTokenEntity
|
|
1303
1146
|
*/
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
1147
|
getRefreshTokenCredential(refreshTokenKey) {
|
|
1307
1148
|
const refreshToken = this.getItem(refreshTokenKey);
|
|
1308
|
-
|
|
1309
1149
|
if (RefreshTokenEntity.isRefreshTokenEntity(refreshToken)) {
|
|
1310
1150
|
return refreshToken;
|
|
1311
1151
|
}
|
|
1312
|
-
|
|
1313
1152
|
return null;
|
|
1314
1153
|
}
|
|
1315
1154
|
/**
|
|
1316
1155
|
* set refreshToken credential
|
|
1317
1156
|
* @param refreshToken - cache value to be set of type RefreshTokenEntity
|
|
1318
1157
|
*/
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
1158
|
setRefreshTokenCredential(refreshToken) {
|
|
1322
1159
|
const refreshTokenKey = refreshToken.generateCredentialKey();
|
|
1323
1160
|
this.setItem(refreshTokenKey, refreshToken);
|
|
@@ -1326,23 +1163,17 @@ class NodeStorage extends CacheManager {
|
|
|
1326
1163
|
* fetch appMetadata entity from the platform cache
|
|
1327
1164
|
* @param appMetadataKey - lookup key to fetch cache type AppMetadataEntity
|
|
1328
1165
|
*/
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
1166
|
getAppMetadata(appMetadataKey) {
|
|
1332
1167
|
const appMetadata = this.getItem(appMetadataKey);
|
|
1333
|
-
|
|
1334
1168
|
if (AppMetadataEntity.isAppMetadataEntity(appMetadataKey, appMetadata)) {
|
|
1335
1169
|
return appMetadata;
|
|
1336
1170
|
}
|
|
1337
|
-
|
|
1338
1171
|
return null;
|
|
1339
1172
|
}
|
|
1340
1173
|
/**
|
|
1341
1174
|
* set appMetadata entity to the platform cache
|
|
1342
1175
|
* @param appMetadata - cache value to be set of type AppMetadataEntity
|
|
1343
1176
|
*/
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
1177
|
setAppMetadata(appMetadata) {
|
|
1347
1178
|
const appMetadataKey = appMetadata.generateAppMetadataKey();
|
|
1348
1179
|
this.setItem(appMetadataKey, appMetadata);
|
|
@@ -1351,15 +1182,11 @@ class NodeStorage extends CacheManager {
|
|
|
1351
1182
|
* fetch server telemetry entity from the platform cache
|
|
1352
1183
|
* @param serverTelemetrykey - lookup key to fetch cache type ServerTelemetryEntity
|
|
1353
1184
|
*/
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
1185
|
getServerTelemetry(serverTelemetrykey) {
|
|
1357
1186
|
const serverTelemetryEntity = this.getItem(serverTelemetrykey);
|
|
1358
|
-
|
|
1359
1187
|
if (serverTelemetryEntity && ServerTelemetryEntity.isServerTelemetryEntity(serverTelemetrykey, serverTelemetryEntity)) {
|
|
1360
1188
|
return serverTelemetryEntity;
|
|
1361
1189
|
}
|
|
1362
|
-
|
|
1363
1190
|
return null;
|
|
1364
1191
|
}
|
|
1365
1192
|
/**
|
|
@@ -1367,8 +1194,6 @@ class NodeStorage extends CacheManager {
|
|
|
1367
1194
|
* @param serverTelemetryKey - lookup key to fetch cache type ServerTelemetryEntity
|
|
1368
1195
|
* @param serverTelemetry - cache value to be set of type ServerTelemetryEntity
|
|
1369
1196
|
*/
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
1197
|
setServerTelemetry(serverTelemetryKey, serverTelemetry) {
|
|
1373
1198
|
this.setItem(serverTelemetryKey, serverTelemetry);
|
|
1374
1199
|
}
|
|
@@ -1376,22 +1201,16 @@ class NodeStorage extends CacheManager {
|
|
|
1376
1201
|
* fetch authority metadata entity from the platform cache
|
|
1377
1202
|
* @param key - lookup key to fetch cache type AuthorityMetadataEntity
|
|
1378
1203
|
*/
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
1204
|
getAuthorityMetadata(key) {
|
|
1382
1205
|
const authorityMetadataEntity = this.getItem(key);
|
|
1383
|
-
|
|
1384
1206
|
if (authorityMetadataEntity && AuthorityMetadataEntity.isAuthorityMetadataEntity(key, authorityMetadataEntity)) {
|
|
1385
1207
|
return authorityMetadataEntity;
|
|
1386
1208
|
}
|
|
1387
|
-
|
|
1388
1209
|
return null;
|
|
1389
1210
|
}
|
|
1390
1211
|
/**
|
|
1391
1212
|
* Get all authority metadata keys
|
|
1392
1213
|
*/
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
1214
|
getAuthorityMetadataKeys() {
|
|
1396
1215
|
return this.getKeys().filter(key => {
|
|
1397
1216
|
return this.isAuthorityMetadata(key);
|
|
@@ -1402,8 +1221,6 @@ class NodeStorage extends CacheManager {
|
|
|
1402
1221
|
* @param key - lookup key to fetch cache type AuthorityMetadataEntity
|
|
1403
1222
|
* @param metadata - cache value to be set of type AuthorityMetadataEntity
|
|
1404
1223
|
*/
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
1224
|
setAuthorityMetadata(key, metadata) {
|
|
1408
1225
|
this.setItem(key, metadata);
|
|
1409
1226
|
}
|
|
@@ -1411,15 +1228,11 @@ class NodeStorage extends CacheManager {
|
|
|
1411
1228
|
* fetch throttling entity from the platform cache
|
|
1412
1229
|
* @param throttlingCacheKey - lookup key to fetch cache type ThrottlingEntity
|
|
1413
1230
|
*/
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
1231
|
getThrottlingCache(throttlingCacheKey) {
|
|
1417
1232
|
const throttlingCache = this.getItem(throttlingCacheKey);
|
|
1418
|
-
|
|
1419
1233
|
if (throttlingCache && ThrottlingEntity.isThrottlingEntity(throttlingCacheKey, throttlingCache)) {
|
|
1420
1234
|
return throttlingCache;
|
|
1421
1235
|
}
|
|
1422
|
-
|
|
1423
1236
|
return null;
|
|
1424
1237
|
}
|
|
1425
1238
|
/**
|
|
@@ -1427,8 +1240,6 @@ class NodeStorage extends CacheManager {
|
|
|
1427
1240
|
* @param throttlingCacheKey - lookup key to fetch cache type ThrottlingEntity
|
|
1428
1241
|
* @param throttlingCache - cache value to be set of type ThrottlingEntity
|
|
1429
1242
|
*/
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
1243
|
setThrottlingCache(throttlingCacheKey, throttlingCache) {
|
|
1433
1244
|
this.setItem(throttlingCacheKey, throttlingCache);
|
|
1434
1245
|
}
|
|
@@ -1437,57 +1248,46 @@ class NodeStorage extends CacheManager {
|
|
|
1437
1248
|
* @param key - lookup key to remove a cache entity
|
|
1438
1249
|
* @param inMemory - key value map of the cache
|
|
1439
1250
|
*/
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
1251
|
removeItem(key) {
|
|
1443
|
-
this.logger.tracePii(`Item key: ${key}`);
|
|
1444
|
-
|
|
1252
|
+
this.logger.tracePii(`Item key: ${key}`);
|
|
1253
|
+
// read inMemoryCache
|
|
1445
1254
|
let result = false;
|
|
1446
1255
|
const cache = this.getCache();
|
|
1447
|
-
|
|
1448
1256
|
if (!!cache[key]) {
|
|
1449
1257
|
delete cache[key];
|
|
1450
1258
|
result = true;
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
|
|
1259
|
+
}
|
|
1260
|
+
// write to the cache after removal
|
|
1454
1261
|
if (result) {
|
|
1455
1262
|
this.setCache(cache);
|
|
1456
1263
|
this.emitChange();
|
|
1457
1264
|
}
|
|
1458
|
-
|
|
1459
1265
|
return result;
|
|
1460
1266
|
}
|
|
1461
1267
|
/**
|
|
1462
1268
|
* Checks whether key is in cache.
|
|
1463
1269
|
* @param key - look up key for a cache entity
|
|
1464
1270
|
*/
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
1271
|
containsKey(key) {
|
|
1468
1272
|
return this.getKeys().includes(key);
|
|
1469
1273
|
}
|
|
1470
1274
|
/**
|
|
1471
1275
|
* Gets all keys in window.
|
|
1472
1276
|
*/
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
1277
|
getKeys() {
|
|
1476
|
-
this.logger.trace("Retrieving all cache keys");
|
|
1477
|
-
|
|
1278
|
+
this.logger.trace("Retrieving all cache keys");
|
|
1279
|
+
// read cache
|
|
1478
1280
|
const cache = this.getCache();
|
|
1479
1281
|
return [...Object.keys(cache)];
|
|
1480
1282
|
}
|
|
1481
1283
|
/**
|
|
1482
1284
|
* Clears all cache entries created by MSAL (except tokens).
|
|
1483
1285
|
*/
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
1286
|
async clear() {
|
|
1487
|
-
this.logger.trace("Clearing cache entries created by MSAL");
|
|
1488
|
-
|
|
1489
|
-
const cacheKeys = this.getKeys();
|
|
1490
|
-
|
|
1287
|
+
this.logger.trace("Clearing cache entries created by MSAL");
|
|
1288
|
+
// read inMemoryCache
|
|
1289
|
+
const cacheKeys = this.getKeys();
|
|
1290
|
+
// delete each element
|
|
1491
1291
|
cacheKeys.forEach(key => {
|
|
1492
1292
|
this.removeItem(key);
|
|
1493
1293
|
});
|
|
@@ -1497,8 +1297,6 @@ class NodeStorage extends CacheManager {
|
|
|
1497
1297
|
* Initialize in memory cache from an exisiting cache vault
|
|
1498
1298
|
* @param cache - blob formatted cache (JSON)
|
|
1499
1299
|
*/
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
1300
|
static generateInMemoryCache(cache) {
|
|
1503
1301
|
return Deserializer.deserializeAllCache(Deserializer.deserializeJSONBlob(cache));
|
|
1504
1302
|
}
|
|
@@ -1506,22 +1304,16 @@ class NodeStorage extends CacheManager {
|
|
|
1506
1304
|
* retrieves the final JSON
|
|
1507
1305
|
* @param inMemoryCache - itemised cache read from the JSON
|
|
1508
1306
|
*/
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
1307
|
static generateJsonCache(inMemoryCache) {
|
|
1512
1308
|
return Serializer.serializeAllCache(inMemoryCache);
|
|
1513
1309
|
}
|
|
1514
1310
|
/**
|
|
1515
1311
|
* Updates a credential's cache key if the current cache key is outdated
|
|
1516
1312
|
*/
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
1313
|
updateCredentialCacheKey(currentCacheKey, credential) {
|
|
1520
1314
|
const updatedCacheKey = credential.generateCredentialKey();
|
|
1521
|
-
|
|
1522
1315
|
if (currentCacheKey !== updatedCacheKey) {
|
|
1523
1316
|
const cacheItem = this.getItem(currentCacheKey);
|
|
1524
|
-
|
|
1525
1317
|
if (cacheItem) {
|
|
1526
1318
|
this.removeItem(currentCacheKey);
|
|
1527
1319
|
this.setItem(updatedCacheKey, cacheItem);
|
|
@@ -1531,10 +1323,8 @@ class NodeStorage extends CacheManager {
|
|
|
1531
1323
|
this.logger.error(`Attempted to update an outdated ${credential.credentialType} cache key but no item matching the outdated key was found in storage`);
|
|
1532
1324
|
}
|
|
1533
1325
|
}
|
|
1534
|
-
|
|
1535
1326
|
return currentCacheKey;
|
|
1536
1327
|
}
|
|
1537
|
-
|
|
1538
1328
|
}
|
|
1539
1329
|
|
|
1540
1330
|
/*
|
|
@@ -1552,43 +1342,35 @@ const defaultSerializedCache = {
|
|
|
1552
1342
|
* In-memory token cache manager
|
|
1553
1343
|
* @public
|
|
1554
1344
|
*/
|
|
1555
|
-
|
|
1556
1345
|
class TokenCache {
|
|
1557
1346
|
constructor(storage, logger, cachePlugin) {
|
|
1558
1347
|
this.cacheHasChanged = false;
|
|
1559
1348
|
this.storage = storage;
|
|
1560
1349
|
this.storage.registerChangeEmitter(this.handleChangeEvent.bind(this));
|
|
1561
|
-
|
|
1562
1350
|
if (cachePlugin) {
|
|
1563
1351
|
this.persistence = cachePlugin;
|
|
1564
1352
|
}
|
|
1565
|
-
|
|
1566
1353
|
this.logger = logger;
|
|
1567
1354
|
}
|
|
1568
1355
|
/**
|
|
1569
1356
|
* Set to true if cache state has changed since last time serialize or writeToPersistence was called
|
|
1570
1357
|
*/
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
1358
|
hasChanged() {
|
|
1574
1359
|
return this.cacheHasChanged;
|
|
1575
1360
|
}
|
|
1576
1361
|
/**
|
|
1577
1362
|
* Serializes in memory cache to JSON
|
|
1578
1363
|
*/
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
1364
|
serialize() {
|
|
1582
1365
|
this.logger.trace("Serializing in-memory cache");
|
|
1583
|
-
let finalState = Serializer.serializeAllCache(this.storage.getInMemoryCache());
|
|
1584
|
-
|
|
1366
|
+
let finalState = Serializer.serializeAllCache(this.storage.getInMemoryCache());
|
|
1367
|
+
// if cacheSnapshot not null or empty, merge
|
|
1585
1368
|
if (!StringUtils.isEmpty(this.cacheSnapshot)) {
|
|
1586
1369
|
this.logger.trace("Reading cache snapshot from disk");
|
|
1587
1370
|
finalState = this.mergeState(JSON.parse(this.cacheSnapshot), finalState);
|
|
1588
1371
|
} else {
|
|
1589
1372
|
this.logger.trace("No cache snapshot to merge");
|
|
1590
1373
|
}
|
|
1591
|
-
|
|
1592
1374
|
this.cacheHasChanged = false;
|
|
1593
1375
|
return JSON.stringify(finalState);
|
|
1594
1376
|
}
|
|
@@ -1596,12 +1378,9 @@ class TokenCache {
|
|
|
1596
1378
|
* Deserializes JSON to in-memory cache. JSON should be in MSAL cache schema format
|
|
1597
1379
|
* @param cache - blob formatted cache
|
|
1598
1380
|
*/
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
1381
|
deserialize(cache) {
|
|
1602
1382
|
this.logger.trace("Deserializing JSON to in-memory cache");
|
|
1603
1383
|
this.cacheSnapshot = cache;
|
|
1604
|
-
|
|
1605
1384
|
if (!StringUtils.isEmpty(this.cacheSnapshot)) {
|
|
1606
1385
|
this.logger.trace("Reading cache snapshot from disk");
|
|
1607
1386
|
const deserializedCache = Deserializer.deserializeAllCache(this.overlayDefaults(JSON.parse(this.cacheSnapshot)));
|
|
@@ -1613,26 +1392,20 @@ class TokenCache {
|
|
|
1613
1392
|
/**
|
|
1614
1393
|
* Fetches the cache key-value map
|
|
1615
1394
|
*/
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
1395
|
getKVStore() {
|
|
1619
1396
|
return this.storage.getCache();
|
|
1620
1397
|
}
|
|
1621
1398
|
/**
|
|
1622
1399
|
* API that retrieves all accounts currently in cache to the user
|
|
1623
1400
|
*/
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
1401
|
async getAllAccounts() {
|
|
1627
1402
|
this.logger.trace("getAllAccounts called");
|
|
1628
1403
|
let cacheContext;
|
|
1629
|
-
|
|
1630
1404
|
try {
|
|
1631
1405
|
if (this.persistence) {
|
|
1632
1406
|
cacheContext = new TokenCacheContext(this, false);
|
|
1633
1407
|
await this.persistence.beforeCacheAccess(cacheContext);
|
|
1634
1408
|
}
|
|
1635
|
-
|
|
1636
1409
|
return this.storage.getAllAccounts();
|
|
1637
1410
|
} finally {
|
|
1638
1411
|
if (this.persistence && cacheContext) {
|
|
@@ -1646,11 +1419,8 @@ class TokenCache {
|
|
|
1646
1419
|
* or null when no matching account is found
|
|
1647
1420
|
* @param homeAccountId - unique identifier for an account (uid.utid)
|
|
1648
1421
|
*/
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
1422
|
async getAccountByHomeId(homeAccountId) {
|
|
1652
1423
|
const allAccounts = await this.getAllAccounts();
|
|
1653
|
-
|
|
1654
1424
|
if (!StringUtils.isEmpty(homeAccountId) && allAccounts && allAccounts.length) {
|
|
1655
1425
|
return allAccounts.filter(accountObj => accountObj.homeAccountId === homeAccountId)[0] || null;
|
|
1656
1426
|
} else {
|
|
@@ -1663,11 +1433,8 @@ class TokenCache {
|
|
|
1663
1433
|
* or null when no matching account is found
|
|
1664
1434
|
* @param localAccountId - unique identifier of an account (sub/obj when homeAccountId cannot be populated)
|
|
1665
1435
|
*/
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
1436
|
async getAccountByLocalId(localAccountId) {
|
|
1669
1437
|
const allAccounts = await this.getAllAccounts();
|
|
1670
|
-
|
|
1671
1438
|
if (!StringUtils.isEmpty(localAccountId) && allAccounts && allAccounts.length) {
|
|
1672
1439
|
return allAccounts.filter(accountObj => accountObj.localAccountId === localAccountId)[0] || null;
|
|
1673
1440
|
} else {
|
|
@@ -1678,18 +1445,14 @@ class TokenCache {
|
|
|
1678
1445
|
* API to remove a specific account and the relevant data from cache
|
|
1679
1446
|
* @param account - AccountInfo passed by the user
|
|
1680
1447
|
*/
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
1448
|
async removeAccount(account) {
|
|
1684
1449
|
this.logger.trace("removeAccount called");
|
|
1685
1450
|
let cacheContext;
|
|
1686
|
-
|
|
1687
1451
|
try {
|
|
1688
1452
|
if (this.persistence) {
|
|
1689
1453
|
cacheContext = new TokenCacheContext(this, true);
|
|
1690
1454
|
await this.persistence.beforeCacheAccess(cacheContext);
|
|
1691
1455
|
}
|
|
1692
|
-
|
|
1693
1456
|
await this.storage.removeAccount(AccountEntity.generateAccountCacheKey(account));
|
|
1694
1457
|
} finally {
|
|
1695
1458
|
if (this.persistence && cacheContext) {
|
|
@@ -1700,8 +1463,6 @@ class TokenCache {
|
|
|
1700
1463
|
/**
|
|
1701
1464
|
* Called when the cache has changed state.
|
|
1702
1465
|
*/
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
1466
|
handleChangeEvent() {
|
|
1706
1467
|
this.cacheHasChanged = true;
|
|
1707
1468
|
}
|
|
@@ -1710,8 +1471,6 @@ class TokenCache {
|
|
|
1710
1471
|
* @param oldState - cache before changes
|
|
1711
1472
|
* @param currentState - current cache state in the library
|
|
1712
1473
|
*/
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
1474
|
mergeState(oldState, currentState) {
|
|
1716
1475
|
this.logger.trace("Merging in-memory cache with cache snapshot");
|
|
1717
1476
|
const stateAfterRemoval = this.mergeRemovals(oldState, currentState);
|
|
@@ -1722,12 +1481,10 @@ class TokenCache {
|
|
|
1722
1481
|
* @param oldState - cache before changes
|
|
1723
1482
|
* @param newState - updated cache
|
|
1724
1483
|
*/
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
1484
|
mergeUpdates(oldState, newState) {
|
|
1728
1485
|
Object.keys(newState).forEach(newKey => {
|
|
1729
|
-
const newValue = newState[newKey];
|
|
1730
|
-
|
|
1486
|
+
const newValue = newState[newKey];
|
|
1487
|
+
// if oldState does not contain value but newValue does, add it
|
|
1731
1488
|
if (!oldState.hasOwnProperty(newKey)) {
|
|
1732
1489
|
if (newValue !== null) {
|
|
1733
1490
|
oldState[newKey] = newValue;
|
|
@@ -1738,7 +1495,6 @@ class TokenCache {
|
|
|
1738
1495
|
const newValueIsObject = typeof newValue === "object";
|
|
1739
1496
|
const newValueIsNotArray = !Array.isArray(newValue);
|
|
1740
1497
|
const oldStateNotUndefinedOrNull = typeof oldState[newKey] !== "undefined" && oldState[newKey] !== null;
|
|
1741
|
-
|
|
1742
1498
|
if (newValueNotNull && newValueIsObject && newValueIsNotArray && oldStateNotUndefinedOrNull) {
|
|
1743
1499
|
this.mergeUpdates(oldState[newKey], newValue);
|
|
1744
1500
|
} else {
|
|
@@ -1754,8 +1510,6 @@ class TokenCache {
|
|
|
1754
1510
|
* @param oldState - cache before changes
|
|
1755
1511
|
* @param newState - updated cache
|
|
1756
1512
|
*/
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
1513
|
mergeRemovals(oldState, newState) {
|
|
1760
1514
|
this.logger.trace("Remove updated entries in cache");
|
|
1761
1515
|
const accounts = oldState.Account ? this.mergeRemovalsDict(oldState.Account, newState.Account) : oldState.Account;
|
|
@@ -1763,7 +1517,8 @@ class TokenCache {
|
|
|
1763
1517
|
const refreshTokens = oldState.RefreshToken ? this.mergeRemovalsDict(oldState.RefreshToken, newState.RefreshToken) : oldState.RefreshToken;
|
|
1764
1518
|
const idTokens = oldState.IdToken ? this.mergeRemovalsDict(oldState.IdToken, newState.IdToken) : oldState.IdToken;
|
|
1765
1519
|
const appMetadata = oldState.AppMetadata ? this.mergeRemovalsDict(oldState.AppMetadata, newState.AppMetadata) : oldState.AppMetadata;
|
|
1766
|
-
return {
|
|
1520
|
+
return {
|
|
1521
|
+
...oldState,
|
|
1767
1522
|
Account: accounts,
|
|
1768
1523
|
AccessToken: accessTokens,
|
|
1769
1524
|
RefreshToken: refreshTokens,
|
|
@@ -1776,10 +1531,9 @@ class TokenCache {
|
|
|
1776
1531
|
* @param oldState - cache before changes
|
|
1777
1532
|
* @param newState - updated cache
|
|
1778
1533
|
*/
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
1534
|
mergeRemovalsDict(oldState, newState) {
|
|
1782
|
-
const finalState = {
|
|
1535
|
+
const finalState = {
|
|
1536
|
+
...oldState
|
|
1783
1537
|
};
|
|
1784
1538
|
Object.keys(oldState).forEach(oldKey => {
|
|
1785
1539
|
if (!newState || !newState.hasOwnProperty(oldKey)) {
|
|
@@ -1792,34 +1546,36 @@ class TokenCache {
|
|
|
1792
1546
|
* Helper to overlay as a part of cache merge
|
|
1793
1547
|
* @param passedInCache - cache read from the blob
|
|
1794
1548
|
*/
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
1549
|
overlayDefaults(passedInCache) {
|
|
1798
1550
|
this.logger.trace("Overlaying input cache with the default cache");
|
|
1799
1551
|
return {
|
|
1800
|
-
Account: {
|
|
1552
|
+
Account: {
|
|
1553
|
+
...defaultSerializedCache.Account,
|
|
1801
1554
|
...passedInCache.Account
|
|
1802
1555
|
},
|
|
1803
|
-
IdToken: {
|
|
1556
|
+
IdToken: {
|
|
1557
|
+
...defaultSerializedCache.IdToken,
|
|
1804
1558
|
...passedInCache.IdToken
|
|
1805
1559
|
},
|
|
1806
|
-
AccessToken: {
|
|
1560
|
+
AccessToken: {
|
|
1561
|
+
...defaultSerializedCache.AccessToken,
|
|
1807
1562
|
...passedInCache.AccessToken
|
|
1808
1563
|
},
|
|
1809
|
-
RefreshToken: {
|
|
1564
|
+
RefreshToken: {
|
|
1565
|
+
...defaultSerializedCache.RefreshToken,
|
|
1810
1566
|
...passedInCache.RefreshToken
|
|
1811
1567
|
},
|
|
1812
|
-
AppMetadata: {
|
|
1568
|
+
AppMetadata: {
|
|
1569
|
+
...defaultSerializedCache.AppMetadata,
|
|
1813
1570
|
...passedInCache.AppMetadata
|
|
1814
1571
|
}
|
|
1815
1572
|
};
|
|
1816
1573
|
}
|
|
1817
|
-
|
|
1818
1574
|
}
|
|
1819
1575
|
|
|
1820
1576
|
/* eslint-disable header/header */
|
|
1821
1577
|
const name = "@azure/msal-node";
|
|
1822
|
-
const version = "1.14.
|
|
1578
|
+
const version = "1.14.6";
|
|
1823
1579
|
|
|
1824
1580
|
/*
|
|
1825
1581
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1828,7 +1584,6 @@ const version = "1.14.4";
|
|
|
1828
1584
|
/**
|
|
1829
1585
|
* NodeAuthErrorMessage class containing string constants used by error codes and messages.
|
|
1830
1586
|
*/
|
|
1831
|
-
|
|
1832
1587
|
const NodeAuthErrorMessage = {
|
|
1833
1588
|
invalidLoopbackAddressType: {
|
|
1834
1589
|
code: "invalid_loopback_server_address_type",
|
|
@@ -1867,60 +1622,45 @@ class NodeAuthError extends AuthError {
|
|
|
1867
1622
|
/**
|
|
1868
1623
|
* Creates an error thrown if loopback server address is of type string.
|
|
1869
1624
|
*/
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
1625
|
static createInvalidLoopbackAddressTypeError() {
|
|
1873
1626
|
return new NodeAuthError(NodeAuthErrorMessage.invalidLoopbackAddressType.code, `${NodeAuthErrorMessage.invalidLoopbackAddressType.desc}`);
|
|
1874
1627
|
}
|
|
1875
1628
|
/**
|
|
1876
1629
|
* Creates an error thrown if the loopback server is unable to get a url.
|
|
1877
1630
|
*/
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
1631
|
static createUnableToLoadRedirectUrlError() {
|
|
1881
1632
|
return new NodeAuthError(NodeAuthErrorMessage.unableToLoadRedirectUri.code, `${NodeAuthErrorMessage.unableToLoadRedirectUri.desc}`);
|
|
1882
1633
|
}
|
|
1883
1634
|
/**
|
|
1884
1635
|
* Creates an error thrown if the server response does not contain an auth code.
|
|
1885
1636
|
*/
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
1637
|
static createNoAuthCodeInResponseError() {
|
|
1889
1638
|
return new NodeAuthError(NodeAuthErrorMessage.noAuthCodeInResponse.code, `${NodeAuthErrorMessage.noAuthCodeInResponse.desc}`);
|
|
1890
1639
|
}
|
|
1891
1640
|
/**
|
|
1892
1641
|
* Creates an error thrown if the loopback server has not been spun up yet.
|
|
1893
1642
|
*/
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
1643
|
static createNoLoopbackServerExistsError() {
|
|
1897
1644
|
return new NodeAuthError(NodeAuthErrorMessage.noLoopbackServerExists.code, `${NodeAuthErrorMessage.noLoopbackServerExists.desc}`);
|
|
1898
1645
|
}
|
|
1899
1646
|
/**
|
|
1900
1647
|
* Creates an error thrown if a loopback server already exists when attempting to create another one.
|
|
1901
1648
|
*/
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
1649
|
static createLoopbackServerAlreadyExistsError() {
|
|
1905
1650
|
return new NodeAuthError(NodeAuthErrorMessage.loopbackServerAlreadyExists.code, `${NodeAuthErrorMessage.loopbackServerAlreadyExists.desc}`);
|
|
1906
1651
|
}
|
|
1907
1652
|
/**
|
|
1908
1653
|
* Creates an error thrown if the loopback server times out registering the auth code listener.
|
|
1909
1654
|
*/
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
1655
|
static createLoopbackServerTimeoutError() {
|
|
1913
1656
|
return new NodeAuthError(NodeAuthErrorMessage.loopbackServerTimeout.code, `${NodeAuthErrorMessage.loopbackServerTimeout.desc}`);
|
|
1914
1657
|
}
|
|
1915
1658
|
/**
|
|
1916
1659
|
* Creates an error thrown when the state is not present.
|
|
1917
1660
|
*/
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
1661
|
static createStateNotFoundError() {
|
|
1921
1662
|
return new NodeAuthError(NodeAuthErrorMessage.stateNotFoundError.code, NodeAuthErrorMessage.stateNotFoundError.desc);
|
|
1922
1663
|
}
|
|
1923
|
-
|
|
1924
1664
|
}
|
|
1925
1665
|
|
|
1926
1666
|
/*
|
|
@@ -1931,7 +1671,6 @@ class NodeAuthError extends AuthError {
|
|
|
1931
1671
|
* Base abstract class for all ClientApplications - public and confidential
|
|
1932
1672
|
* @public
|
|
1933
1673
|
*/
|
|
1934
|
-
|
|
1935
1674
|
class ClientApplication {
|
|
1936
1675
|
/**
|
|
1937
1676
|
* Constructor for the ClientApplication
|
|
@@ -1952,11 +1691,10 @@ class ClientApplication {
|
|
|
1952
1691
|
* sent in the request and should contain an authorization code, which can then be used to acquire tokens via
|
|
1953
1692
|
* `acquireTokenByCode(AuthorizationCodeRequest)`.
|
|
1954
1693
|
*/
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
1694
|
async getAuthCodeUrl(request) {
|
|
1958
1695
|
this.logger.info("getAuthCodeUrl called", request.correlationId);
|
|
1959
|
-
const validRequest = {
|
|
1696
|
+
const validRequest = {
|
|
1697
|
+
...request,
|
|
1960
1698
|
...(await this.initializeBaseRequest(request)),
|
|
1961
1699
|
responseMode: request.responseMode || ResponseMode.QUERY,
|
|
1962
1700
|
authenticationScheme: AuthenticationScheme.BEARER
|
|
@@ -1974,26 +1712,23 @@ class ClientApplication {
|
|
|
1974
1712
|
* Authorization Code flow. Ensure that values for redirectUri and scopes in AuthorizationCodeUrlRequest and
|
|
1975
1713
|
* AuthorizationCodeRequest are the same.
|
|
1976
1714
|
*/
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
1715
|
async acquireTokenByCode(request, authCodePayLoad) {
|
|
1980
1716
|
this.logger.info("acquireTokenByCode called");
|
|
1981
|
-
|
|
1982
1717
|
if (request.state && authCodePayLoad) {
|
|
1983
1718
|
this.logger.info("acquireTokenByCode - validating state");
|
|
1984
|
-
this.validateState(request.state, authCodePayLoad.state || "");
|
|
1985
|
-
|
|
1986
|
-
authCodePayLoad = {
|
|
1719
|
+
this.validateState(request.state, authCodePayLoad.state || "");
|
|
1720
|
+
// eslint-disable-next-line no-param-reassign
|
|
1721
|
+
authCodePayLoad = {
|
|
1722
|
+
...authCodePayLoad,
|
|
1987
1723
|
state: ""
|
|
1988
1724
|
};
|
|
1989
1725
|
}
|
|
1990
|
-
|
|
1991
|
-
|
|
1726
|
+
const validRequest = {
|
|
1727
|
+
...request,
|
|
1992
1728
|
...(await this.initializeBaseRequest(request)),
|
|
1993
1729
|
authenticationScheme: AuthenticationScheme.BEARER
|
|
1994
1730
|
};
|
|
1995
1731
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByCode, validRequest.correlationId);
|
|
1996
|
-
|
|
1997
1732
|
try {
|
|
1998
1733
|
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1999
1734
|
const authorizationCodeClient = new AuthorizationCodeClient(authClientConfig);
|
|
@@ -2003,7 +1738,6 @@ class ClientApplication {
|
|
|
2003
1738
|
if (e instanceof AuthError) {
|
|
2004
1739
|
e.setCorrelationId(validRequest.correlationId);
|
|
2005
1740
|
}
|
|
2006
|
-
|
|
2007
1741
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2008
1742
|
throw e;
|
|
2009
1743
|
}
|
|
@@ -2015,16 +1749,14 @@ class ClientApplication {
|
|
|
2015
1749
|
* recommended that you use `acquireTokenSilent()` for silent scenarios. When using `acquireTokenSilent()`, MSAL will
|
|
2016
1750
|
* handle the caching and refreshing of tokens automatically.
|
|
2017
1751
|
*/
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
1752
|
async acquireTokenByRefreshToken(request) {
|
|
2021
1753
|
this.logger.info("acquireTokenByRefreshToken called", request.correlationId);
|
|
2022
|
-
const validRequest = {
|
|
1754
|
+
const validRequest = {
|
|
1755
|
+
...request,
|
|
2023
1756
|
...(await this.initializeBaseRequest(request)),
|
|
2024
1757
|
authenticationScheme: AuthenticationScheme.BEARER
|
|
2025
1758
|
};
|
|
2026
1759
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByRefreshToken, validRequest.correlationId);
|
|
2027
|
-
|
|
2028
1760
|
try {
|
|
2029
1761
|
const refreshTokenClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
2030
1762
|
const refreshTokenClient = new RefreshTokenClient(refreshTokenClientConfig);
|
|
@@ -2034,7 +1766,6 @@ class ClientApplication {
|
|
|
2034
1766
|
if (e instanceof AuthError) {
|
|
2035
1767
|
e.setCorrelationId(validRequest.correlationId);
|
|
2036
1768
|
}
|
|
2037
|
-
|
|
2038
1769
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2039
1770
|
throw e;
|
|
2040
1771
|
}
|
|
@@ -2047,15 +1778,13 @@ class ClientApplication {
|
|
|
2047
1778
|
* In case the refresh_token is expired or not found, an error is thrown
|
|
2048
1779
|
* and the guidance is for the user to call any interactive token acquisition API (eg: `acquireTokenByCode()`).
|
|
2049
1780
|
*/
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
1781
|
async acquireTokenSilent(request) {
|
|
2053
|
-
const validRequest = {
|
|
1782
|
+
const validRequest = {
|
|
1783
|
+
...request,
|
|
2054
1784
|
...(await this.initializeBaseRequest(request)),
|
|
2055
1785
|
forceRefresh: request.forceRefresh || false
|
|
2056
1786
|
};
|
|
2057
1787
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent, validRequest.correlationId, validRequest.forceRefresh);
|
|
2058
|
-
|
|
2059
1788
|
try {
|
|
2060
1789
|
const silentFlowClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
2061
1790
|
const silentFlowClient = new SilentFlowClient(silentFlowClientConfig);
|
|
@@ -2065,7 +1794,6 @@ class ClientApplication {
|
|
|
2065
1794
|
if (e instanceof AuthError) {
|
|
2066
1795
|
e.setCorrelationId(validRequest.correlationId);
|
|
2067
1796
|
}
|
|
2068
|
-
|
|
2069
1797
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2070
1798
|
throw e;
|
|
2071
1799
|
}
|
|
@@ -2080,15 +1808,13 @@ class ClientApplication {
|
|
|
2080
1808
|
*
|
|
2081
1809
|
* @param request - UsenamePasswordRequest
|
|
2082
1810
|
*/
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
1811
|
async acquireTokenByUsernamePassword(request) {
|
|
2086
1812
|
this.logger.info("acquireTokenByUsernamePassword called", request.correlationId);
|
|
2087
|
-
const validRequest = {
|
|
1813
|
+
const validRequest = {
|
|
1814
|
+
...request,
|
|
2088
1815
|
...(await this.initializeBaseRequest(request))
|
|
2089
1816
|
};
|
|
2090
1817
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByUsernamePassword, validRequest.correlationId);
|
|
2091
|
-
|
|
2092
1818
|
try {
|
|
2093
1819
|
const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
2094
1820
|
const usernamePasswordClient = new UsernamePasswordClient(usernamePasswordClientConfig);
|
|
@@ -2098,7 +1824,6 @@ class ClientApplication {
|
|
|
2098
1824
|
if (e instanceof AuthError) {
|
|
2099
1825
|
e.setCorrelationId(validRequest.correlationId);
|
|
2100
1826
|
}
|
|
2101
|
-
|
|
2102
1827
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2103
1828
|
throw e;
|
|
2104
1829
|
}
|
|
@@ -2106,8 +1831,6 @@ class ClientApplication {
|
|
|
2106
1831
|
/**
|
|
2107
1832
|
* Gets the token cache for the application.
|
|
2108
1833
|
*/
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
1834
|
getTokenCache() {
|
|
2112
1835
|
this.logger.info("getTokenCache called");
|
|
2113
1836
|
return this.tokenCache;
|
|
@@ -2121,13 +1844,10 @@ class ClientApplication {
|
|
|
2121
1844
|
* @param state
|
|
2122
1845
|
* @param cachedState
|
|
2123
1846
|
*/
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
1847
|
validateState(state, cachedState) {
|
|
2127
1848
|
if (!state) {
|
|
2128
1849
|
throw NodeAuthError.createStateNotFoundError();
|
|
2129
1850
|
}
|
|
2130
|
-
|
|
2131
1851
|
if (state !== cachedState) {
|
|
2132
1852
|
throw ClientAuthError.createStateMismatchError();
|
|
2133
1853
|
}
|
|
@@ -2135,8 +1855,6 @@ class ClientApplication {
|
|
|
2135
1855
|
/**
|
|
2136
1856
|
* Returns the logger instance
|
|
2137
1857
|
*/
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
1858
|
getLogger() {
|
|
2141
1859
|
return this.logger;
|
|
2142
1860
|
}
|
|
@@ -2144,8 +1862,6 @@ class ClientApplication {
|
|
|
2144
1862
|
* Replaces the default logger set in configurations with new Logger with new configurations
|
|
2145
1863
|
* @param logger - Logger instance
|
|
2146
1864
|
*/
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
1865
|
setLogger(logger) {
|
|
2150
1866
|
this.logger = logger;
|
|
2151
1867
|
}
|
|
@@ -2154,13 +1870,11 @@ class ClientApplication {
|
|
|
2154
1870
|
* @param authority - user passed authority in configuration
|
|
2155
1871
|
* @param serverTelemetryManager - initializes servertelemetry if passed
|
|
2156
1872
|
*/
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
1873
|
async buildOauthClientConfiguration(authority, requestCorrelationId, serverTelemetryManager, azureRegionConfiguration, azureCloudOptions) {
|
|
2160
|
-
this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId);
|
|
2161
|
-
|
|
2162
|
-
const userAzureCloudOptions = azureCloudOptions ? azureCloudOptions : this.config.auth.azureCloudOptions;
|
|
2163
|
-
|
|
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()
|
|
2164
1878
|
this.logger.verbose(`building oauth client configuration with the authority: ${authority}`, requestCorrelationId);
|
|
2165
1879
|
const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId, userAzureCloudOptions);
|
|
2166
1880
|
serverTelemetryManager == null ? void 0 : serverTelemetryManager.updateRegionDiscoveryMetadata(discoveredAuthority.regionDiscoveryMetadata);
|
|
@@ -2199,7 +1913,6 @@ class ClientApplication {
|
|
|
2199
1913
|
};
|
|
2200
1914
|
return clientConfiguration;
|
|
2201
1915
|
}
|
|
2202
|
-
|
|
2203
1916
|
getClientAssertion(authority) {
|
|
2204
1917
|
return {
|
|
2205
1918
|
assertion: this.clientAssertion.getJwt(this.cryptoProvider, this.config.auth.clientId, authority.tokenEndpoint),
|
|
@@ -2210,22 +1923,19 @@ class ClientApplication {
|
|
|
2210
1923
|
* Generates a request with the default scopes & generates a correlationId.
|
|
2211
1924
|
* @param authRequest - BaseAuthRequest for initialization
|
|
2212
1925
|
*/
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
1926
|
async initializeBaseRequest(authRequest) {
|
|
2216
|
-
this.logger.verbose("initializeRequestScopes called", authRequest.correlationId);
|
|
2217
|
-
|
|
1927
|
+
this.logger.verbose("initializeRequestScopes called", authRequest.correlationId);
|
|
1928
|
+
// Default authenticationScheme to Bearer, log that POP isn't supported yet
|
|
2218
1929
|
if (authRequest.authenticationScheme && authRequest.authenticationScheme === AuthenticationScheme.POP) {
|
|
2219
1930
|
this.logger.verbose("Authentication Scheme 'pop' is not supported yet, setting Authentication Scheme to 'Bearer' for request", authRequest.correlationId);
|
|
2220
1931
|
}
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
1932
|
+
authRequest.authenticationScheme = AuthenticationScheme.BEARER;
|
|
1933
|
+
// Set requested claims hash if claims were requested
|
|
2224
1934
|
if (authRequest.claims && !StringUtils.isEmpty(authRequest.claims)) {
|
|
2225
1935
|
authRequest.requestedClaimsHash = await this.cryptoProvider.hashString(authRequest.claims);
|
|
2226
1936
|
}
|
|
2227
|
-
|
|
2228
|
-
|
|
1937
|
+
return {
|
|
1938
|
+
...authRequest,
|
|
2229
1939
|
scopes: [...(authRequest && authRequest.scopes || []), ...OIDC_DEFAULT_SCOPES],
|
|
2230
1940
|
correlationId: authRequest && authRequest.correlationId || this.cryptoProvider.createNewGuid(),
|
|
2231
1941
|
authority: authRequest.authority || this.config.auth.authority
|
|
@@ -2237,8 +1947,6 @@ class ClientApplication {
|
|
|
2237
1947
|
* @param correlationId - GUID
|
|
2238
1948
|
* @param forceRefresh - boolean to indicate network call
|
|
2239
1949
|
*/
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
1950
|
initializeServerTelemetryManager(apiId, correlationId, forceRefresh) {
|
|
2243
1951
|
const telemetryPayload = {
|
|
2244
1952
|
clientId: this.config.auth.clientId,
|
|
@@ -2253,11 +1961,9 @@ class ClientApplication {
|
|
|
2253
1961
|
* object. If no authority set in application object, then default to common authority.
|
|
2254
1962
|
* @param authorityString - authority from user configuration
|
|
2255
1963
|
*/
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
1964
|
async createAuthority(authorityString, azureRegionConfiguration, requestCorrelationId, azureCloudOptions) {
|
|
2259
|
-
this.logger.verbose("createAuthority called", requestCorrelationId);
|
|
2260
|
-
|
|
1965
|
+
this.logger.verbose("createAuthority called", requestCorrelationId);
|
|
1966
|
+
// build authority string based on auth params - azureCloudInstance is prioritized if provided
|
|
2261
1967
|
const authorityUrl = Authority.generateAuthority(authorityString, azureCloudOptions);
|
|
2262
1968
|
const authorityOptions = {
|
|
2263
1969
|
protocolMode: this.config.auth.protocolMode,
|
|
@@ -2272,12 +1978,9 @@ class ClientApplication {
|
|
|
2272
1978
|
/**
|
|
2273
1979
|
* Clear the cache
|
|
2274
1980
|
*/
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
1981
|
clearCache() {
|
|
2278
1982
|
this.storage.clear();
|
|
2279
1983
|
}
|
|
2280
|
-
|
|
2281
1984
|
}
|
|
2282
1985
|
|
|
2283
1986
|
/*
|
|
@@ -2295,11 +1998,9 @@ class LoopbackClient {
|
|
|
2295
1998
|
if (!!this.server) {
|
|
2296
1999
|
throw NodeAuthError.createLoopbackServerAlreadyExistsError();
|
|
2297
2000
|
}
|
|
2298
|
-
|
|
2299
2001
|
const authCodeListener = new Promise((resolve, reject) => {
|
|
2300
2002
|
this.server = createServer(async (req, res) => {
|
|
2301
2003
|
const url = req.url;
|
|
2302
|
-
|
|
2303
2004
|
if (!url) {
|
|
2304
2005
|
res.end(errorTemplate || "Error occurred loading redirectUrl");
|
|
2305
2006
|
reject(NodeAuthError.createUnableToLoadRedirectUrlError());
|
|
@@ -2308,35 +2009,29 @@ class LoopbackClient {
|
|
|
2308
2009
|
res.end(successTemplate || "Auth code was successfully acquired. You can close this window now.");
|
|
2309
2010
|
return;
|
|
2310
2011
|
}
|
|
2311
|
-
|
|
2312
2012
|
const authCodeResponse = UrlString.getDeserializedQueryString(url);
|
|
2313
|
-
|
|
2314
2013
|
if (authCodeResponse.code) {
|
|
2315
2014
|
const redirectUri = await this.getRedirectUri();
|
|
2316
2015
|
res.writeHead(HttpStatus.REDIRECT, {
|
|
2317
2016
|
location: redirectUri
|
|
2318
2017
|
}); // Prevent auth code from being saved in the browser history
|
|
2319
|
-
|
|
2320
2018
|
res.end();
|
|
2321
2019
|
}
|
|
2322
|
-
|
|
2323
2020
|
resolve(authCodeResponse);
|
|
2324
2021
|
});
|
|
2325
2022
|
this.server.listen(0); // Listen on any available port
|
|
2326
|
-
});
|
|
2327
|
-
|
|
2023
|
+
});
|
|
2024
|
+
// Wait for server to be listening
|
|
2328
2025
|
await new Promise(resolve => {
|
|
2329
2026
|
let ticks = 0;
|
|
2330
2027
|
const id = setInterval(() => {
|
|
2331
2028
|
if (LOOPBACK_SERVER_CONSTANTS.TIMEOUT_MS / LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS < ticks) {
|
|
2332
2029
|
throw NodeAuthError.createLoopbackServerTimeoutError();
|
|
2333
2030
|
}
|
|
2334
|
-
|
|
2335
2031
|
if (this.server.listening) {
|
|
2336
2032
|
clearInterval(id);
|
|
2337
2033
|
resolve();
|
|
2338
2034
|
}
|
|
2339
|
-
|
|
2340
2035
|
ticks++;
|
|
2341
2036
|
}, LOOPBACK_SERVER_CONSTANTS.INTERVAL_MS);
|
|
2342
2037
|
});
|
|
@@ -2346,34 +2041,26 @@ class LoopbackClient {
|
|
|
2346
2041
|
* Get the port that the loopback server is running on
|
|
2347
2042
|
* @returns
|
|
2348
2043
|
*/
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
2044
|
getRedirectUri() {
|
|
2352
2045
|
if (!this.server) {
|
|
2353
2046
|
throw NodeAuthError.createNoLoopbackServerExistsError();
|
|
2354
2047
|
}
|
|
2355
|
-
|
|
2356
2048
|
const address = this.server.address();
|
|
2357
|
-
|
|
2358
2049
|
if (!address || typeof address === "string" || !address.port) {
|
|
2359
2050
|
this.closeServer();
|
|
2360
2051
|
throw NodeAuthError.createInvalidLoopbackAddressTypeError();
|
|
2361
2052
|
}
|
|
2362
|
-
|
|
2363
2053
|
const port = address && address.port;
|
|
2364
2054
|
return `${Constants.HTTP_PROTOCOL}${Constants.LOCALHOST}:${port}`;
|
|
2365
2055
|
}
|
|
2366
2056
|
/**
|
|
2367
2057
|
* Close the loopback server
|
|
2368
2058
|
*/
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
2059
|
closeServer() {
|
|
2372
2060
|
if (!!this.server) {
|
|
2373
2061
|
this.server.close();
|
|
2374
2062
|
}
|
|
2375
2063
|
}
|
|
2376
|
-
|
|
2377
2064
|
}
|
|
2378
2065
|
|
|
2379
2066
|
/*
|
|
@@ -2385,7 +2072,6 @@ class LoopbackClient {
|
|
|
2385
2072
|
* are not trusted to safely store application secrets, and therefore can only request tokens in the name of an user.
|
|
2386
2073
|
* @public
|
|
2387
2074
|
*/
|
|
2388
|
-
|
|
2389
2075
|
class PublicClientApplication extends ClientApplication {
|
|
2390
2076
|
/**
|
|
2391
2077
|
* Important attributes in the Configuration object for auth are:
|
|
@@ -2416,13 +2102,10 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2416
2102
|
* Since the client cannot receive incoming requests, it polls the authorization server repeatedly
|
|
2417
2103
|
* until the end-user completes input of credentials.
|
|
2418
2104
|
*/
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
2105
|
async acquireTokenByDeviceCode(request) {
|
|
2422
2106
|
this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
|
|
2423
2107
|
const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
|
|
2424
2108
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
|
|
2425
|
-
|
|
2426
2109
|
try {
|
|
2427
2110
|
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
2428
2111
|
const deviceCodeClient = new DeviceCodeClient(deviceCodeConfig);
|
|
@@ -2432,7 +2115,6 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2432
2115
|
if (e instanceof AuthError) {
|
|
2433
2116
|
e.setCorrelationId(validRequest.correlationId);
|
|
2434
2117
|
}
|
|
2435
|
-
|
|
2436
2118
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2437
2119
|
throw e;
|
|
2438
2120
|
}
|
|
@@ -2440,8 +2122,6 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2440
2122
|
/**
|
|
2441
2123
|
* Acquires a token by requesting an Authorization code then exchanging it for a token.
|
|
2442
2124
|
*/
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
2125
|
async acquireTokenInteractive(request) {
|
|
2446
2126
|
const {
|
|
2447
2127
|
verifier,
|
|
@@ -2456,7 +2136,8 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2456
2136
|
const loopbackClient = new LoopbackClient();
|
|
2457
2137
|
const authCodeListener = loopbackClient.listenForAuthCode(successTemplate, errorTemplate);
|
|
2458
2138
|
const redirectUri = loopbackClient.getRedirectUri();
|
|
2459
|
-
const validRequest = {
|
|
2139
|
+
const validRequest = {
|
|
2140
|
+
...remainingProperties,
|
|
2460
2141
|
scopes: request.scopes || OIDC_DEFAULT_SCOPES,
|
|
2461
2142
|
redirectUri: redirectUri,
|
|
2462
2143
|
responseMode: ResponseMode.QUERY,
|
|
@@ -2468,13 +2149,11 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2468
2149
|
const authCodeResponse = await authCodeListener.finally(() => {
|
|
2469
2150
|
loopbackClient.closeServer();
|
|
2470
2151
|
});
|
|
2471
|
-
|
|
2472
2152
|
if (authCodeResponse.error) {
|
|
2473
2153
|
throw new ServerError(authCodeResponse.error, authCodeResponse.error_description, authCodeResponse.suberror);
|
|
2474
2154
|
} else if (!authCodeResponse.code) {
|
|
2475
2155
|
throw NodeAuthError.createNoAuthCodeInResponseError();
|
|
2476
2156
|
}
|
|
2477
|
-
|
|
2478
2157
|
const clientInfo = authCodeResponse.client_info;
|
|
2479
2158
|
const tokenRequest = {
|
|
2480
2159
|
code: authCodeResponse.code,
|
|
@@ -2484,7 +2163,6 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2484
2163
|
};
|
|
2485
2164
|
return this.acquireTokenByCode(tokenRequest);
|
|
2486
2165
|
}
|
|
2487
|
-
|
|
2488
2166
|
}
|
|
2489
2167
|
|
|
2490
2168
|
/*
|
|
@@ -2495,7 +2173,6 @@ class PublicClientApplication extends ClientApplication {
|
|
|
2495
2173
|
* Client assertion of type jwt-bearer used in confidential client flows
|
|
2496
2174
|
* @public
|
|
2497
2175
|
*/
|
|
2498
|
-
|
|
2499
2176
|
class ClientAssertion {
|
|
2500
2177
|
/**
|
|
2501
2178
|
* Initialize the ClientAssertion class from the clientAssertion passed by the user
|
|
@@ -2512,17 +2189,13 @@ class ClientAssertion {
|
|
|
2512
2189
|
* @param privateKey - secret key
|
|
2513
2190
|
* @param publicCertificate - electronic document provided to prove the ownership of the public key
|
|
2514
2191
|
*/
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
2192
|
static fromCertificate(thumbprint, privateKey, publicCertificate) {
|
|
2518
2193
|
const clientAssertion = new ClientAssertion();
|
|
2519
2194
|
clientAssertion.privateKey = privateKey;
|
|
2520
2195
|
clientAssertion.thumbprint = thumbprint;
|
|
2521
|
-
|
|
2522
2196
|
if (publicCertificate) {
|
|
2523
2197
|
clientAssertion.publicCertificate = this.parseCertificate(publicCertificate);
|
|
2524
2198
|
}
|
|
2525
|
-
|
|
2526
2199
|
return clientAssertion;
|
|
2527
2200
|
}
|
|
2528
2201
|
/**
|
|
@@ -2531,34 +2204,26 @@ class ClientAssertion {
|
|
|
2531
2204
|
* @param issuer - iss claim
|
|
2532
2205
|
* @param jwtAudience - aud claim
|
|
2533
2206
|
*/
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
2207
|
getJwt(cryptoProvider, issuer, jwtAudience) {
|
|
2537
2208
|
// if assertion was created from certificate, check if jwt is expired and create new one.
|
|
2538
2209
|
if (this.privateKey && this.thumbprint) {
|
|
2539
2210
|
if (this.jwt && !this.isExpired() && issuer === this.issuer && jwtAudience === this.jwtAudience) {
|
|
2540
2211
|
return this.jwt;
|
|
2541
2212
|
}
|
|
2542
|
-
|
|
2543
2213
|
return this.createJwt(cryptoProvider, issuer, jwtAudience);
|
|
2544
2214
|
}
|
|
2545
2215
|
/*
|
|
2546
2216
|
* if assertion was created by caller, then we just append it. It is up to the caller to
|
|
2547
2217
|
* ensure that it contains necessary claims and that it is not expired.
|
|
2548
2218
|
*/
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
2219
|
if (this.jwt) {
|
|
2552
2220
|
return this.jwt;
|
|
2553
2221
|
}
|
|
2554
|
-
|
|
2555
2222
|
throw ClientAuthError.createInvalidAssertionError();
|
|
2556
2223
|
}
|
|
2557
2224
|
/**
|
|
2558
2225
|
* JWT format and required claims specified: https://tools.ietf.org/html/rfc7523#section-3
|
|
2559
2226
|
*/
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
2227
|
createJwt(cryptoProvider, issuer, jwtAudience) {
|
|
2563
2228
|
this.issuer = issuer;
|
|
2564
2229
|
this.jwtAudience = jwtAudience;
|
|
@@ -2568,13 +2233,11 @@ class ClientAssertion {
|
|
|
2568
2233
|
alg: JwtConstants.RSA_256,
|
|
2569
2234
|
x5t: EncodingUtils.base64EncodeUrl(this.thumbprint, "hex")
|
|
2570
2235
|
};
|
|
2571
|
-
|
|
2572
2236
|
if (this.publicCertificate) {
|
|
2573
2237
|
Object.assign(header, {
|
|
2574
2238
|
x5c: this.publicCertificate
|
|
2575
2239
|
});
|
|
2576
2240
|
}
|
|
2577
|
-
|
|
2578
2241
|
const payload = {
|
|
2579
2242
|
[JwtConstants.AUDIENCE]: this.jwtAudience,
|
|
2580
2243
|
[JwtConstants.EXPIRATION_TIME]: this.expirationTime,
|
|
@@ -2591,8 +2254,6 @@ class ClientAssertion {
|
|
|
2591
2254
|
/**
|
|
2592
2255
|
* Utility API to check expiration
|
|
2593
2256
|
*/
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
2257
|
isExpired() {
|
|
2597
2258
|
return this.expirationTime < TimeUtils.nowSeconds();
|
|
2598
2259
|
}
|
|
@@ -2600,8 +2261,6 @@ class ClientAssertion {
|
|
|
2600
2261
|
* Extracts the raw certs from a given certificate string and returns them in an array.
|
|
2601
2262
|
* @param publicCertificate - electronic document provided to prove the ownership of the public key
|
|
2602
2263
|
*/
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
2264
|
static parseCertificate(publicCertificate) {
|
|
2606
2265
|
/**
|
|
2607
2266
|
* This is regex to identify the certs in a given certificate string.
|
|
@@ -2613,15 +2272,12 @@ class ClientAssertion {
|
|
|
2613
2272
|
const regexToFindCerts = /-----BEGIN CERTIFICATE-----\r*\n(.+?)\r*\n-----END CERTIFICATE-----/gs;
|
|
2614
2273
|
const certs = [];
|
|
2615
2274
|
let matches;
|
|
2616
|
-
|
|
2617
2275
|
while ((matches = regexToFindCerts.exec(publicCertificate)) !== null) {
|
|
2618
2276
|
// matches[1] represents the first parens capture group in the regex.
|
|
2619
2277
|
certs.push(matches[1].replace(/\r*\n/g, Constants$1.EMPTY_STRING));
|
|
2620
2278
|
}
|
|
2621
|
-
|
|
2622
2279
|
return certs;
|
|
2623
2280
|
}
|
|
2624
|
-
|
|
2625
2281
|
}
|
|
2626
2282
|
|
|
2627
2283
|
/*
|
|
@@ -2633,7 +2289,6 @@ class ClientAssertion {
|
|
|
2633
2289
|
* will configure application secrets, client certificates/assertions as applicable
|
|
2634
2290
|
* @public
|
|
2635
2291
|
*/
|
|
2636
|
-
|
|
2637
2292
|
class ConfidentialClientApplication extends ClientApplication {
|
|
2638
2293
|
/**
|
|
2639
2294
|
* Constructor for the ConfidentialClientApplication
|
|
@@ -2665,34 +2320,30 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2665
2320
|
*
|
|
2666
2321
|
* @param IAppTokenProvider - Extensibility interface, which allows the app developer to return a token from a custom source.
|
|
2667
2322
|
*/
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
2323
|
SetAppTokenProvider(provider) {
|
|
2671
2324
|
this.appTokenProvider = provider;
|
|
2672
2325
|
}
|
|
2673
2326
|
/**
|
|
2674
2327
|
* Acquires tokens from the authority for the application (not for an end user).
|
|
2675
2328
|
*/
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
2329
|
async acquireTokenByClientCredential(request) {
|
|
2679
|
-
this.logger.info("acquireTokenByClientCredential called", request.correlationId);
|
|
2680
|
-
|
|
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
|
|
2681
2332
|
let clientAssertion;
|
|
2682
|
-
|
|
2683
2333
|
if (request.clientAssertion) {
|
|
2684
2334
|
clientAssertion = {
|
|
2685
2335
|
assertion: request.clientAssertion,
|
|
2686
2336
|
assertionType: Constants.JWT_BEARER_ASSERTION_TYPE
|
|
2687
2337
|
};
|
|
2688
2338
|
}
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
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,
|
|
2693
2343
|
scopes: baseRequest.scopes.filter(scope => !OIDC_DEFAULT_SCOPES.includes(scope))
|
|
2694
2344
|
};
|
|
2695
|
-
const validRequest = {
|
|
2345
|
+
const validRequest = {
|
|
2346
|
+
...request,
|
|
2696
2347
|
...validBaseRequest,
|
|
2697
2348
|
clientAssertion
|
|
2698
2349
|
};
|
|
@@ -2701,7 +2352,6 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2701
2352
|
environmentRegion: process.env[REGION_ENVIRONMENT_VARIABLE]
|
|
2702
2353
|
};
|
|
2703
2354
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByClientCredential, validRequest.correlationId, validRequest.skipCache);
|
|
2704
|
-
|
|
2705
2355
|
try {
|
|
2706
2356
|
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration, request.azureCloudOptions);
|
|
2707
2357
|
const clientCredentialClient = new ClientCredentialClient(clientCredentialConfig, this.appTokenProvider);
|
|
@@ -2711,7 +2361,6 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2711
2361
|
if (e instanceof AuthError) {
|
|
2712
2362
|
e.setCorrelationId(validRequest.correlationId);
|
|
2713
2363
|
}
|
|
2714
|
-
|
|
2715
2364
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2716
2365
|
throw e;
|
|
2717
2366
|
}
|
|
@@ -2727,14 +2376,12 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2727
2376
|
* See how to gain consent upfront for your middle-tier app from this article.
|
|
2728
2377
|
* https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow#gaining-consent-for-the-middle-tier-application
|
|
2729
2378
|
*/
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
2379
|
async acquireTokenOnBehalfOf(request) {
|
|
2733
2380
|
this.logger.info("acquireTokenOnBehalfOf called", request.correlationId);
|
|
2734
|
-
const validRequest = {
|
|
2381
|
+
const validRequest = {
|
|
2382
|
+
...request,
|
|
2735
2383
|
...(await this.initializeBaseRequest(request))
|
|
2736
2384
|
};
|
|
2737
|
-
|
|
2738
2385
|
try {
|
|
2739
2386
|
const onBehalfOfConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
|
|
2740
2387
|
const oboClient = new OnBehalfOfClient(onBehalfOfConfig);
|
|
@@ -2744,11 +2391,9 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2744
2391
|
if (e instanceof AuthError) {
|
|
2745
2392
|
e.setCorrelationId(validRequest.correlationId);
|
|
2746
2393
|
}
|
|
2747
|
-
|
|
2748
2394
|
throw e;
|
|
2749
2395
|
}
|
|
2750
2396
|
}
|
|
2751
|
-
|
|
2752
2397
|
setClientCredential(configuration) {
|
|
2753
2398
|
const clientSecretNotEmpty = !StringUtils.isEmpty(configuration.auth.clientSecret);
|
|
2754
2399
|
const clientAssertionNotEmpty = !StringUtils.isEmpty(configuration.auth.clientAssertion);
|
|
@@ -2761,35 +2406,28 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2761
2406
|
* If app developer configures this callback, they don't need a credential
|
|
2762
2407
|
* i.e. AzureSDK can get token from Managed Identity without a cert / secret
|
|
2763
2408
|
*/
|
|
2764
|
-
|
|
2765
2409
|
if (this.appTokenProvider) {
|
|
2766
2410
|
return;
|
|
2767
|
-
}
|
|
2768
|
-
|
|
2769
|
-
|
|
2411
|
+
}
|
|
2412
|
+
// Check that at most one credential is set on the application
|
|
2770
2413
|
if (clientSecretNotEmpty && clientAssertionNotEmpty || clientAssertionNotEmpty && certificateNotEmpty || clientSecretNotEmpty && certificateNotEmpty) {
|
|
2771
2414
|
throw ClientAuthError.createInvalidCredentialError();
|
|
2772
2415
|
}
|
|
2773
|
-
|
|
2774
2416
|
if (configuration.auth.clientSecret) {
|
|
2775
2417
|
this.clientSecret = configuration.auth.clientSecret;
|
|
2776
2418
|
return;
|
|
2777
2419
|
}
|
|
2778
|
-
|
|
2779
2420
|
if (configuration.auth.clientAssertion) {
|
|
2780
2421
|
this.clientAssertion = ClientAssertion.fromAssertion(configuration.auth.clientAssertion);
|
|
2781
2422
|
return;
|
|
2782
2423
|
}
|
|
2783
|
-
|
|
2784
2424
|
if (!certificateNotEmpty) {
|
|
2785
2425
|
throw ClientAuthError.createInvalidCredentialError();
|
|
2786
2426
|
} else {
|
|
2787
2427
|
var _configuration$auth$c;
|
|
2788
|
-
|
|
2789
2428
|
this.clientAssertion = ClientAssertion.fromCertificate(certificate.thumbprint, certificate.privateKey, (_configuration$auth$c = configuration.auth.clientCertificate) == null ? void 0 : _configuration$auth$c.x5c);
|
|
2790
2429
|
}
|
|
2791
2430
|
}
|
|
2792
|
-
|
|
2793
2431
|
}
|
|
2794
2432
|
|
|
2795
2433
|
/*
|
|
@@ -2801,18 +2439,15 @@ class DistributedCachePlugin {
|
|
|
2801
2439
|
this.client = client;
|
|
2802
2440
|
this.partitionManager = partitionManager;
|
|
2803
2441
|
}
|
|
2804
|
-
|
|
2805
2442
|
async beforeCacheAccess(cacheContext) {
|
|
2806
2443
|
const partitionKey = await this.partitionManager.getKey();
|
|
2807
2444
|
const cacheData = await this.client.get(partitionKey);
|
|
2808
2445
|
cacheContext.tokenCache.deserialize(cacheData);
|
|
2809
2446
|
}
|
|
2810
|
-
|
|
2811
2447
|
async afterCacheAccess(cacheContext) {
|
|
2812
2448
|
if (cacheContext.cacheHasChanged) {
|
|
2813
2449
|
const kvStore = cacheContext.tokenCache.getKVStore();
|
|
2814
2450
|
const accountEntities = Object.values(kvStore).filter(value => AccountEntity.isAccountEntity(value));
|
|
2815
|
-
|
|
2816
2451
|
if (accountEntities.length > 0) {
|
|
2817
2452
|
const accountEntity = accountEntities[0];
|
|
2818
2453
|
const partitionKey = await this.partitionManager.extractKey(accountEntity);
|
|
@@ -2820,7 +2455,6 @@ class DistributedCachePlugin {
|
|
|
2820
2455
|
}
|
|
2821
2456
|
}
|
|
2822
2457
|
}
|
|
2823
|
-
|
|
2824
2458
|
}
|
|
2825
2459
|
|
|
2826
2460
|
export { ClientApplication, ClientAssertion, ConfidentialClientApplication, CryptoProvider, DistributedCachePlugin, NodeStorage, PublicClientApplication, TokenCache, buildAppConfiguration, version };
|