@azure/msal-node 1.2.0 → 1.3.3
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/CHANGELOG.json +150 -0
- package/{changelog.md → CHANGELOG.md} +42 -1
- package/README.md +11 -11
- package/dist/cache/NodeStorage.d.ts +1 -1
- package/dist/cache/NodeStorage.d.ts.map +1 -1
- package/dist/client/ClientApplication.d.ts +14 -2
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
- package/dist/client/IConfidentialClientApplication.d.ts +3 -0
- package/dist/client/IConfidentialClientApplication.d.ts.map +1 -1
- package/dist/client/PublicClientApplication.d.ts +0 -12
- package/dist/client/PublicClientApplication.d.ts.map +1 -1
- package/dist/config/Configuration.d.ts +6 -1
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/crypto/CryptoProvider.d.ts +9 -0
- package/dist/crypto/CryptoProvider.d.ts.map +1 -1
- package/dist/crypto/PkceGenerator.d.ts +0 -5
- package/dist/crypto/PkceGenerator.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/msal-node.cjs.development.js +128 -56
- 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 +124 -59
- 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/AuthorizationUrlRequest.d.ts +1 -0
- package/dist/request/AuthorizationUrlRequest.d.ts.map +1 -1
- package/package.json +8 -3
|
@@ -111,7 +111,11 @@ class HttpClient {
|
|
|
111
111
|
const request = {
|
|
112
112
|
method: HttpMethod.GET,
|
|
113
113
|
url: url,
|
|
114
|
+
|
|
115
|
+
/* istanbul ignore next */
|
|
114
116
|
headers: options && options.headers,
|
|
117
|
+
|
|
118
|
+
/* istanbul ignore next */
|
|
115
119
|
validateStatus: () => true
|
|
116
120
|
};
|
|
117
121
|
const response = await axios(request);
|
|
@@ -132,9 +136,15 @@ class HttpClient {
|
|
|
132
136
|
const request = {
|
|
133
137
|
method: HttpMethod.POST,
|
|
134
138
|
url: url,
|
|
139
|
+
|
|
140
|
+
/* istanbul ignore next */
|
|
135
141
|
data: options && options.body || "",
|
|
136
142
|
timeout: cancellationToken,
|
|
143
|
+
|
|
144
|
+
/* istanbul ignore next */
|
|
137
145
|
headers: options && options.headers,
|
|
146
|
+
|
|
147
|
+
/* istanbul ignore next */
|
|
138
148
|
validateStatus: () => true
|
|
139
149
|
};
|
|
140
150
|
const response = await axios(request);
|
|
@@ -325,8 +335,25 @@ class PkceGenerator {
|
|
|
325
335
|
|
|
326
336
|
|
|
327
337
|
generateCodeVerifier() {
|
|
328
|
-
const
|
|
329
|
-
const
|
|
338
|
+
const charArr = [];
|
|
339
|
+
const maxNumber = 256 - 256 % CharSet.CV_CHARSET.length;
|
|
340
|
+
|
|
341
|
+
while (charArr.length <= RANDOM_OCTET_SIZE) {
|
|
342
|
+
const byte = crypto.randomBytes(1)[0];
|
|
343
|
+
|
|
344
|
+
if (byte >= maxNumber) {
|
|
345
|
+
/*
|
|
346
|
+
* Ignore this number to maintain randomness.
|
|
347
|
+
* Including it would result in an unequal distribution of characters after doing the modulo
|
|
348
|
+
*/
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const index = byte % CharSet.CV_CHARSET.length;
|
|
353
|
+
charArr.push(CharSet.CV_CHARSET[index]);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const verifier = charArr.join("");
|
|
330
357
|
return EncodingUtils.base64EncodeUrl(verifier);
|
|
331
358
|
}
|
|
332
359
|
/**
|
|
@@ -347,22 +374,6 @@ class PkceGenerator {
|
|
|
347
374
|
sha256(buffer) {
|
|
348
375
|
return crypto.createHash(Hash.SHA256).update(buffer).digest();
|
|
349
376
|
}
|
|
350
|
-
/**
|
|
351
|
-
* Accepted characters; reference: https://tools.ietf.org/html/rfc7636#section-4.1
|
|
352
|
-
* @param buffer
|
|
353
|
-
*/
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
bufferToCVString(buffer) {
|
|
357
|
-
const charArr = [];
|
|
358
|
-
|
|
359
|
-
for (let i = 0; i < buffer.byteLength; i += 1) {
|
|
360
|
-
const index = buffer[i] % CharSet.CV_CHARSET.length;
|
|
361
|
-
charArr.push(CharSet.CV_CHARSET[index]);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
return charArr.join("");
|
|
365
|
-
}
|
|
366
377
|
|
|
367
378
|
}
|
|
368
379
|
|
|
@@ -424,6 +435,23 @@ class CryptoProvider {
|
|
|
424
435
|
getPublicKeyThumbprint() {
|
|
425
436
|
throw new Error("Method not implemented.");
|
|
426
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* Removes cryptographic keypair from key store matching the keyId passed in
|
|
440
|
+
* @param kid
|
|
441
|
+
*/
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
removeTokenBindingKey() {
|
|
445
|
+
throw new Error("Method not implemented.");
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Removes all cryptographic keys from Keystore
|
|
449
|
+
*/
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
clearKeystore() {
|
|
453
|
+
throw new Error("Method not implemented.");
|
|
454
|
+
}
|
|
427
455
|
/**
|
|
428
456
|
* Signs the given object as a jwt payload with private key retrieved by given kid - currently not implemented for node
|
|
429
457
|
*/
|
|
@@ -1181,7 +1209,7 @@ class NodeStorage extends msalCommon.CacheManager {
|
|
|
1181
1209
|
*/
|
|
1182
1210
|
|
|
1183
1211
|
|
|
1184
|
-
clear() {
|
|
1212
|
+
async clear() {
|
|
1185
1213
|
this.logger.trace("Clearing cache entries created by MSAL"); // read inMemoryCache
|
|
1186
1214
|
|
|
1187
1215
|
const cacheKeys = this.getKeys(); // delete each element
|
|
@@ -1365,7 +1393,7 @@ class TokenCache {
|
|
|
1365
1393
|
await this.persistence.beforeCacheAccess(cacheContext);
|
|
1366
1394
|
}
|
|
1367
1395
|
|
|
1368
|
-
this.storage.removeAccount(msalCommon.AccountEntity.generateAccountCacheKey(account));
|
|
1396
|
+
await this.storage.removeAccount(msalCommon.AccountEntity.generateAccountCacheKey(account));
|
|
1369
1397
|
} finally {
|
|
1370
1398
|
if (this.persistence && cacheContext) {
|
|
1371
1399
|
await this.persistence.afterCacheAccess(cacheContext);
|
|
@@ -1494,7 +1522,7 @@ class TokenCache {
|
|
|
1494
1522
|
|
|
1495
1523
|
/* eslint-disable header/header */
|
|
1496
1524
|
const name = "@azure/msal-node";
|
|
1497
|
-
const version = "1.
|
|
1525
|
+
const version = "1.3.3";
|
|
1498
1526
|
|
|
1499
1527
|
/*
|
|
1500
1528
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1563,6 +1591,10 @@ class ClientApplication {
|
|
|
1563
1591
|
this.logger.verbose("Auth code client created", validRequest.correlationId);
|
|
1564
1592
|
return authorizationCodeClient.acquireToken(validRequest);
|
|
1565
1593
|
} catch (e) {
|
|
1594
|
+
if (e instanceof msalCommon.AuthError) {
|
|
1595
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1566
1598
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
1567
1599
|
throw e;
|
|
1568
1600
|
}
|
|
@@ -1590,6 +1622,10 @@ class ClientApplication {
|
|
|
1590
1622
|
this.logger.verbose("Refresh token client created", validRequest.correlationId);
|
|
1591
1623
|
return refreshTokenClient.acquireToken(validRequest);
|
|
1592
1624
|
} catch (e) {
|
|
1625
|
+
if (e instanceof msalCommon.AuthError) {
|
|
1626
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1593
1629
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
1594
1630
|
throw e;
|
|
1595
1631
|
}
|
|
@@ -1617,6 +1653,43 @@ class ClientApplication {
|
|
|
1617
1653
|
this.logger.verbose("Silent flow client created", validRequest.correlationId);
|
|
1618
1654
|
return silentFlowClient.acquireToken(validRequest);
|
|
1619
1655
|
} catch (e) {
|
|
1656
|
+
if (e instanceof msalCommon.AuthError) {
|
|
1657
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
serverTelemetryManager.cacheFailedRequest(e);
|
|
1661
|
+
throw e;
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
/**
|
|
1665
|
+
* Acquires tokens with password grant by exchanging client applications username and password for credentials
|
|
1666
|
+
*
|
|
1667
|
+
* The latest OAuth 2.0 Security Best Current Practice disallows the password grant entirely.
|
|
1668
|
+
* More details on this recommendation at https://tools.ietf.org/html/draft-ietf-oauth-security-topics-13#section-3.4
|
|
1669
|
+
* Microsoft's documentation and recommendations are at:
|
|
1670
|
+
* https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#usernamepassword
|
|
1671
|
+
*
|
|
1672
|
+
* @param request - UsenamePasswordRequest
|
|
1673
|
+
*/
|
|
1674
|
+
|
|
1675
|
+
|
|
1676
|
+
async acquireTokenByUsernamePassword(request) {
|
|
1677
|
+
this.logger.info("acquireTokenByUsernamePassword called", request.correlationId);
|
|
1678
|
+
const validRequest = { ...request,
|
|
1679
|
+
...this.initializeBaseRequest(request)
|
|
1680
|
+
};
|
|
1681
|
+
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByUsernamePassword, validRequest.correlationId);
|
|
1682
|
+
|
|
1683
|
+
try {
|
|
1684
|
+
const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1685
|
+
const usernamePasswordClient = new msalCommon.UsernamePasswordClient(usernamePasswordClientConfig);
|
|
1686
|
+
this.logger.verbose("Username password client created", validRequest.correlationId);
|
|
1687
|
+
return usernamePasswordClient.acquireToken(validRequest);
|
|
1688
|
+
} catch (e) {
|
|
1689
|
+
if (e instanceof msalCommon.AuthError) {
|
|
1690
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1620
1693
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
1621
1694
|
throw e;
|
|
1622
1695
|
}
|
|
@@ -1659,6 +1732,7 @@ class ClientApplication {
|
|
|
1659
1732
|
|
|
1660
1733
|
this.logger.verbose(`building oauth client configuration with the authority: ${authority}`, requestCorrelationId);
|
|
1661
1734
|
const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId);
|
|
1735
|
+
serverTelemetryManager == null ? void 0 : serverTelemetryManager.updateRegionDiscoveryMetadata(discoveredAuthority.regionDiscoveryMetadata);
|
|
1662
1736
|
return {
|
|
1663
1737
|
authOptions: {
|
|
1664
1738
|
clientId: this.config.auth.clientId,
|
|
@@ -1807,35 +1881,10 @@ class PublicClientApplication extends ClientApplication {
|
|
|
1807
1881
|
this.logger.verbose("Device code client created", validRequest.correlationId);
|
|
1808
1882
|
return deviceCodeClient.acquireToken(validRequest);
|
|
1809
1883
|
} catch (e) {
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
}
|
|
1814
|
-
/**
|
|
1815
|
-
* Acquires tokens with password grant by exchanging client applications username and password for credentials
|
|
1816
|
-
*
|
|
1817
|
-
* The latest OAuth 2.0 Security Best Current Practice disallows the password grant entirely.
|
|
1818
|
-
* More details on this recommendation at https://tools.ietf.org/html/draft-ietf-oauth-security-topics-13#section-3.4
|
|
1819
|
-
* Microsoft's documentation and recommendations are at:
|
|
1820
|
-
* https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#usernamepassword
|
|
1821
|
-
*
|
|
1822
|
-
* @param request - UsenamePasswordRequest
|
|
1823
|
-
*/
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
async acquireTokenByUsernamePassword(request) {
|
|
1827
|
-
this.logger.info("acquireTokenByUsernamePassword called", request.correlationId);
|
|
1828
|
-
const validRequest = { ...request,
|
|
1829
|
-
...this.initializeBaseRequest(request)
|
|
1830
|
-
};
|
|
1831
|
-
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByUsernamePassword, validRequest.correlationId);
|
|
1884
|
+
if (e instanceof msalCommon.AuthError) {
|
|
1885
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
1886
|
+
}
|
|
1832
1887
|
|
|
1833
|
-
try {
|
|
1834
|
-
const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1835
|
-
const usernamePasswordClient = new msalCommon.UsernamePasswordClient(usernamePasswordClientConfig);
|
|
1836
|
-
this.logger.verbose("Username password client created", validRequest.correlationId);
|
|
1837
|
-
return usernamePasswordClient.acquireToken(validRequest);
|
|
1838
|
-
} catch (e) {
|
|
1839
1888
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
1840
1889
|
throw e;
|
|
1841
1890
|
}
|
|
@@ -2036,6 +2085,10 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2036
2085
|
this.logger.verbose("Client credential client created", validRequest.correlationId);
|
|
2037
2086
|
return clientCredentialClient.acquireToken(validRequest);
|
|
2038
2087
|
} catch (e) {
|
|
2088
|
+
if (e instanceof msalCommon.AuthError) {
|
|
2089
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2039
2092
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2040
2093
|
throw e;
|
|
2041
2094
|
}
|
|
@@ -2058,28 +2111,40 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2058
2111
|
const validRequest = { ...request,
|
|
2059
2112
|
...this.initializeBaseRequest(request)
|
|
2060
2113
|
};
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2114
|
+
|
|
2115
|
+
try {
|
|
2116
|
+
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId);
|
|
2117
|
+
const oboClient = new msalCommon.OnBehalfOfClient(clientCredentialConfig);
|
|
2118
|
+
this.logger.verbose("On behalf of client created", validRequest.correlationId);
|
|
2119
|
+
return oboClient.acquireToken(validRequest);
|
|
2120
|
+
} catch (e) {
|
|
2121
|
+
if (e instanceof msalCommon.AuthError) {
|
|
2122
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
|
+
throw e;
|
|
2126
|
+
}
|
|
2065
2127
|
}
|
|
2066
2128
|
|
|
2067
2129
|
setClientCredential(configuration) {
|
|
2068
2130
|
const clientSecretNotEmpty = !msalCommon.StringUtils.isEmpty(configuration.auth.clientSecret);
|
|
2069
2131
|
const clientAssertionNotEmpty = !msalCommon.StringUtils.isEmpty(configuration.auth.clientAssertion);
|
|
2070
|
-
const certificate = configuration.auth.clientCertificate
|
|
2132
|
+
const certificate = configuration.auth.clientCertificate || {
|
|
2133
|
+
thumbprint: "",
|
|
2134
|
+
privateKey: ""
|
|
2135
|
+
};
|
|
2071
2136
|
const certificateNotEmpty = !msalCommon.StringUtils.isEmpty(certificate.thumbprint) || !msalCommon.StringUtils.isEmpty(certificate.privateKey); // Check that at most one credential is set on the application
|
|
2072
2137
|
|
|
2073
2138
|
if (clientSecretNotEmpty && clientAssertionNotEmpty || clientAssertionNotEmpty && certificateNotEmpty || clientSecretNotEmpty && certificateNotEmpty) {
|
|
2074
2139
|
throw msalCommon.ClientAuthError.createInvalidCredentialError();
|
|
2075
2140
|
}
|
|
2076
2141
|
|
|
2077
|
-
if (
|
|
2142
|
+
if (configuration.auth.clientSecret) {
|
|
2078
2143
|
this.clientSecret = configuration.auth.clientSecret;
|
|
2079
2144
|
return;
|
|
2080
2145
|
}
|
|
2081
2146
|
|
|
2082
|
-
if (
|
|
2147
|
+
if (configuration.auth.clientAssertion) {
|
|
2083
2148
|
this.clientAssertion = ClientAssertion.fromAssertion(configuration.auth.clientAssertion);
|
|
2084
2149
|
return;
|
|
2085
2150
|
}
|
|
@@ -2137,6 +2202,12 @@ Object.defineProperty(exports, 'InteractionRequiredAuthError', {
|
|
|
2137
2202
|
return msalCommon.InteractionRequiredAuthError;
|
|
2138
2203
|
}
|
|
2139
2204
|
});
|
|
2205
|
+
Object.defineProperty(exports, 'InteractionRequiredAuthErrorMessage', {
|
|
2206
|
+
enumerable: true,
|
|
2207
|
+
get: function () {
|
|
2208
|
+
return msalCommon.InteractionRequiredAuthErrorMessage;
|
|
2209
|
+
}
|
|
2210
|
+
});
|
|
2140
2211
|
Object.defineProperty(exports, 'LogLevel', {
|
|
2141
2212
|
enumerable: true,
|
|
2142
2213
|
get: function () {
|
|
@@ -2187,4 +2258,5 @@ exports.NodeStorage = NodeStorage;
|
|
|
2187
2258
|
exports.PublicClientApplication = PublicClientApplication;
|
|
2188
2259
|
exports.TokenCache = TokenCache;
|
|
2189
2260
|
exports.buildAppConfiguration = buildAppConfiguration;
|
|
2261
|
+
exports.version = version;
|
|
2190
2262
|
//# sourceMappingURL=msal-node.cjs.development.js.map
|