@azure/msal-node 1.5.0 → 1.8.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.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 +10 -2
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/crypto/CryptoProvider.d.ts +3 -1
- package/dist/crypto/CryptoProvider.d.ts.map +1 -1
- package/dist/crypto/GuidGenerator.d.ts +4 -3
- package/dist/crypto/GuidGenerator.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 +174 -65
- 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 +170 -68
- 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/utils/EncodingUtils.d.ts.map +1 -1
- package/package.json +4 -17
- package/CHANGELOG.json +0 -980
- package/CHANGELOG.md +0 -322
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,
|
|
@@ -133,7 +141,7 @@ class HttpClient {
|
|
|
133
141
|
url: url,
|
|
134
142
|
|
|
135
143
|
/* istanbul ignore next */
|
|
136
|
-
data: options && options.body ||
|
|
144
|
+
data: options && options.body || Constants$1.EMPTY_STRING,
|
|
137
145
|
timeout: cancellationToken,
|
|
138
146
|
|
|
139
147
|
/* istanbul ignore next */
|
|
@@ -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,
|
|
@@ -171,20 +186,24 @@ class NetworkUtils {
|
|
|
171
186
|
* Licensed under the MIT License.
|
|
172
187
|
*/
|
|
173
188
|
const DEFAULT_AUTH_OPTIONS = {
|
|
174
|
-
clientId:
|
|
189
|
+
clientId: Constants$1.EMPTY_STRING,
|
|
175
190
|
authority: Constants$1.DEFAULT_AUTHORITY,
|
|
176
|
-
clientSecret:
|
|
177
|
-
clientAssertion:
|
|
191
|
+
clientSecret: Constants$1.EMPTY_STRING,
|
|
192
|
+
clientAssertion: Constants$1.EMPTY_STRING,
|
|
178
193
|
clientCertificate: {
|
|
179
|
-
thumbprint:
|
|
180
|
-
privateKey:
|
|
181
|
-
x5c:
|
|
194
|
+
thumbprint: Constants$1.EMPTY_STRING,
|
|
195
|
+
privateKey: Constants$1.EMPTY_STRING,
|
|
196
|
+
x5c: Constants$1.EMPTY_STRING
|
|
182
197
|
},
|
|
183
198
|
knownAuthorities: [],
|
|
184
|
-
cloudDiscoveryMetadata:
|
|
185
|
-
authorityMetadata:
|
|
199
|
+
cloudDiscoveryMetadata: Constants$1.EMPTY_STRING,
|
|
200
|
+
authorityMetadata: Constants$1.EMPTY_STRING,
|
|
186
201
|
clientCapabilities: [],
|
|
187
|
-
protocolMode: ProtocolMode.AAD
|
|
202
|
+
protocolMode: ProtocolMode.AAD,
|
|
203
|
+
azureCloudOptions: {
|
|
204
|
+
azureCloudInstance: AzureCloudInstance.None,
|
|
205
|
+
tenant: Constants$1.EMPTY_STRING
|
|
206
|
+
}
|
|
188
207
|
};
|
|
189
208
|
const DEFAULT_CACHE_OPTIONS = {};
|
|
190
209
|
const DEFAULT_LOGGER_OPTIONS = {
|
|
@@ -195,7 +214,14 @@ 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: Constants$1.EMPTY_STRING
|
|
219
|
+
};
|
|
220
|
+
const DEFAULT_TELEMETRY_OPTIONS = {
|
|
221
|
+
application: {
|
|
222
|
+
appName: Constants$1.EMPTY_STRING,
|
|
223
|
+
appVersion: Constants$1.EMPTY_STRING
|
|
224
|
+
}
|
|
199
225
|
};
|
|
200
226
|
/**
|
|
201
227
|
* Sets the default options when not explicitly configured from app developer
|
|
@@ -203,6 +229,7 @@ const DEFAULT_SYSTEM_OPTIONS = {
|
|
|
203
229
|
* @param auth - Authentication options
|
|
204
230
|
* @param cache - Cache options
|
|
205
231
|
* @param system - System options
|
|
232
|
+
* @param telemetry - Telemetry options
|
|
206
233
|
*
|
|
207
234
|
* @returns Configuration
|
|
208
235
|
* @public
|
|
@@ -211,7 +238,8 @@ const DEFAULT_SYSTEM_OPTIONS = {
|
|
|
211
238
|
function buildAppConfiguration({
|
|
212
239
|
auth,
|
|
213
240
|
cache,
|
|
214
|
-
system
|
|
241
|
+
system,
|
|
242
|
+
telemetry
|
|
215
243
|
}) {
|
|
216
244
|
return {
|
|
217
245
|
auth: { ...DEFAULT_AUTH_OPTIONS,
|
|
@@ -222,6 +250,9 @@ function buildAppConfiguration({
|
|
|
222
250
|
},
|
|
223
251
|
system: { ...DEFAULT_SYSTEM_OPTIONS,
|
|
224
252
|
...system
|
|
253
|
+
},
|
|
254
|
+
telemetry: { ...DEFAULT_TELEMETRY_OPTIONS,
|
|
255
|
+
...telemetry
|
|
225
256
|
}
|
|
226
257
|
};
|
|
227
258
|
}
|
|
@@ -236,7 +267,7 @@ class GuidGenerator {
|
|
|
236
267
|
* RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or pseudo-random numbers.
|
|
237
268
|
* uuidv4 generates guids from cryprtographically-string random
|
|
238
269
|
*/
|
|
239
|
-
|
|
270
|
+
generateGuid() {
|
|
240
271
|
return v4();
|
|
241
272
|
}
|
|
242
273
|
/**
|
|
@@ -245,7 +276,7 @@ class GuidGenerator {
|
|
|
245
276
|
*/
|
|
246
277
|
|
|
247
278
|
|
|
248
|
-
|
|
279
|
+
isGuid(guid) {
|
|
249
280
|
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;
|
|
250
281
|
return regexGuid.test(guid);
|
|
251
282
|
}
|
|
@@ -273,7 +304,7 @@ class EncodingUtils {
|
|
|
273
304
|
|
|
274
305
|
|
|
275
306
|
static base64EncodeUrl(str, encoding) {
|
|
276
|
-
return EncodingUtils.base64Encode(str, encoding).replace(/=/g,
|
|
307
|
+
return EncodingUtils.base64Encode(str, encoding).replace(/=/g, Constants$1.EMPTY_STRING).replace(/\+/g, "-").replace(/\//g, "_");
|
|
277
308
|
}
|
|
278
309
|
/**
|
|
279
310
|
* 'utf8': Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
|
|
@@ -303,6 +334,21 @@ class EncodingUtils {
|
|
|
303
334
|
|
|
304
335
|
}
|
|
305
336
|
|
|
337
|
+
/*
|
|
338
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
339
|
+
* Licensed under the MIT License.
|
|
340
|
+
*/
|
|
341
|
+
class HashUtils {
|
|
342
|
+
/**
|
|
343
|
+
* generate 'SHA256' hash
|
|
344
|
+
* @param buffer
|
|
345
|
+
*/
|
|
346
|
+
sha256(buffer) {
|
|
347
|
+
return crypto.createHash(Hash.SHA256).update(buffer).digest();
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
}
|
|
351
|
+
|
|
306
352
|
/*
|
|
307
353
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
308
354
|
* Licensed under the MIT License.
|
|
@@ -312,10 +358,15 @@ class EncodingUtils {
|
|
|
312
358
|
*/
|
|
313
359
|
|
|
314
360
|
class PkceGenerator {
|
|
361
|
+
constructor() {
|
|
362
|
+
this.hashUtils = new HashUtils();
|
|
363
|
+
}
|
|
315
364
|
/**
|
|
316
365
|
* generates the codeVerfier and the challenge from the codeVerfier
|
|
317
366
|
* reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
|
|
318
367
|
*/
|
|
368
|
+
|
|
369
|
+
|
|
319
370
|
async generatePkceCodes() {
|
|
320
371
|
const verifier = this.generateCodeVerifier();
|
|
321
372
|
const challenge = this.generateCodeChallengeFromVerifier(verifier);
|
|
@@ -348,7 +399,7 @@ class PkceGenerator {
|
|
|
348
399
|
charArr.push(CharSet.CV_CHARSET[index]);
|
|
349
400
|
}
|
|
350
401
|
|
|
351
|
-
const verifier = charArr.join(
|
|
402
|
+
const verifier = charArr.join(Constants$1.EMPTY_STRING);
|
|
352
403
|
return EncodingUtils.base64EncodeUrl(verifier);
|
|
353
404
|
}
|
|
354
405
|
/**
|
|
@@ -358,16 +409,7 @@ class PkceGenerator {
|
|
|
358
409
|
|
|
359
410
|
|
|
360
411
|
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();
|
|
412
|
+
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString("base64"), "base64");
|
|
371
413
|
}
|
|
372
414
|
|
|
373
415
|
}
|
|
@@ -386,6 +428,8 @@ class CryptoProvider {
|
|
|
386
428
|
constructor() {
|
|
387
429
|
// Browser crypto needs to be validated first before any other classes can be set.
|
|
388
430
|
this.pkceGenerator = new PkceGenerator();
|
|
431
|
+
this.guidGenerator = new GuidGenerator();
|
|
432
|
+
this.hashUtils = new HashUtils();
|
|
389
433
|
}
|
|
390
434
|
/**
|
|
391
435
|
* Creates a new random GUID - used to populate state and nonce.
|
|
@@ -394,7 +438,7 @@ class CryptoProvider {
|
|
|
394
438
|
|
|
395
439
|
|
|
396
440
|
createNewGuid() {
|
|
397
|
-
return
|
|
441
|
+
return this.guidGenerator.generateGuid();
|
|
398
442
|
}
|
|
399
443
|
/**
|
|
400
444
|
* Encodes input string to base64.
|
|
@@ -460,8 +504,8 @@ class CryptoProvider {
|
|
|
460
504
|
*/
|
|
461
505
|
|
|
462
506
|
|
|
463
|
-
hashString() {
|
|
464
|
-
|
|
507
|
+
async hashString(plainText) {
|
|
508
|
+
return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(plainText).toString("base64"), "base64");
|
|
465
509
|
}
|
|
466
510
|
|
|
467
511
|
}
|
|
@@ -568,7 +612,9 @@ class Deserializer {
|
|
|
568
612
|
extendedExpiresOn: serializedAT.extended_expires_on,
|
|
569
613
|
refreshOn: serializedAT.refresh_on,
|
|
570
614
|
keyId: serializedAT.key_id,
|
|
571
|
-
tokenType: serializedAT.token_type
|
|
615
|
+
tokenType: serializedAT.token_type,
|
|
616
|
+
requestedClaims: serializedAT.requestedClaims,
|
|
617
|
+
requestedClaimsHash: serializedAT.requestedClaimsHash
|
|
572
618
|
};
|
|
573
619
|
const accessToken = new AccessTokenEntity();
|
|
574
620
|
CacheManager.toObject(accessToken, mappedAT);
|
|
@@ -732,7 +778,9 @@ class Serializer {
|
|
|
732
778
|
extended_expires_on: atEntity.extendedExpiresOn,
|
|
733
779
|
refresh_on: atEntity.refreshOn,
|
|
734
780
|
key_id: atEntity.keyId,
|
|
735
|
-
token_type: atEntity.tokenType
|
|
781
|
+
token_type: atEntity.tokenType,
|
|
782
|
+
requestedClaims: atEntity.requestedClaims,
|
|
783
|
+
requestedClaimsHash: atEntity.requestedClaimsHash
|
|
736
784
|
};
|
|
737
785
|
});
|
|
738
786
|
return accessTokens;
|
|
@@ -871,12 +919,14 @@ class NodeStorage extends CacheManager {
|
|
|
871
919
|
inMemoryCacheToCache(inMemoryCache) {
|
|
872
920
|
// convert in memory cache to a flat Key-Value map
|
|
873
921
|
let cache = this.getCache();
|
|
874
|
-
cache = { ...
|
|
922
|
+
cache = { ...cache,
|
|
923
|
+
...inMemoryCache.accounts,
|
|
875
924
|
...inMemoryCache.idTokens,
|
|
876
925
|
...inMemoryCache.accessTokens,
|
|
877
926
|
...inMemoryCache.refreshTokens,
|
|
878
927
|
...inMemoryCache.appMetadata
|
|
879
|
-
};
|
|
928
|
+
}; // convert in memory cache to a flat Key-Value map
|
|
929
|
+
|
|
880
930
|
return cache;
|
|
881
931
|
}
|
|
882
932
|
/**
|
|
@@ -1548,7 +1598,7 @@ class TokenCache {
|
|
|
1548
1598
|
|
|
1549
1599
|
/* eslint-disable header/header */
|
|
1550
1600
|
const name = "@azure/msal-node";
|
|
1551
|
-
const version = "1.
|
|
1601
|
+
const version = "1.8.0";
|
|
1552
1602
|
|
|
1553
1603
|
/*
|
|
1554
1604
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1584,11 +1634,11 @@ class ClientApplication {
|
|
|
1584
1634
|
async getAuthCodeUrl(request) {
|
|
1585
1635
|
this.logger.info("getAuthCodeUrl called", request.correlationId);
|
|
1586
1636
|
const validRequest = { ...request,
|
|
1587
|
-
...this.initializeBaseRequest(request),
|
|
1637
|
+
...(await this.initializeBaseRequest(request)),
|
|
1588
1638
|
responseMode: request.responseMode || ResponseMode.QUERY,
|
|
1589
1639
|
authenticationScheme: AuthenticationScheme.BEARER
|
|
1590
1640
|
};
|
|
1591
|
-
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId);
|
|
1641
|
+
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
|
|
1592
1642
|
const authorizationCodeClient = new AuthorizationCodeClient(authClientConfig);
|
|
1593
1643
|
this.logger.verbose("Auth code client created", validRequest.correlationId);
|
|
1594
1644
|
return authorizationCodeClient.getAuthCodeUrl(validRequest);
|
|
@@ -1603,19 +1653,19 @@ class ClientApplication {
|
|
|
1603
1653
|
*/
|
|
1604
1654
|
|
|
1605
1655
|
|
|
1606
|
-
async acquireTokenByCode(request) {
|
|
1656
|
+
async acquireTokenByCode(request, authCodePayLoad) {
|
|
1607
1657
|
this.logger.info("acquireTokenByCode called", request.correlationId);
|
|
1608
1658
|
const validRequest = { ...request,
|
|
1609
|
-
...this.initializeBaseRequest(request),
|
|
1659
|
+
...(await this.initializeBaseRequest(request)),
|
|
1610
1660
|
authenticationScheme: AuthenticationScheme.BEARER
|
|
1611
1661
|
};
|
|
1612
1662
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByCode, validRequest.correlationId);
|
|
1613
1663
|
|
|
1614
1664
|
try {
|
|
1615
|
-
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1665
|
+
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1616
1666
|
const authorizationCodeClient = new AuthorizationCodeClient(authClientConfig);
|
|
1617
1667
|
this.logger.verbose("Auth code client created", validRequest.correlationId);
|
|
1618
|
-
return authorizationCodeClient.acquireToken(validRequest);
|
|
1668
|
+
return authorizationCodeClient.acquireToken(validRequest, authCodePayLoad);
|
|
1619
1669
|
} catch (e) {
|
|
1620
1670
|
if (e instanceof AuthError) {
|
|
1621
1671
|
e.setCorrelationId(validRequest.correlationId);
|
|
@@ -1637,13 +1687,13 @@ class ClientApplication {
|
|
|
1637
1687
|
async acquireTokenByRefreshToken(request) {
|
|
1638
1688
|
this.logger.info("acquireTokenByRefreshToken called", request.correlationId);
|
|
1639
1689
|
const validRequest = { ...request,
|
|
1640
|
-
...this.initializeBaseRequest(request),
|
|
1690
|
+
...(await this.initializeBaseRequest(request)),
|
|
1641
1691
|
authenticationScheme: AuthenticationScheme.BEARER
|
|
1642
1692
|
};
|
|
1643
1693
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByRefreshToken, validRequest.correlationId);
|
|
1644
1694
|
|
|
1645
1695
|
try {
|
|
1646
|
-
const refreshTokenClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1696
|
+
const refreshTokenClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1647
1697
|
const refreshTokenClient = new RefreshTokenClient(refreshTokenClientConfig);
|
|
1648
1698
|
this.logger.verbose("Refresh token client created", validRequest.correlationId);
|
|
1649
1699
|
return refreshTokenClient.acquireToken(validRequest);
|
|
@@ -1668,13 +1718,13 @@ class ClientApplication {
|
|
|
1668
1718
|
|
|
1669
1719
|
async acquireTokenSilent(request) {
|
|
1670
1720
|
const validRequest = { ...request,
|
|
1671
|
-
...this.initializeBaseRequest(request),
|
|
1721
|
+
...(await this.initializeBaseRequest(request)),
|
|
1672
1722
|
forceRefresh: request.forceRefresh || false
|
|
1673
1723
|
};
|
|
1674
1724
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent, validRequest.correlationId, validRequest.forceRefresh);
|
|
1675
1725
|
|
|
1676
1726
|
try {
|
|
1677
|
-
const silentFlowClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1727
|
+
const silentFlowClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1678
1728
|
const silentFlowClient = new SilentFlowClient(silentFlowClientConfig);
|
|
1679
1729
|
this.logger.verbose("Silent flow client created", validRequest.correlationId);
|
|
1680
1730
|
return silentFlowClient.acquireToken(validRequest);
|
|
@@ -1702,12 +1752,12 @@ class ClientApplication {
|
|
|
1702
1752
|
async acquireTokenByUsernamePassword(request) {
|
|
1703
1753
|
this.logger.info("acquireTokenByUsernamePassword called", request.correlationId);
|
|
1704
1754
|
const validRequest = { ...request,
|
|
1705
|
-
...this.initializeBaseRequest(request)
|
|
1755
|
+
...(await this.initializeBaseRequest(request))
|
|
1706
1756
|
};
|
|
1707
1757
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByUsernamePassword, validRequest.correlationId);
|
|
1708
1758
|
|
|
1709
1759
|
try {
|
|
1710
|
-
const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1760
|
+
const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1711
1761
|
const usernamePasswordClient = new UsernamePasswordClient(usernamePasswordClientConfig);
|
|
1712
1762
|
this.logger.verbose("Username password client created", validRequest.correlationId);
|
|
1713
1763
|
return usernamePasswordClient.acquireToken(validRequest);
|
|
@@ -1753,11 +1803,13 @@ class ClientApplication {
|
|
|
1753
1803
|
*/
|
|
1754
1804
|
|
|
1755
1805
|
|
|
1756
|
-
async buildOauthClientConfiguration(authority, requestCorrelationId, serverTelemetryManager, azureRegionConfiguration) {
|
|
1757
|
-
this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId); //
|
|
1806
|
+
async buildOauthClientConfiguration(authority, requestCorrelationId, serverTelemetryManager, azureRegionConfiguration, azureCloudOptions) {
|
|
1807
|
+
this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId); // precedence - azureCloudInstance + tenant >> authority and request >> config
|
|
1808
|
+
|
|
1809
|
+
const userAzureCloudOptions = azureCloudOptions ? azureCloudOptions : this.config.auth.azureCloudOptions; // using null assertion operator as we ensure that all config values have default values in buildConfiguration()
|
|
1758
1810
|
|
|
1759
1811
|
this.logger.verbose(`building oauth client configuration with the authority: ${authority}`, requestCorrelationId);
|
|
1760
|
-
const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId);
|
|
1812
|
+
const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId, userAzureCloudOptions);
|
|
1761
1813
|
serverTelemetryManager == null ? void 0 : serverTelemetryManager.updateRegionDiscoveryMetadata(discoveredAuthority.regionDiscoveryMetadata);
|
|
1762
1814
|
return {
|
|
1763
1815
|
authOptions: {
|
|
@@ -1765,6 +1817,9 @@ class ClientApplication {
|
|
|
1765
1817
|
authority: discoveredAuthority,
|
|
1766
1818
|
clientCapabilities: this.config.auth.clientCapabilities
|
|
1767
1819
|
},
|
|
1820
|
+
systemOptions: {
|
|
1821
|
+
proxyUrl: this.config.system.proxyUrl
|
|
1822
|
+
},
|
|
1768
1823
|
loggerOptions: {
|
|
1769
1824
|
logLevel: this.config.system.loggerOptions.logLevel,
|
|
1770
1825
|
loggerCallback: this.config.system.loggerOptions.loggerCallback,
|
|
@@ -1782,9 +1837,10 @@ class ClientApplication {
|
|
|
1782
1837
|
libraryInfo: {
|
|
1783
1838
|
sku: Constants.MSAL_SKU,
|
|
1784
1839
|
version: version,
|
|
1785
|
-
cpu: process.arch ||
|
|
1786
|
-
os: process.platform ||
|
|
1840
|
+
cpu: process.arch || Constants$1.EMPTY_STRING,
|
|
1841
|
+
os: process.platform || Constants$1.EMPTY_STRING
|
|
1787
1842
|
},
|
|
1843
|
+
telemetry: this.config.telemetry,
|
|
1788
1844
|
persistencePlugin: this.config.cache.cachePlugin,
|
|
1789
1845
|
serializableCache: this.tokenCache
|
|
1790
1846
|
};
|
|
@@ -1802,14 +1858,19 @@ class ClientApplication {
|
|
|
1802
1858
|
*/
|
|
1803
1859
|
|
|
1804
1860
|
|
|
1805
|
-
initializeBaseRequest(authRequest) {
|
|
1861
|
+
async initializeBaseRequest(authRequest) {
|
|
1806
1862
|
this.logger.verbose("initializeRequestScopes called", authRequest.correlationId); // Default authenticationScheme to Bearer, log that POP isn't supported yet
|
|
1807
1863
|
|
|
1808
1864
|
if (authRequest.authenticationScheme && authRequest.authenticationScheme === AuthenticationScheme.POP) {
|
|
1809
1865
|
this.logger.verbose("Authentication Scheme 'pop' is not supported yet, setting Authentication Scheme to 'Bearer' for request", authRequest.correlationId);
|
|
1810
1866
|
}
|
|
1811
1867
|
|
|
1812
|
-
authRequest.authenticationScheme = AuthenticationScheme.BEARER;
|
|
1868
|
+
authRequest.authenticationScheme = AuthenticationScheme.BEARER; // Set requested claims hash if claims were requested
|
|
1869
|
+
|
|
1870
|
+
if (authRequest.claims && !StringUtils.isEmpty(authRequest.claims)) {
|
|
1871
|
+
authRequest.requestedClaimsHash = await this.cryptoProvider.hashString(authRequest.claims);
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1813
1874
|
return { ...authRequest,
|
|
1814
1875
|
scopes: [...(authRequest && authRequest.scopes || []), ...OIDC_DEFAULT_SCOPES],
|
|
1815
1876
|
correlationId: authRequest && authRequest.correlationId || this.cryptoProvider.createNewGuid(),
|
|
@@ -1840,8 +1901,10 @@ class ClientApplication {
|
|
|
1840
1901
|
*/
|
|
1841
1902
|
|
|
1842
1903
|
|
|
1843
|
-
async createAuthority(authorityString, azureRegionConfiguration, requestCorrelationId) {
|
|
1844
|
-
this.logger.verbose("createAuthority called", requestCorrelationId);
|
|
1904
|
+
async createAuthority(authorityString, azureRegionConfiguration, requestCorrelationId, azureCloudOptions) {
|
|
1905
|
+
this.logger.verbose("createAuthority called", requestCorrelationId); // build authority string based on auth params - azureCloudInstance is prioritized if provided
|
|
1906
|
+
|
|
1907
|
+
const authorityUrl = Authority.generateAuthority(authorityString, azureCloudOptions);
|
|
1845
1908
|
const authorityOptions = {
|
|
1846
1909
|
protocolMode: this.config.auth.protocolMode,
|
|
1847
1910
|
knownAuthorities: this.config.auth.knownAuthorities,
|
|
@@ -1849,7 +1912,15 @@ class ClientApplication {
|
|
|
1849
1912
|
authorityMetadata: this.config.auth.authorityMetadata,
|
|
1850
1913
|
azureRegionConfiguration
|
|
1851
1914
|
};
|
|
1852
|
-
return await AuthorityFactory.createDiscoveredInstance(
|
|
1915
|
+
return await AuthorityFactory.createDiscoveredInstance(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions);
|
|
1916
|
+
}
|
|
1917
|
+
/**
|
|
1918
|
+
* Clear the cache
|
|
1919
|
+
*/
|
|
1920
|
+
|
|
1921
|
+
|
|
1922
|
+
clearCache() {
|
|
1923
|
+
this.storage.clear();
|
|
1853
1924
|
}
|
|
1854
1925
|
|
|
1855
1926
|
}
|
|
@@ -1898,11 +1969,11 @@ class PublicClientApplication extends ClientApplication {
|
|
|
1898
1969
|
|
|
1899
1970
|
async acquireTokenByDeviceCode(request) {
|
|
1900
1971
|
this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
|
|
1901
|
-
const validRequest = Object.assign(request, this.initializeBaseRequest(request));
|
|
1972
|
+
const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
|
|
1902
1973
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
|
|
1903
1974
|
|
|
1904
1975
|
try {
|
|
1905
|
-
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1976
|
+
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1906
1977
|
const deviceCodeClient = new DeviceCodeClient(deviceCodeConfig);
|
|
1907
1978
|
this.logger.verbose("Device code client created", validRequest.correlationId);
|
|
1908
1979
|
return deviceCodeClient.acquireToken(validRequest);
|
|
@@ -2047,7 +2118,7 @@ class ClientAssertion {
|
|
|
2047
2118
|
|
|
2048
2119
|
while ((matches = regexToFindCerts.exec(publicCertificate)) !== null) {
|
|
2049
2120
|
// matches[1] represents the first parens capture group in the regex.
|
|
2050
|
-
certs.push(matches[1].replace(/\n/,
|
|
2121
|
+
certs.push(matches[1].replace(/\n/, Constants$1.EMPTY_STRING));
|
|
2051
2122
|
}
|
|
2052
2123
|
|
|
2053
2124
|
return certs;
|
|
@@ -2097,7 +2168,7 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2097
2168
|
async acquireTokenByClientCredential(request) {
|
|
2098
2169
|
this.logger.info("acquireTokenByClientCredential called", request.correlationId);
|
|
2099
2170
|
const validRequest = { ...request,
|
|
2100
|
-
...this.initializeBaseRequest(request)
|
|
2171
|
+
...(await this.initializeBaseRequest(request))
|
|
2101
2172
|
};
|
|
2102
2173
|
const azureRegionConfiguration = {
|
|
2103
2174
|
azureRegion: validRequest.azureRegion,
|
|
@@ -2106,7 +2177,7 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2106
2177
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByClientCredential, validRequest.correlationId, validRequest.skipCache);
|
|
2107
2178
|
|
|
2108
2179
|
try {
|
|
2109
|
-
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration);
|
|
2180
|
+
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration, request.azureCloudOptions);
|
|
2110
2181
|
const clientCredentialClient = new ClientCredentialClient(clientCredentialConfig);
|
|
2111
2182
|
this.logger.verbose("Client credential client created", validRequest.correlationId);
|
|
2112
2183
|
return clientCredentialClient.acquireToken(validRequest);
|
|
@@ -2135,11 +2206,11 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2135
2206
|
async acquireTokenOnBehalfOf(request) {
|
|
2136
2207
|
this.logger.info("acquireTokenOnBehalfOf called", request.correlationId);
|
|
2137
2208
|
const validRequest = { ...request,
|
|
2138
|
-
...this.initializeBaseRequest(request)
|
|
2209
|
+
...(await this.initializeBaseRequest(request))
|
|
2139
2210
|
};
|
|
2140
2211
|
|
|
2141
2212
|
try {
|
|
2142
|
-
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId);
|
|
2213
|
+
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
|
|
2143
2214
|
const oboClient = new OnBehalfOfClient(clientCredentialConfig);
|
|
2144
2215
|
this.logger.verbose("On behalf of client created", validRequest.correlationId);
|
|
2145
2216
|
return oboClient.acquireToken(validRequest);
|
|
@@ -2156,8 +2227,8 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2156
2227
|
const clientSecretNotEmpty = !StringUtils.isEmpty(configuration.auth.clientSecret);
|
|
2157
2228
|
const clientAssertionNotEmpty = !StringUtils.isEmpty(configuration.auth.clientAssertion);
|
|
2158
2229
|
const certificate = configuration.auth.clientCertificate || {
|
|
2159
|
-
thumbprint:
|
|
2160
|
-
privateKey:
|
|
2230
|
+
thumbprint: Constants$1.EMPTY_STRING,
|
|
2231
|
+
privateKey: Constants$1.EMPTY_STRING
|
|
2161
2232
|
};
|
|
2162
2233
|
const certificateNotEmpty = !StringUtils.isEmpty(certificate.thumbprint) || !StringUtils.isEmpty(certificate.privateKey); // Check that at most one credential is set on the application
|
|
2163
2234
|
|
|
@@ -2186,5 +2257,36 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2186
2257
|
|
|
2187
2258
|
}
|
|
2188
2259
|
|
|
2189
|
-
|
|
2260
|
+
/*
|
|
2261
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2262
|
+
* Licensed under the MIT License.
|
|
2263
|
+
*/
|
|
2264
|
+
class DistributedCachePlugin {
|
|
2265
|
+
constructor(client, partitionManager) {
|
|
2266
|
+
this.client = client;
|
|
2267
|
+
this.partitionManager = partitionManager;
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
async beforeCacheAccess(cacheContext) {
|
|
2271
|
+
const partitionKey = await this.partitionManager.getKey();
|
|
2272
|
+
const cacheData = await this.client.get(partitionKey);
|
|
2273
|
+
cacheContext.tokenCache.deserialize(cacheData);
|
|
2274
|
+
}
|
|
2275
|
+
|
|
2276
|
+
async afterCacheAccess(cacheContext) {
|
|
2277
|
+
if (cacheContext.cacheHasChanged) {
|
|
2278
|
+
const kvStore = cacheContext.tokenCache.getKVStore();
|
|
2279
|
+
const accountEntities = Object.values(kvStore).filter(value => AccountEntity.isAccountEntity(value));
|
|
2280
|
+
|
|
2281
|
+
if (accountEntities.length > 0) {
|
|
2282
|
+
const accountEntity = accountEntities[0];
|
|
2283
|
+
const partitionKey = await this.partitionManager.extractKey(accountEntity);
|
|
2284
|
+
await this.client.set(partitionKey, cacheContext.tokenCache.serialize());
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
export { ClientApplication, ClientAssertion, ConfidentialClientApplication, CryptoProvider, DistributedCachePlugin, NodeStorage, PublicClientApplication, TokenCache, buildAppConfiguration, version };
|
|
2190
2292
|
//# sourceMappingURL=msal-node.esm.js.map
|