@azure/msal-node 1.4.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache/NodeStorage.d.ts +5 -1
- package/dist/cache/NodeStorage.d.ts.map +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.d.ts +11 -0
- package/dist/cache/distributed/DistributedCachePlugin.d.ts.map +1 -0
- package/dist/cache/distributed/ICacheClient.d.ts +18 -0
- package/dist/cache/distributed/ICacheClient.d.ts.map +1 -0
- package/dist/cache/distributed/IPartitionManager.d.ts +33 -0
- package/dist/cache/distributed/IPartitionManager.d.ts.map +1 -0
- 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 +2 -0
- package/dist/cache/serializer/SerializerTypes.d.ts.map +1 -1
- package/dist/client/ClientApplication.d.ts +8 -4
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
- package/dist/client/IConfidentialClientApplication.d.ts +2 -0
- package/dist/client/IConfidentialClientApplication.d.ts.map +1 -1
- package/dist/client/IPublicClientApplication.d.ts +2 -0
- package/dist/client/IPublicClientApplication.d.ts.map +1 -1
- package/dist/client/PublicClientApplication.d.ts.map +1 -1
- package/dist/config/Configuration.d.ts +3 -1
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/crypto/CryptoProvider.d.ts +5 -0
- package/dist/crypto/CryptoProvider.d.ts.map +1 -1
- package/dist/crypto/HashUtils.d.ts +9 -0
- package/dist/crypto/HashUtils.d.ts.map +1 -0
- package/dist/crypto/PkceGenerator.d.ts +2 -5
- package/dist/crypto/PkceGenerator.d.ts.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/msal-node.cjs.development.js +170 -43
- 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 +166 -46
- package/dist/msal-node.esm.js.map +1 -1
- package/dist/network/HttpClient.d.ts.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/request/AuthorizationCodeRequest.d.ts +1 -1
- package/dist/request/AuthorizationCodeRequest.d.ts.map +1 -1
- package/dist/request/AuthorizationUrlRequest.d.ts +1 -1
- package/dist/request/AuthorizationUrlRequest.d.ts.map +1 -1
- package/dist/request/ClientCredentialRequest.d.ts +1 -1
- package/dist/request/ClientCredentialRequest.d.ts.map +1 -1
- package/dist/request/DeviceCodeRequest.d.ts +1 -1
- package/dist/request/DeviceCodeRequest.d.ts.map +1 -1
- package/dist/request/OnBehalfOfRequest.d.ts +1 -1
- package/dist/request/OnBehalfOfRequest.d.ts.map +1 -1
- package/dist/request/RefreshTokenRequest.d.ts +1 -1
- package/dist/request/RefreshTokenRequest.d.ts.map +1 -1
- package/dist/request/SilentFlowRequest.d.ts +1 -1
- package/dist/request/SilentFlowRequest.d.ts.map +1 -1
- package/dist/request/UsernamePasswordRequest.d.ts +1 -1
- package/dist/request/UsernamePasswordRequest.d.ts.map +1 -1
- package/package.json +4 -17
- package/CHANGELOG.json +0 -957
- package/CHANGELOG.md +0 -314
|
@@ -6,6 +6,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
6
6
|
|
|
7
7
|
var msalCommon = require('@azure/msal-common');
|
|
8
8
|
var axios = _interopDefault(require('axios'));
|
|
9
|
+
var createHttpsProxyAgent = _interopDefault(require('https-proxy-agent'));
|
|
9
10
|
var uuid = require('uuid');
|
|
10
11
|
var crypto = _interopDefault(require('crypto'));
|
|
11
12
|
var jsonwebtoken = require('jsonwebtoken');
|
|
@@ -118,6 +119,13 @@ class HttpClient {
|
|
|
118
119
|
/* istanbul ignore next */
|
|
119
120
|
validateStatus: () => true
|
|
120
121
|
};
|
|
122
|
+
|
|
123
|
+
if (options && options.proxyUrl) {
|
|
124
|
+
// for axios, this has to be disabled
|
|
125
|
+
request.proxy = false;
|
|
126
|
+
request.httpsAgent = createHttpsProxyAgent(options.proxyUrl);
|
|
127
|
+
}
|
|
128
|
+
|
|
121
129
|
const response = await axios(request);
|
|
122
130
|
return {
|
|
123
131
|
headers: response.headers,
|
|
@@ -147,6 +155,13 @@ class HttpClient {
|
|
|
147
155
|
/* istanbul ignore next */
|
|
148
156
|
validateStatus: () => true
|
|
149
157
|
};
|
|
158
|
+
|
|
159
|
+
if (options && options.proxyUrl) {
|
|
160
|
+
// for axios, this has to be disabled
|
|
161
|
+
request.proxy = false;
|
|
162
|
+
request.httpsAgent = createHttpsProxyAgent(options.proxyUrl);
|
|
163
|
+
}
|
|
164
|
+
|
|
150
165
|
const response = await axios(request);
|
|
151
166
|
return {
|
|
152
167
|
headers: response.headers,
|
|
@@ -189,7 +204,11 @@ const DEFAULT_AUTH_OPTIONS = {
|
|
|
189
204
|
cloudDiscoveryMetadata: "",
|
|
190
205
|
authorityMetadata: "",
|
|
191
206
|
clientCapabilities: [],
|
|
192
|
-
protocolMode: msalCommon.ProtocolMode.AAD
|
|
207
|
+
protocolMode: msalCommon.ProtocolMode.AAD,
|
|
208
|
+
azureCloudOptions: {
|
|
209
|
+
azureCloudInstance: msalCommon.AzureCloudInstance.None,
|
|
210
|
+
tenant: ""
|
|
211
|
+
}
|
|
193
212
|
};
|
|
194
213
|
const DEFAULT_CACHE_OPTIONS = {};
|
|
195
214
|
const DEFAULT_LOGGER_OPTIONS = {
|
|
@@ -200,7 +219,8 @@ const DEFAULT_LOGGER_OPTIONS = {
|
|
|
200
219
|
};
|
|
201
220
|
const DEFAULT_SYSTEM_OPTIONS = {
|
|
202
221
|
loggerOptions: DEFAULT_LOGGER_OPTIONS,
|
|
203
|
-
networkClient: /*#__PURE__*/NetworkUtils.getNetworkClient()
|
|
222
|
+
networkClient: /*#__PURE__*/NetworkUtils.getNetworkClient(),
|
|
223
|
+
proxyUrl: ""
|
|
204
224
|
};
|
|
205
225
|
/**
|
|
206
226
|
* Sets the default options when not explicitly configured from app developer
|
|
@@ -308,6 +328,21 @@ class EncodingUtils {
|
|
|
308
328
|
|
|
309
329
|
}
|
|
310
330
|
|
|
331
|
+
/*
|
|
332
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
333
|
+
* Licensed under the MIT License.
|
|
334
|
+
*/
|
|
335
|
+
class HashUtils {
|
|
336
|
+
/**
|
|
337
|
+
* generate 'SHA256' hash
|
|
338
|
+
* @param buffer
|
|
339
|
+
*/
|
|
340
|
+
sha256(buffer) {
|
|
341
|
+
return crypto.createHash(Hash.SHA256).update(buffer).digest();
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
}
|
|
345
|
+
|
|
311
346
|
/*
|
|
312
347
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
313
348
|
* Licensed under the MIT License.
|
|
@@ -317,10 +352,15 @@ class EncodingUtils {
|
|
|
317
352
|
*/
|
|
318
353
|
|
|
319
354
|
class PkceGenerator {
|
|
355
|
+
constructor() {
|
|
356
|
+
this.hashUtils = new HashUtils();
|
|
357
|
+
}
|
|
320
358
|
/**
|
|
321
359
|
* generates the codeVerfier and the challenge from the codeVerfier
|
|
322
360
|
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
|
|
323
361
|
*/
|
|
362
|
+
|
|
363
|
+
|
|
324
364
|
async generatePkceCodes() {
|
|
325
365
|
const verifier = this.generateCodeVerifier();
|
|
326
366
|
const challenge = this.generateCodeChallengeFromVerifier(verifier);
|
|
@@ -363,16 +403,7 @@ class PkceGenerator {
|
|
|
363
403
|
|
|
364
404
|
|
|
365
405
|
generateCodeChallengeFromVerifier(codeVerifier) {
|
|
366
|
-
return EncodingUtils.base64EncodeUrl(this.sha256(codeVerifier).toString("base64"), "base64");
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* generate 'SHA256' hash
|
|
370
|
-
* @param buffer
|
|
371
|
-
*/
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
sha256(buffer) {
|
|
375
|
-
return crypto.createHash(Hash.SHA256).update(buffer).digest();
|
|
406
|
+
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString("base64"), "base64");
|
|
376
407
|
}
|
|
377
408
|
|
|
378
409
|
}
|
|
@@ -391,6 +422,7 @@ class CryptoProvider {
|
|
|
391
422
|
constructor() {
|
|
392
423
|
// Browser crypto needs to be validated first before any other classes can be set.
|
|
393
424
|
this.pkceGenerator = new PkceGenerator();
|
|
425
|
+
this.hashUtils = new HashUtils();
|
|
394
426
|
}
|
|
395
427
|
/**
|
|
396
428
|
* Creates a new random GUID - used to populate state and nonce.
|
|
@@ -460,6 +492,14 @@ class CryptoProvider {
|
|
|
460
492
|
signJwt() {
|
|
461
493
|
throw new Error("Method not implemented.");
|
|
462
494
|
}
|
|
495
|
+
/**
|
|
496
|
+
* Returns the SHA-256 hash of an input string
|
|
497
|
+
*/
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
async hashString(plainText) {
|
|
501
|
+
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(plainText).toString("base64"), "base64");
|
|
502
|
+
}
|
|
463
503
|
|
|
464
504
|
}
|
|
465
505
|
|
|
@@ -565,7 +605,9 @@ class Deserializer {
|
|
|
565
605
|
extendedExpiresOn: serializedAT.extended_expires_on,
|
|
566
606
|
refreshOn: serializedAT.refresh_on,
|
|
567
607
|
keyId: serializedAT.key_id,
|
|
568
|
-
tokenType: serializedAT.token_type
|
|
608
|
+
tokenType: serializedAT.token_type,
|
|
609
|
+
requestedClaims: serializedAT.requestedClaims,
|
|
610
|
+
requestedClaimsHash: serializedAT.requestedClaimsHash
|
|
569
611
|
};
|
|
570
612
|
const accessToken = new msalCommon.AccessTokenEntity();
|
|
571
613
|
msalCommon.CacheManager.toObject(accessToken, mappedAT);
|
|
@@ -729,7 +771,9 @@ class Serializer {
|
|
|
729
771
|
extended_expires_on: atEntity.extendedExpiresOn,
|
|
730
772
|
refresh_on: atEntity.refreshOn,
|
|
731
773
|
key_id: atEntity.keyId,
|
|
732
|
-
token_type: atEntity.tokenType
|
|
774
|
+
token_type: atEntity.tokenType,
|
|
775
|
+
requestedClaims: atEntity.requestedClaims,
|
|
776
|
+
requestedClaimsHash: atEntity.requestedClaimsHash
|
|
733
777
|
};
|
|
734
778
|
});
|
|
735
779
|
return accessTokens;
|
|
@@ -868,12 +912,14 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
868
912
|
inMemoryCacheToCache(inMemoryCache) {
|
|
869
913
|
// convert in memory cache to a flat Key-Value map
|
|
870
914
|
let cache = this.getCache();
|
|
871
|
-
cache = { ...
|
|
915
|
+
cache = { ...cache,
|
|
916
|
+
...inMemoryCache.accounts,
|
|
872
917
|
...inMemoryCache.idTokens,
|
|
873
918
|
...inMemoryCache.accessTokens,
|
|
874
919
|
...inMemoryCache.refreshTokens,
|
|
875
920
|
...inMemoryCache.appMetadata
|
|
876
|
-
};
|
|
921
|
+
}; // convert in memory cache to a flat Key-Value map
|
|
922
|
+
|
|
877
923
|
return cache;
|
|
878
924
|
}
|
|
879
925
|
/**
|
|
@@ -1237,6 +1283,29 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1237
1283
|
static generateJsonCache(inMemoryCache) {
|
|
1238
1284
|
return Serializer.serializeAllCache(inMemoryCache);
|
|
1239
1285
|
}
|
|
1286
|
+
/**
|
|
1287
|
+
* Updates a credential's cache key if the current cache key is outdated
|
|
1288
|
+
*/
|
|
1289
|
+
|
|
1290
|
+
|
|
1291
|
+
updateCredentialCacheKey(currentCacheKey, credential) {
|
|
1292
|
+
const updatedCacheKey = credential.generateCredentialKey();
|
|
1293
|
+
|
|
1294
|
+
if (currentCacheKey !== updatedCacheKey) {
|
|
1295
|
+
const cacheItem = this.getItem(currentCacheKey);
|
|
1296
|
+
|
|
1297
|
+
if (cacheItem) {
|
|
1298
|
+
this.removeItem(currentCacheKey);
|
|
1299
|
+
this.setItem(updatedCacheKey, cacheItem);
|
|
1300
|
+
this.logger.verbose(`Updated an outdated ${credential.credentialType} cache key`);
|
|
1301
|
+
return updatedCacheKey;
|
|
1302
|
+
} else {
|
|
1303
|
+
this.logger.error(`Attempted to update an outdated ${credential.credentialType} cache key but no item matching the outdated key was found in storage`);
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
return currentCacheKey;
|
|
1308
|
+
}
|
|
1240
1309
|
|
|
1241
1310
|
}
|
|
1242
1311
|
|
|
@@ -1522,7 +1591,7 @@ class TokenCache {
|
|
|
1522
1591
|
|
|
1523
1592
|
/* eslint-disable header/header */
|
|
1524
1593
|
const name = "@azure/msal-node";
|
|
1525
|
-
const version = "1.
|
|
1594
|
+
const version = "1.7.0";
|
|
1526
1595
|
|
|
1527
1596
|
/*
|
|
1528
1597
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1558,11 +1627,11 @@ class ClientApplication {
|
|
|
1558
1627
|
async getAuthCodeUrl(request) {
|
|
1559
1628
|
this.logger.info("getAuthCodeUrl called", request.correlationId);
|
|
1560
1629
|
const validRequest = { ...request,
|
|
1561
|
-
...this.initializeBaseRequest(request),
|
|
1630
|
+
...(await this.initializeBaseRequest(request)),
|
|
1562
1631
|
responseMode: request.responseMode || msalCommon.ResponseMode.QUERY,
|
|
1563
1632
|
authenticationScheme: msalCommon.AuthenticationScheme.BEARER
|
|
1564
1633
|
};
|
|
1565
|
-
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId);
|
|
1634
|
+
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
|
|
1566
1635
|
const authorizationCodeClient = new msalCommon.AuthorizationCodeClient(authClientConfig);
|
|
1567
1636
|
this.logger.verbose("Auth code client created", validRequest.correlationId);
|
|
1568
1637
|
return authorizationCodeClient.getAuthCodeUrl(validRequest);
|
|
@@ -1577,19 +1646,19 @@ class ClientApplication {
|
|
|
1577
1646
|
*/
|
|
1578
1647
|
|
|
1579
1648
|
|
|
1580
|
-
async acquireTokenByCode(request) {
|
|
1649
|
+
async acquireTokenByCode(request, authCodePayLoad) {
|
|
1581
1650
|
this.logger.info("acquireTokenByCode called", request.correlationId);
|
|
1582
1651
|
const validRequest = { ...request,
|
|
1583
|
-
...this.initializeBaseRequest(request),
|
|
1652
|
+
...(await this.initializeBaseRequest(request)),
|
|
1584
1653
|
authenticationScheme: msalCommon.AuthenticationScheme.BEARER
|
|
1585
1654
|
};
|
|
1586
1655
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByCode, validRequest.correlationId);
|
|
1587
1656
|
|
|
1588
1657
|
try {
|
|
1589
|
-
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1658
|
+
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1590
1659
|
const authorizationCodeClient = new msalCommon.AuthorizationCodeClient(authClientConfig);
|
|
1591
1660
|
this.logger.verbose("Auth code client created", validRequest.correlationId);
|
|
1592
|
-
return authorizationCodeClient.acquireToken(validRequest);
|
|
1661
|
+
return authorizationCodeClient.acquireToken(validRequest, authCodePayLoad);
|
|
1593
1662
|
} catch (e) {
|
|
1594
1663
|
if (e instanceof msalCommon.AuthError) {
|
|
1595
1664
|
e.setCorrelationId(validRequest.correlationId);
|
|
@@ -1611,13 +1680,13 @@ class ClientApplication {
|
|
|
1611
1680
|
async acquireTokenByRefreshToken(request) {
|
|
1612
1681
|
this.logger.info("acquireTokenByRefreshToken called", request.correlationId);
|
|
1613
1682
|
const validRequest = { ...request,
|
|
1614
|
-
...this.initializeBaseRequest(request),
|
|
1683
|
+
...(await this.initializeBaseRequest(request)),
|
|
1615
1684
|
authenticationScheme: msalCommon.AuthenticationScheme.BEARER
|
|
1616
1685
|
};
|
|
1617
1686
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByRefreshToken, validRequest.correlationId);
|
|
1618
1687
|
|
|
1619
1688
|
try {
|
|
1620
|
-
const refreshTokenClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1689
|
+
const refreshTokenClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1621
1690
|
const refreshTokenClient = new msalCommon.RefreshTokenClient(refreshTokenClientConfig);
|
|
1622
1691
|
this.logger.verbose("Refresh token client created", validRequest.correlationId);
|
|
1623
1692
|
return refreshTokenClient.acquireToken(validRequest);
|
|
@@ -1642,13 +1711,13 @@ class ClientApplication {
|
|
|
1642
1711
|
|
|
1643
1712
|
async acquireTokenSilent(request) {
|
|
1644
1713
|
const validRequest = { ...request,
|
|
1645
|
-
...this.initializeBaseRequest(request),
|
|
1714
|
+
...(await this.initializeBaseRequest(request)),
|
|
1646
1715
|
forceRefresh: request.forceRefresh || false
|
|
1647
1716
|
};
|
|
1648
1717
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent, validRequest.correlationId, validRequest.forceRefresh);
|
|
1649
1718
|
|
|
1650
1719
|
try {
|
|
1651
|
-
const silentFlowClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1720
|
+
const silentFlowClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1652
1721
|
const silentFlowClient = new msalCommon.SilentFlowClient(silentFlowClientConfig);
|
|
1653
1722
|
this.logger.verbose("Silent flow client created", validRequest.correlationId);
|
|
1654
1723
|
return silentFlowClient.acquireToken(validRequest);
|
|
@@ -1676,12 +1745,12 @@ class ClientApplication {
|
|
|
1676
1745
|
async acquireTokenByUsernamePassword(request) {
|
|
1677
1746
|
this.logger.info("acquireTokenByUsernamePassword called", request.correlationId);
|
|
1678
1747
|
const validRequest = { ...request,
|
|
1679
|
-
...this.initializeBaseRequest(request)
|
|
1748
|
+
...(await this.initializeBaseRequest(request))
|
|
1680
1749
|
};
|
|
1681
1750
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByUsernamePassword, validRequest.correlationId);
|
|
1682
1751
|
|
|
1683
1752
|
try {
|
|
1684
|
-
const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1753
|
+
const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1685
1754
|
const usernamePasswordClient = new msalCommon.UsernamePasswordClient(usernamePasswordClientConfig);
|
|
1686
1755
|
this.logger.verbose("Username password client created", validRequest.correlationId);
|
|
1687
1756
|
return usernamePasswordClient.acquireToken(validRequest);
|
|
@@ -1727,11 +1796,13 @@ class ClientApplication {
|
|
|
1727
1796
|
*/
|
|
1728
1797
|
|
|
1729
1798
|
|
|
1730
|
-
async buildOauthClientConfiguration(authority, requestCorrelationId, serverTelemetryManager, azureRegionConfiguration) {
|
|
1731
|
-
this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId); //
|
|
1799
|
+
async buildOauthClientConfiguration(authority, requestCorrelationId, serverTelemetryManager, azureRegionConfiguration, azureCloudOptions) {
|
|
1800
|
+
this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId); // precedence - azureCloudInstance + tenant >> authority and request >> config
|
|
1801
|
+
|
|
1802
|
+
const userAzureCloudOptions = azureCloudOptions ? azureCloudOptions : this.config.auth.azureCloudOptions; // using null assertion operator as we ensure that all config values have default values in buildConfiguration()
|
|
1732
1803
|
|
|
1733
1804
|
this.logger.verbose(`building oauth client configuration with the authority: ${authority}`, requestCorrelationId);
|
|
1734
|
-
const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId);
|
|
1805
|
+
const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId, userAzureCloudOptions);
|
|
1735
1806
|
serverTelemetryManager == null ? void 0 : serverTelemetryManager.updateRegionDiscoveryMetadata(discoveredAuthority.regionDiscoveryMetadata);
|
|
1736
1807
|
return {
|
|
1737
1808
|
authOptions: {
|
|
@@ -1739,6 +1810,9 @@ class ClientApplication {
|
|
|
1739
1810
|
authority: discoveredAuthority,
|
|
1740
1811
|
clientCapabilities: this.config.auth.clientCapabilities
|
|
1741
1812
|
},
|
|
1813
|
+
systemOptions: {
|
|
1814
|
+
proxyUrl: this.config.system.proxyUrl
|
|
1815
|
+
},
|
|
1742
1816
|
loggerOptions: {
|
|
1743
1817
|
logLevel: this.config.system.loggerOptions.logLevel,
|
|
1744
1818
|
loggerCallback: this.config.system.loggerOptions.loggerCallback,
|
|
@@ -1776,14 +1850,19 @@ class ClientApplication {
|
|
|
1776
1850
|
*/
|
|
1777
1851
|
|
|
1778
1852
|
|
|
1779
|
-
initializeBaseRequest(authRequest) {
|
|
1853
|
+
async initializeBaseRequest(authRequest) {
|
|
1780
1854
|
this.logger.verbose("initializeRequestScopes called", authRequest.correlationId); // Default authenticationScheme to Bearer, log that POP isn't supported yet
|
|
1781
1855
|
|
|
1782
1856
|
if (authRequest.authenticationScheme && authRequest.authenticationScheme === msalCommon.AuthenticationScheme.POP) {
|
|
1783
1857
|
this.logger.verbose("Authentication Scheme 'pop' is not supported yet, setting Authentication Scheme to 'Bearer' for request", authRequest.correlationId);
|
|
1784
1858
|
}
|
|
1785
1859
|
|
|
1786
|
-
authRequest.authenticationScheme = msalCommon.AuthenticationScheme.BEARER;
|
|
1860
|
+
authRequest.authenticationScheme = msalCommon.AuthenticationScheme.BEARER; // Set requested claims hash if claims were requested
|
|
1861
|
+
|
|
1862
|
+
if (authRequest.claims && !msalCommon.StringUtils.isEmpty(authRequest.claims)) {
|
|
1863
|
+
authRequest.requestedClaimsHash = await this.cryptoProvider.hashString(authRequest.claims);
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1787
1866
|
return { ...authRequest,
|
|
1788
1867
|
scopes: [...(authRequest && authRequest.scopes || []), ...msalCommon.OIDC_DEFAULT_SCOPES],
|
|
1789
1868
|
correlationId: authRequest && authRequest.correlationId || this.cryptoProvider.createNewGuid(),
|
|
@@ -1814,8 +1893,10 @@ class ClientApplication {
|
|
|
1814
1893
|
*/
|
|
1815
1894
|
|
|
1816
1895
|
|
|
1817
|
-
async createAuthority(authorityString, azureRegionConfiguration, requestCorrelationId) {
|
|
1818
|
-
this.logger.verbose("createAuthority called", requestCorrelationId);
|
|
1896
|
+
async createAuthority(authorityString, azureRegionConfiguration, requestCorrelationId, azureCloudOptions) {
|
|
1897
|
+
this.logger.verbose("createAuthority called", requestCorrelationId); // build authority string based on auth params - azureCloudInstance is prioritized if provided
|
|
1898
|
+
|
|
1899
|
+
const authorityUrl = msalCommon.Authority.generateAuthority(authorityString, azureCloudOptions);
|
|
1819
1900
|
const authorityOptions = {
|
|
1820
1901
|
protocolMode: this.config.auth.protocolMode,
|
|
1821
1902
|
knownAuthorities: this.config.auth.knownAuthorities,
|
|
@@ -1823,7 +1904,15 @@ class ClientApplication {
|
|
|
1823
1904
|
authorityMetadata: this.config.auth.authorityMetadata,
|
|
1824
1905
|
azureRegionConfiguration
|
|
1825
1906
|
};
|
|
1826
|
-
return await msalCommon.AuthorityFactory.createDiscoveredInstance(
|
|
1907
|
+
return await msalCommon.AuthorityFactory.createDiscoveredInstance(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions);
|
|
1908
|
+
}
|
|
1909
|
+
/**
|
|
1910
|
+
* Clear the cache
|
|
1911
|
+
*/
|
|
1912
|
+
|
|
1913
|
+
|
|
1914
|
+
clearCache() {
|
|
1915
|
+
this.storage.clear();
|
|
1827
1916
|
}
|
|
1828
1917
|
|
|
1829
1918
|
}
|
|
@@ -1872,11 +1961,11 @@ class PublicClientApplication extends ClientApplication {
|
|
|
1872
1961
|
|
|
1873
1962
|
async acquireTokenByDeviceCode(request) {
|
|
1874
1963
|
this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
|
|
1875
|
-
const validRequest = Object.assign(request, this.initializeBaseRequest(request));
|
|
1964
|
+
const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
|
|
1876
1965
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
|
|
1877
1966
|
|
|
1878
1967
|
try {
|
|
1879
|
-
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1968
|
+
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1880
1969
|
const deviceCodeClient = new msalCommon.DeviceCodeClient(deviceCodeConfig);
|
|
1881
1970
|
this.logger.verbose("Device code client created", validRequest.correlationId);
|
|
1882
1971
|
return deviceCodeClient.acquireToken(validRequest);
|
|
@@ -2071,7 +2160,7 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2071
2160
|
async acquireTokenByClientCredential(request) {
|
|
2072
2161
|
this.logger.info("acquireTokenByClientCredential called", request.correlationId);
|
|
2073
2162
|
const validRequest = { ...request,
|
|
2074
|
-
...this.initializeBaseRequest(request)
|
|
2163
|
+
...(await this.initializeBaseRequest(request))
|
|
2075
2164
|
};
|
|
2076
2165
|
const azureRegionConfiguration = {
|
|
2077
2166
|
azureRegion: validRequest.azureRegion,
|
|
@@ -2080,7 +2169,7 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2080
2169
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByClientCredential, validRequest.correlationId, validRequest.skipCache);
|
|
2081
2170
|
|
|
2082
2171
|
try {
|
|
2083
|
-
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration);
|
|
2172
|
+
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration, request.azureCloudOptions);
|
|
2084
2173
|
const clientCredentialClient = new msalCommon.ClientCredentialClient(clientCredentialConfig);
|
|
2085
2174
|
this.logger.verbose("Client credential client created", validRequest.correlationId);
|
|
2086
2175
|
return clientCredentialClient.acquireToken(validRequest);
|
|
@@ -2109,11 +2198,11 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2109
2198
|
async acquireTokenOnBehalfOf(request) {
|
|
2110
2199
|
this.logger.info("acquireTokenOnBehalfOf called", request.correlationId);
|
|
2111
2200
|
const validRequest = { ...request,
|
|
2112
|
-
...this.initializeBaseRequest(request)
|
|
2201
|
+
...(await this.initializeBaseRequest(request))
|
|
2113
2202
|
};
|
|
2114
2203
|
|
|
2115
2204
|
try {
|
|
2116
|
-
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId);
|
|
2205
|
+
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
|
|
2117
2206
|
const oboClient = new msalCommon.OnBehalfOfClient(clientCredentialConfig);
|
|
2118
2207
|
this.logger.verbose("On behalf of client created", validRequest.correlationId);
|
|
2119
2208
|
return oboClient.acquireToken(validRequest);
|
|
@@ -2160,6 +2249,37 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2160
2249
|
|
|
2161
2250
|
}
|
|
2162
2251
|
|
|
2252
|
+
/*
|
|
2253
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2254
|
+
* Licensed under the MIT License.
|
|
2255
|
+
*/
|
|
2256
|
+
class DistributedCachePlugin {
|
|
2257
|
+
constructor(client, partitionManager) {
|
|
2258
|
+
this.client = client;
|
|
2259
|
+
this.partitionManager = partitionManager;
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
async beforeCacheAccess(cacheContext) {
|
|
2263
|
+
const partitionKey = await this.partitionManager.getKey();
|
|
2264
|
+
const cacheData = await this.client.get(partitionKey);
|
|
2265
|
+
cacheContext.tokenCache.deserialize(cacheData);
|
|
2266
|
+
}
|
|
2267
|
+
|
|
2268
|
+
async afterCacheAccess(cacheContext) {
|
|
2269
|
+
if (cacheContext.cacheHasChanged) {
|
|
2270
|
+
const kvStore = cacheContext.tokenCache.getKVStore();
|
|
2271
|
+
const accountEntities = Object.values(kvStore).filter(value => msalCommon.AccountEntity.isAccountEntity(value));
|
|
2272
|
+
|
|
2273
|
+
if (accountEntities.length > 0) {
|
|
2274
|
+
const accountEntity = accountEntities[0];
|
|
2275
|
+
const partitionKey = await this.partitionManager.extractKey(accountEntity);
|
|
2276
|
+
await this.client.set(partitionKey, cacheContext.tokenCache.serialize());
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2163
2283
|
Object.defineProperty(exports, 'AuthError', {
|
|
2164
2284
|
enumerable: true,
|
|
2165
2285
|
get: function () {
|
|
@@ -2172,6 +2292,12 @@ Object.defineProperty(exports, 'AuthErrorMessage', {
|
|
|
2172
2292
|
return msalCommon.AuthErrorMessage;
|
|
2173
2293
|
}
|
|
2174
2294
|
});
|
|
2295
|
+
Object.defineProperty(exports, 'AzureCloudInstance', {
|
|
2296
|
+
enumerable: true,
|
|
2297
|
+
get: function () {
|
|
2298
|
+
return msalCommon.AzureCloudInstance;
|
|
2299
|
+
}
|
|
2300
|
+
});
|
|
2175
2301
|
Object.defineProperty(exports, 'ClientAuthError', {
|
|
2176
2302
|
enumerable: true,
|
|
2177
2303
|
get: function () {
|
|
@@ -2254,6 +2380,7 @@ exports.ClientApplication = ClientApplication;
|
|
|
2254
2380
|
exports.ClientAssertion = ClientAssertion;
|
|
2255
2381
|
exports.ConfidentialClientApplication = ConfidentialClientApplication;
|
|
2256
2382
|
exports.CryptoProvider = CryptoProvider;
|
|
2383
|
+
exports.DistributedCachePlugin = DistributedCachePlugin;
|
|
2257
2384
|
exports.NodeStorage = NodeStorage;
|
|
2258
2385
|
exports.PublicClientApplication = PublicClientApplication;
|
|
2259
2386
|
exports.TokenCache = TokenCache;
|