@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
package/dist/msal-node.esm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Constants as Constants$1, ProtocolMode, LogLevel, StringUtils, AccountEntity, CacheManager, IdTokenEntity, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, ServerTelemetryEntity, AuthorityMetadataEntity, ThrottlingEntity, TokenCacheContext, Logger, ResponseMode, AuthenticationScheme, AuthorizationCodeClient, AuthError, RefreshTokenClient, SilentFlowClient, UsernamePasswordClient, OIDC_DEFAULT_SCOPES, ServerTelemetryManager, AuthorityFactory, DeviceCodeClient, ClientAuthError, TimeUtils, ClientCredentialClient, OnBehalfOfClient } from '@azure/msal-common';
|
|
2
|
-
export { AuthError, AuthErrorMessage, ClientAuthError, ClientAuthErrorMessage, ClientConfigurationError, ClientConfigurationErrorMessage, InteractionRequiredAuthError, InteractionRequiredAuthErrorMessage, LogLevel, Logger, PromptValue, ProtocolMode, ResponseMode, ServerError, TokenCacheContext } from '@azure/msal-common';
|
|
1
|
+
import { Constants as Constants$1, ProtocolMode, AzureCloudInstance, LogLevel, StringUtils, AccountEntity, CacheManager, IdTokenEntity, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, ServerTelemetryEntity, AuthorityMetadataEntity, ThrottlingEntity, TokenCacheContext, Logger, ResponseMode, AuthenticationScheme, AuthorizationCodeClient, AuthError, RefreshTokenClient, SilentFlowClient, UsernamePasswordClient, OIDC_DEFAULT_SCOPES, ServerTelemetryManager, Authority, AuthorityFactory, DeviceCodeClient, ClientAuthError, TimeUtils, ClientCredentialClient, OnBehalfOfClient } from '@azure/msal-common';
|
|
2
|
+
export { AuthError, AuthErrorMessage, AzureCloudInstance, ClientAuthError, ClientAuthErrorMessage, ClientConfigurationError, ClientConfigurationErrorMessage, InteractionRequiredAuthError, InteractionRequiredAuthErrorMessage, LogLevel, Logger, PromptValue, ProtocolMode, ResponseMode, ServerError, TokenCacheContext } from '@azure/msal-common';
|
|
3
3
|
import axios from 'axios';
|
|
4
|
+
import createHttpsProxyAgent from 'https-proxy-agent';
|
|
4
5
|
import { v4 } from 'uuid';
|
|
5
6
|
import crypto from 'crypto';
|
|
6
7
|
import { sign } from 'jsonwebtoken';
|
|
@@ -113,6 +114,13 @@ class HttpClient {
|
|
|
113
114
|
/* istanbul ignore next */
|
|
114
115
|
validateStatus: () => true
|
|
115
116
|
};
|
|
117
|
+
|
|
118
|
+
if (options && options.proxyUrl) {
|
|
119
|
+
// for axios, this has to be disabled
|
|
120
|
+
request.proxy = false;
|
|
121
|
+
request.httpsAgent = createHttpsProxyAgent(options.proxyUrl);
|
|
122
|
+
}
|
|
123
|
+
|
|
116
124
|
const response = await axios(request);
|
|
117
125
|
return {
|
|
118
126
|
headers: response.headers,
|
|
@@ -142,6 +150,13 @@ class HttpClient {
|
|
|
142
150
|
/* istanbul ignore next */
|
|
143
151
|
validateStatus: () => true
|
|
144
152
|
};
|
|
153
|
+
|
|
154
|
+
if (options && options.proxyUrl) {
|
|
155
|
+
// for axios, this has to be disabled
|
|
156
|
+
request.proxy = false;
|
|
157
|
+
request.httpsAgent = createHttpsProxyAgent(options.proxyUrl);
|
|
158
|
+
}
|
|
159
|
+
|
|
145
160
|
const response = await axios(request);
|
|
146
161
|
return {
|
|
147
162
|
headers: response.headers,
|
|
@@ -184,7 +199,11 @@ const DEFAULT_AUTH_OPTIONS = {
|
|
|
184
199
|
cloudDiscoveryMetadata: "",
|
|
185
200
|
authorityMetadata: "",
|
|
186
201
|
clientCapabilities: [],
|
|
187
|
-
protocolMode: ProtocolMode.AAD
|
|
202
|
+
protocolMode: ProtocolMode.AAD,
|
|
203
|
+
azureCloudOptions: {
|
|
204
|
+
azureCloudInstance: AzureCloudInstance.None,
|
|
205
|
+
tenant: ""
|
|
206
|
+
}
|
|
188
207
|
};
|
|
189
208
|
const DEFAULT_CACHE_OPTIONS = {};
|
|
190
209
|
const DEFAULT_LOGGER_OPTIONS = {
|
|
@@ -195,7 +214,8 @@ const DEFAULT_LOGGER_OPTIONS = {
|
|
|
195
214
|
};
|
|
196
215
|
const DEFAULT_SYSTEM_OPTIONS = {
|
|
197
216
|
loggerOptions: DEFAULT_LOGGER_OPTIONS,
|
|
198
|
-
networkClient: /*#__PURE__*/NetworkUtils.getNetworkClient()
|
|
217
|
+
networkClient: /*#__PURE__*/NetworkUtils.getNetworkClient(),
|
|
218
|
+
proxyUrl: ""
|
|
199
219
|
};
|
|
200
220
|
/**
|
|
201
221
|
* Sets the default options when not explicitly configured from app developer
|
|
@@ -303,6 +323,21 @@ class EncodingUtils {
|
|
|
303
323
|
|
|
304
324
|
}
|
|
305
325
|
|
|
326
|
+
/*
|
|
327
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
328
|
+
* Licensed under the MIT License.
|
|
329
|
+
*/
|
|
330
|
+
class HashUtils {
|
|
331
|
+
/**
|
|
332
|
+
* generate 'SHA256' hash
|
|
333
|
+
* @param buffer
|
|
334
|
+
*/
|
|
335
|
+
sha256(buffer) {
|
|
336
|
+
return crypto.createHash(Hash.SHA256).update(buffer).digest();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
}
|
|
340
|
+
|
|
306
341
|
/*
|
|
307
342
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
308
343
|
* Licensed under the MIT License.
|
|
@@ -312,10 +347,15 @@ class EncodingUtils {
|
|
|
312
347
|
*/
|
|
313
348
|
|
|
314
349
|
class PkceGenerator {
|
|
350
|
+
constructor() {
|
|
351
|
+
this.hashUtils = new HashUtils();
|
|
352
|
+
}
|
|
315
353
|
/**
|
|
316
354
|
* generates the codeVerfier and the challenge from the codeVerfier
|
|
317
355
|
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
|
|
318
356
|
*/
|
|
357
|
+
|
|
358
|
+
|
|
319
359
|
async generatePkceCodes() {
|
|
320
360
|
const verifier = this.generateCodeVerifier();
|
|
321
361
|
const challenge = this.generateCodeChallengeFromVerifier(verifier);
|
|
@@ -358,16 +398,7 @@ class PkceGenerator {
|
|
|
358
398
|
|
|
359
399
|
|
|
360
400
|
generateCodeChallengeFromVerifier(codeVerifier) {
|
|
361
|
-
return EncodingUtils.base64EncodeUrl(this.sha256(codeVerifier).toString("base64"), "base64");
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* generate 'SHA256' hash
|
|
365
|
-
* @param buffer
|
|
366
|
-
*/
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
sha256(buffer) {
|
|
370
|
-
return crypto.createHash(Hash.SHA256).update(buffer).digest();
|
|
401
|
+
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString("base64"), "base64");
|
|
371
402
|
}
|
|
372
403
|
|
|
373
404
|
}
|
|
@@ -386,6 +417,7 @@ class CryptoProvider {
|
|
|
386
417
|
constructor() {
|
|
387
418
|
// Browser crypto needs to be validated first before any other classes can be set.
|
|
388
419
|
this.pkceGenerator = new PkceGenerator();
|
|
420
|
+
this.hashUtils = new HashUtils();
|
|
389
421
|
}
|
|
390
422
|
/**
|
|
391
423
|
* Creates a new random GUID - used to populate state and nonce.
|
|
@@ -455,6 +487,14 @@ class CryptoProvider {
|
|
|
455
487
|
signJwt() {
|
|
456
488
|
throw new Error("Method not implemented.");
|
|
457
489
|
}
|
|
490
|
+
/**
|
|
491
|
+
* Returns the SHA-256 hash of an input string
|
|
492
|
+
*/
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
async hashString(plainText) {
|
|
496
|
+
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(plainText).toString("base64"), "base64");
|
|
497
|
+
}
|
|
458
498
|
|
|
459
499
|
}
|
|
460
500
|
|
|
@@ -560,7 +600,9 @@ class Deserializer {
|
|
|
560
600
|
extendedExpiresOn: serializedAT.extended_expires_on,
|
|
561
601
|
refreshOn: serializedAT.refresh_on,
|
|
562
602
|
keyId: serializedAT.key_id,
|
|
563
|
-
tokenType: serializedAT.token_type
|
|
603
|
+
tokenType: serializedAT.token_type,
|
|
604
|
+
requestedClaims: serializedAT.requestedClaims,
|
|
605
|
+
requestedClaimsHash: serializedAT.requestedClaimsHash
|
|
564
606
|
};
|
|
565
607
|
const accessToken = new AccessTokenEntity();
|
|
566
608
|
CacheManager.toObject(accessToken, mappedAT);
|
|
@@ -724,7 +766,9 @@ class Serializer {
|
|
|
724
766
|
extended_expires_on: atEntity.extendedExpiresOn,
|
|
725
767
|
refresh_on: atEntity.refreshOn,
|
|
726
768
|
key_id: atEntity.keyId,
|
|
727
|
-
token_type: atEntity.tokenType
|
|
769
|
+
token_type: atEntity.tokenType,
|
|
770
|
+
requestedClaims: atEntity.requestedClaims,
|
|
771
|
+
requestedClaimsHash: atEntity.requestedClaimsHash
|
|
728
772
|
};
|
|
729
773
|
});
|
|
730
774
|
return accessTokens;
|
|
@@ -863,12 +907,14 @@ class NodeStorage extends CacheManager {
|
|
|
863
907
|
inMemoryCacheToCache(inMemoryCache) {
|
|
864
908
|
// convert in memory cache to a flat Key-Value map
|
|
865
909
|
let cache = this.getCache();
|
|
866
|
-
cache = { ...
|
|
910
|
+
cache = { ...cache,
|
|
911
|
+
...inMemoryCache.accounts,
|
|
867
912
|
...inMemoryCache.idTokens,
|
|
868
913
|
...inMemoryCache.accessTokens,
|
|
869
914
|
...inMemoryCache.refreshTokens,
|
|
870
915
|
...inMemoryCache.appMetadata
|
|
871
|
-
};
|
|
916
|
+
}; // convert in memory cache to a flat Key-Value map
|
|
917
|
+
|
|
872
918
|
return cache;
|
|
873
919
|
}
|
|
874
920
|
/**
|
|
@@ -1232,6 +1278,29 @@ class NodeStorage extends CacheManager {
|
|
|
1232
1278
|
static generateJsonCache(inMemoryCache) {
|
|
1233
1279
|
return Serializer.serializeAllCache(inMemoryCache);
|
|
1234
1280
|
}
|
|
1281
|
+
/**
|
|
1282
|
+
* Updates a credential's cache key if the current cache key is outdated
|
|
1283
|
+
*/
|
|
1284
|
+
|
|
1285
|
+
|
|
1286
|
+
updateCredentialCacheKey(currentCacheKey, credential) {
|
|
1287
|
+
const updatedCacheKey = credential.generateCredentialKey();
|
|
1288
|
+
|
|
1289
|
+
if (currentCacheKey !== updatedCacheKey) {
|
|
1290
|
+
const cacheItem = this.getItem(currentCacheKey);
|
|
1291
|
+
|
|
1292
|
+
if (cacheItem) {
|
|
1293
|
+
this.removeItem(currentCacheKey);
|
|
1294
|
+
this.setItem(updatedCacheKey, cacheItem);
|
|
1295
|
+
this.logger.verbose(`Updated an outdated ${credential.credentialType} cache key`);
|
|
1296
|
+
return updatedCacheKey;
|
|
1297
|
+
} else {
|
|
1298
|
+
this.logger.error(`Attempted to update an outdated ${credential.credentialType} cache key but no item matching the outdated key was found in storage`);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
return currentCacheKey;
|
|
1303
|
+
}
|
|
1235
1304
|
|
|
1236
1305
|
}
|
|
1237
1306
|
|
|
@@ -1517,7 +1586,7 @@ class TokenCache {
|
|
|
1517
1586
|
|
|
1518
1587
|
/* eslint-disable header/header */
|
|
1519
1588
|
const name = "@azure/msal-node";
|
|
1520
|
-
const version = "1.
|
|
1589
|
+
const version = "1.7.0";
|
|
1521
1590
|
|
|
1522
1591
|
/*
|
|
1523
1592
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1553,11 +1622,11 @@ class ClientApplication {
|
|
|
1553
1622
|
async getAuthCodeUrl(request) {
|
|
1554
1623
|
this.logger.info("getAuthCodeUrl called", request.correlationId);
|
|
1555
1624
|
const validRequest = { ...request,
|
|
1556
|
-
...this.initializeBaseRequest(request),
|
|
1625
|
+
...(await this.initializeBaseRequest(request)),
|
|
1557
1626
|
responseMode: request.responseMode || ResponseMode.QUERY,
|
|
1558
1627
|
authenticationScheme: AuthenticationScheme.BEARER
|
|
1559
1628
|
};
|
|
1560
|
-
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId);
|
|
1629
|
+
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
|
|
1561
1630
|
const authorizationCodeClient = new AuthorizationCodeClient(authClientConfig);
|
|
1562
1631
|
this.logger.verbose("Auth code client created", validRequest.correlationId);
|
|
1563
1632
|
return authorizationCodeClient.getAuthCodeUrl(validRequest);
|
|
@@ -1572,19 +1641,19 @@ class ClientApplication {
|
|
|
1572
1641
|
*/
|
|
1573
1642
|
|
|
1574
1643
|
|
|
1575
|
-
async acquireTokenByCode(request) {
|
|
1644
|
+
async acquireTokenByCode(request, authCodePayLoad) {
|
|
1576
1645
|
this.logger.info("acquireTokenByCode called", request.correlationId);
|
|
1577
1646
|
const validRequest = { ...request,
|
|
1578
|
-
...this.initializeBaseRequest(request),
|
|
1647
|
+
...(await this.initializeBaseRequest(request)),
|
|
1579
1648
|
authenticationScheme: AuthenticationScheme.BEARER
|
|
1580
1649
|
};
|
|
1581
1650
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByCode, validRequest.correlationId);
|
|
1582
1651
|
|
|
1583
1652
|
try {
|
|
1584
|
-
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1653
|
+
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1585
1654
|
const authorizationCodeClient = new AuthorizationCodeClient(authClientConfig);
|
|
1586
1655
|
this.logger.verbose("Auth code client created", validRequest.correlationId);
|
|
1587
|
-
return authorizationCodeClient.acquireToken(validRequest);
|
|
1656
|
+
return authorizationCodeClient.acquireToken(validRequest, authCodePayLoad);
|
|
1588
1657
|
} catch (e) {
|
|
1589
1658
|
if (e instanceof AuthError) {
|
|
1590
1659
|
e.setCorrelationId(validRequest.correlationId);
|
|
@@ -1606,13 +1675,13 @@ class ClientApplication {
|
|
|
1606
1675
|
async acquireTokenByRefreshToken(request) {
|
|
1607
1676
|
this.logger.info("acquireTokenByRefreshToken called", request.correlationId);
|
|
1608
1677
|
const validRequest = { ...request,
|
|
1609
|
-
...this.initializeBaseRequest(request),
|
|
1678
|
+
...(await this.initializeBaseRequest(request)),
|
|
1610
1679
|
authenticationScheme: AuthenticationScheme.BEARER
|
|
1611
1680
|
};
|
|
1612
1681
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByRefreshToken, validRequest.correlationId);
|
|
1613
1682
|
|
|
1614
1683
|
try {
|
|
1615
|
-
const refreshTokenClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1684
|
+
const refreshTokenClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1616
1685
|
const refreshTokenClient = new RefreshTokenClient(refreshTokenClientConfig);
|
|
1617
1686
|
this.logger.verbose("Refresh token client created", validRequest.correlationId);
|
|
1618
1687
|
return refreshTokenClient.acquireToken(validRequest);
|
|
@@ -1637,13 +1706,13 @@ class ClientApplication {
|
|
|
1637
1706
|
|
|
1638
1707
|
async acquireTokenSilent(request) {
|
|
1639
1708
|
const validRequest = { ...request,
|
|
1640
|
-
...this.initializeBaseRequest(request),
|
|
1709
|
+
...(await this.initializeBaseRequest(request)),
|
|
1641
1710
|
forceRefresh: request.forceRefresh || false
|
|
1642
1711
|
};
|
|
1643
1712
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent, validRequest.correlationId, validRequest.forceRefresh);
|
|
1644
1713
|
|
|
1645
1714
|
try {
|
|
1646
|
-
const silentFlowClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1715
|
+
const silentFlowClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1647
1716
|
const silentFlowClient = new SilentFlowClient(silentFlowClientConfig);
|
|
1648
1717
|
this.logger.verbose("Silent flow client created", validRequest.correlationId);
|
|
1649
1718
|
return silentFlowClient.acquireToken(validRequest);
|
|
@@ -1671,12 +1740,12 @@ class ClientApplication {
|
|
|
1671
1740
|
async acquireTokenByUsernamePassword(request) {
|
|
1672
1741
|
this.logger.info("acquireTokenByUsernamePassword called", request.correlationId);
|
|
1673
1742
|
const validRequest = { ...request,
|
|
1674
|
-
...this.initializeBaseRequest(request)
|
|
1743
|
+
...(await this.initializeBaseRequest(request))
|
|
1675
1744
|
};
|
|
1676
1745
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByUsernamePassword, validRequest.correlationId);
|
|
1677
1746
|
|
|
1678
1747
|
try {
|
|
1679
|
-
const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1748
|
+
const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1680
1749
|
const usernamePasswordClient = new UsernamePasswordClient(usernamePasswordClientConfig);
|
|
1681
1750
|
this.logger.verbose("Username password client created", validRequest.correlationId);
|
|
1682
1751
|
return usernamePasswordClient.acquireToken(validRequest);
|
|
@@ -1722,11 +1791,13 @@ class ClientApplication {
|
|
|
1722
1791
|
*/
|
|
1723
1792
|
|
|
1724
1793
|
|
|
1725
|
-
async buildOauthClientConfiguration(authority, requestCorrelationId, serverTelemetryManager, azureRegionConfiguration) {
|
|
1726
|
-
this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId); //
|
|
1794
|
+
async buildOauthClientConfiguration(authority, requestCorrelationId, serverTelemetryManager, azureRegionConfiguration, azureCloudOptions) {
|
|
1795
|
+
this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId); // precedence - azureCloudInstance + tenant >> authority and request >> config
|
|
1796
|
+
|
|
1797
|
+
const userAzureCloudOptions = azureCloudOptions ? azureCloudOptions : this.config.auth.azureCloudOptions; // using null assertion operator as we ensure that all config values have default values in buildConfiguration()
|
|
1727
1798
|
|
|
1728
1799
|
this.logger.verbose(`building oauth client configuration with the authority: ${authority}`, requestCorrelationId);
|
|
1729
|
-
const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId);
|
|
1800
|
+
const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId, userAzureCloudOptions);
|
|
1730
1801
|
serverTelemetryManager == null ? void 0 : serverTelemetryManager.updateRegionDiscoveryMetadata(discoveredAuthority.regionDiscoveryMetadata);
|
|
1731
1802
|
return {
|
|
1732
1803
|
authOptions: {
|
|
@@ -1734,6 +1805,9 @@ class ClientApplication {
|
|
|
1734
1805
|
authority: discoveredAuthority,
|
|
1735
1806
|
clientCapabilities: this.config.auth.clientCapabilities
|
|
1736
1807
|
},
|
|
1808
|
+
systemOptions: {
|
|
1809
|
+
proxyUrl: this.config.system.proxyUrl
|
|
1810
|
+
},
|
|
1737
1811
|
loggerOptions: {
|
|
1738
1812
|
logLevel: this.config.system.loggerOptions.logLevel,
|
|
1739
1813
|
loggerCallback: this.config.system.loggerOptions.loggerCallback,
|
|
@@ -1771,14 +1845,19 @@ class ClientApplication {
|
|
|
1771
1845
|
*/
|
|
1772
1846
|
|
|
1773
1847
|
|
|
1774
|
-
initializeBaseRequest(authRequest) {
|
|
1848
|
+
async initializeBaseRequest(authRequest) {
|
|
1775
1849
|
this.logger.verbose("initializeRequestScopes called", authRequest.correlationId); // Default authenticationScheme to Bearer, log that POP isn't supported yet
|
|
1776
1850
|
|
|
1777
1851
|
if (authRequest.authenticationScheme && authRequest.authenticationScheme === AuthenticationScheme.POP) {
|
|
1778
1852
|
this.logger.verbose("Authentication Scheme 'pop' is not supported yet, setting Authentication Scheme to 'Bearer' for request", authRequest.correlationId);
|
|
1779
1853
|
}
|
|
1780
1854
|
|
|
1781
|
-
authRequest.authenticationScheme = AuthenticationScheme.BEARER;
|
|
1855
|
+
authRequest.authenticationScheme = AuthenticationScheme.BEARER; // Set requested claims hash if claims were requested
|
|
1856
|
+
|
|
1857
|
+
if (authRequest.claims && !StringUtils.isEmpty(authRequest.claims)) {
|
|
1858
|
+
authRequest.requestedClaimsHash = await this.cryptoProvider.hashString(authRequest.claims);
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1782
1861
|
return { ...authRequest,
|
|
1783
1862
|
scopes: [...(authRequest && authRequest.scopes || []), ...OIDC_DEFAULT_SCOPES],
|
|
1784
1863
|
correlationId: authRequest && authRequest.correlationId || this.cryptoProvider.createNewGuid(),
|
|
@@ -1809,8 +1888,10 @@ class ClientApplication {
|
|
|
1809
1888
|
*/
|
|
1810
1889
|
|
|
1811
1890
|
|
|
1812
|
-
async createAuthority(authorityString, azureRegionConfiguration, requestCorrelationId) {
|
|
1813
|
-
this.logger.verbose("createAuthority called", requestCorrelationId);
|
|
1891
|
+
async createAuthority(authorityString, azureRegionConfiguration, requestCorrelationId, azureCloudOptions) {
|
|
1892
|
+
this.logger.verbose("createAuthority called", requestCorrelationId); // build authority string based on auth params - azureCloudInstance is prioritized if provided
|
|
1893
|
+
|
|
1894
|
+
const authorityUrl = Authority.generateAuthority(authorityString, azureCloudOptions);
|
|
1814
1895
|
const authorityOptions = {
|
|
1815
1896
|
protocolMode: this.config.auth.protocolMode,
|
|
1816
1897
|
knownAuthorities: this.config.auth.knownAuthorities,
|
|
@@ -1818,7 +1899,15 @@ class ClientApplication {
|
|
|
1818
1899
|
authorityMetadata: this.config.auth.authorityMetadata,
|
|
1819
1900
|
azureRegionConfiguration
|
|
1820
1901
|
};
|
|
1821
|
-
return await AuthorityFactory.createDiscoveredInstance(
|
|
1902
|
+
return await AuthorityFactory.createDiscoveredInstance(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions);
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Clear the cache
|
|
1906
|
+
*/
|
|
1907
|
+
|
|
1908
|
+
|
|
1909
|
+
clearCache() {
|
|
1910
|
+
this.storage.clear();
|
|
1822
1911
|
}
|
|
1823
1912
|
|
|
1824
1913
|
}
|
|
@@ -1867,11 +1956,11 @@ class PublicClientApplication extends ClientApplication {
|
|
|
1867
1956
|
|
|
1868
1957
|
async acquireTokenByDeviceCode(request) {
|
|
1869
1958
|
this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
|
|
1870
|
-
const validRequest = Object.assign(request, this.initializeBaseRequest(request));
|
|
1959
|
+
const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
|
|
1871
1960
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
|
|
1872
1961
|
|
|
1873
1962
|
try {
|
|
1874
|
-
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1963
|
+
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1875
1964
|
const deviceCodeClient = new DeviceCodeClient(deviceCodeConfig);
|
|
1876
1965
|
this.logger.verbose("Device code client created", validRequest.correlationId);
|
|
1877
1966
|
return deviceCodeClient.acquireToken(validRequest);
|
|
@@ -2066,7 +2155,7 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2066
2155
|
async acquireTokenByClientCredential(request) {
|
|
2067
2156
|
this.logger.info("acquireTokenByClientCredential called", request.correlationId);
|
|
2068
2157
|
const validRequest = { ...request,
|
|
2069
|
-
...this.initializeBaseRequest(request)
|
|
2158
|
+
...(await this.initializeBaseRequest(request))
|
|
2070
2159
|
};
|
|
2071
2160
|
const azureRegionConfiguration = {
|
|
2072
2161
|
azureRegion: validRequest.azureRegion,
|
|
@@ -2075,7 +2164,7 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2075
2164
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByClientCredential, validRequest.correlationId, validRequest.skipCache);
|
|
2076
2165
|
|
|
2077
2166
|
try {
|
|
2078
|
-
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration);
|
|
2167
|
+
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration, request.azureCloudOptions);
|
|
2079
2168
|
const clientCredentialClient = new ClientCredentialClient(clientCredentialConfig);
|
|
2080
2169
|
this.logger.verbose("Client credential client created", validRequest.correlationId);
|
|
2081
2170
|
return clientCredentialClient.acquireToken(validRequest);
|
|
@@ -2104,11 +2193,11 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2104
2193
|
async acquireTokenOnBehalfOf(request) {
|
|
2105
2194
|
this.logger.info("acquireTokenOnBehalfOf called", request.correlationId);
|
|
2106
2195
|
const validRequest = { ...request,
|
|
2107
|
-
...this.initializeBaseRequest(request)
|
|
2196
|
+
...(await this.initializeBaseRequest(request))
|
|
2108
2197
|
};
|
|
2109
2198
|
|
|
2110
2199
|
try {
|
|
2111
|
-
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId);
|
|
2200
|
+
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
|
|
2112
2201
|
const oboClient = new OnBehalfOfClient(clientCredentialConfig);
|
|
2113
2202
|
this.logger.verbose("On behalf of client created", validRequest.correlationId);
|
|
2114
2203
|
return oboClient.acquireToken(validRequest);
|
|
@@ -2155,5 +2244,36 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2155
2244
|
|
|
2156
2245
|
}
|
|
2157
2246
|
|
|
2158
|
-
|
|
2247
|
+
/*
|
|
2248
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2249
|
+
* Licensed under the MIT License.
|
|
2250
|
+
*/
|
|
2251
|
+
class DistributedCachePlugin {
|
|
2252
|
+
constructor(client, partitionManager) {
|
|
2253
|
+
this.client = client;
|
|
2254
|
+
this.partitionManager = partitionManager;
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
async beforeCacheAccess(cacheContext) {
|
|
2258
|
+
const partitionKey = await this.partitionManager.getKey();
|
|
2259
|
+
const cacheData = await this.client.get(partitionKey);
|
|
2260
|
+
cacheContext.tokenCache.deserialize(cacheData);
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
async afterCacheAccess(cacheContext) {
|
|
2264
|
+
if (cacheContext.cacheHasChanged) {
|
|
2265
|
+
const kvStore = cacheContext.tokenCache.getKVStore();
|
|
2266
|
+
const accountEntities = Object.values(kvStore).filter(value => AccountEntity.isAccountEntity(value));
|
|
2267
|
+
|
|
2268
|
+
if (accountEntities.length > 0) {
|
|
2269
|
+
const accountEntity = accountEntities[0];
|
|
2270
|
+
const partitionKey = await this.partitionManager.extractKey(accountEntity);
|
|
2271
|
+
await this.client.set(partitionKey, cacheContext.tokenCache.serialize());
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
export { ClientApplication, ClientAssertion, ConfidentialClientApplication, CryptoProvider, DistributedCachePlugin, NodeStorage, PublicClientApplication, TokenCache, buildAppConfiguration, version };
|
|
2159
2279
|
//# sourceMappingURL=msal-node.esm.js.map
|