@azure/msal-node 1.3.0 → 1.4.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/CHANGELOG.json +156 -0
- package/{changelog.md → CHANGELOG.md} +299 -258
- package/LICENSE +21 -21
- package/README.md +183 -182
- package/dist/cache/NodeStorage.d.ts +1 -1
- package/dist/cache/NodeStorage.d.ts.map +1 -1
- package/dist/client/ClientApplication.d.ts +2 -2
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
- 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 +103 -32
- 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 +99 -35
- 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/package.json +12 -6
|
@@ -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.4.0";
|
|
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,10 @@ 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
|
+
|
|
1620
1660
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
1621
1661
|
throw e;
|
|
1622
1662
|
}
|
|
@@ -1646,6 +1686,10 @@ class ClientApplication {
|
|
|
1646
1686
|
this.logger.verbose("Username password client created", validRequest.correlationId);
|
|
1647
1687
|
return usernamePasswordClient.acquireToken(validRequest);
|
|
1648
1688
|
} catch (e) {
|
|
1689
|
+
if (e instanceof msalCommon.AuthError) {
|
|
1690
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1649
1693
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
1650
1694
|
throw e;
|
|
1651
1695
|
}
|
|
@@ -1837,6 +1881,10 @@ class PublicClientApplication extends ClientApplication {
|
|
|
1837
1881
|
this.logger.verbose("Device code client created", validRequest.correlationId);
|
|
1838
1882
|
return deviceCodeClient.acquireToken(validRequest);
|
|
1839
1883
|
} catch (e) {
|
|
1884
|
+
if (e instanceof msalCommon.AuthError) {
|
|
1885
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1840
1888
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
1841
1889
|
throw e;
|
|
1842
1890
|
}
|
|
@@ -1922,13 +1970,13 @@ class ClientAssertion {
|
|
|
1922
1970
|
const issuedAt = msalCommon.TimeUtils.nowSeconds();
|
|
1923
1971
|
this.expirationTime = issuedAt + 600;
|
|
1924
1972
|
const header = {
|
|
1925
|
-
|
|
1926
|
-
|
|
1973
|
+
alg: JwtConstants.RSA_256,
|
|
1974
|
+
x5t: EncodingUtils.base64EncodeUrl(this.thumbprint, "hex")
|
|
1927
1975
|
};
|
|
1928
1976
|
|
|
1929
1977
|
if (this.publicCertificate) {
|
|
1930
1978
|
Object.assign(header, {
|
|
1931
|
-
|
|
1979
|
+
x5c: this.publicCertificate
|
|
1932
1980
|
});
|
|
1933
1981
|
}
|
|
1934
1982
|
|
|
@@ -1941,7 +1989,7 @@ class ClientAssertion {
|
|
|
1941
1989
|
[JwtConstants.JWT_ID]: cryptoProvider.createNewGuid()
|
|
1942
1990
|
};
|
|
1943
1991
|
this.jwt = jsonwebtoken.sign(payload, this.privateKey, {
|
|
1944
|
-
header
|
|
1992
|
+
header
|
|
1945
1993
|
});
|
|
1946
1994
|
return this.jwt;
|
|
1947
1995
|
}
|
|
@@ -2037,6 +2085,10 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2037
2085
|
this.logger.verbose("Client credential client created", validRequest.correlationId);
|
|
2038
2086
|
return clientCredentialClient.acquireToken(validRequest);
|
|
2039
2087
|
} catch (e) {
|
|
2088
|
+
if (e instanceof msalCommon.AuthError) {
|
|
2089
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2040
2092
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2041
2093
|
throw e;
|
|
2042
2094
|
}
|
|
@@ -2059,28 +2111,40 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2059
2111
|
const validRequest = { ...request,
|
|
2060
2112
|
...this.initializeBaseRequest(request)
|
|
2061
2113
|
};
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
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
|
+
}
|
|
2066
2127
|
}
|
|
2067
2128
|
|
|
2068
2129
|
setClientCredential(configuration) {
|
|
2069
2130
|
const clientSecretNotEmpty = !msalCommon.StringUtils.isEmpty(configuration.auth.clientSecret);
|
|
2070
2131
|
const clientAssertionNotEmpty = !msalCommon.StringUtils.isEmpty(configuration.auth.clientAssertion);
|
|
2071
|
-
const certificate = configuration.auth.clientCertificate
|
|
2132
|
+
const certificate = configuration.auth.clientCertificate || {
|
|
2133
|
+
thumbprint: "",
|
|
2134
|
+
privateKey: ""
|
|
2135
|
+
};
|
|
2072
2136
|
const certificateNotEmpty = !msalCommon.StringUtils.isEmpty(certificate.thumbprint) || !msalCommon.StringUtils.isEmpty(certificate.privateKey); // Check that at most one credential is set on the application
|
|
2073
2137
|
|
|
2074
2138
|
if (clientSecretNotEmpty && clientAssertionNotEmpty || clientAssertionNotEmpty && certificateNotEmpty || clientSecretNotEmpty && certificateNotEmpty) {
|
|
2075
2139
|
throw msalCommon.ClientAuthError.createInvalidCredentialError();
|
|
2076
2140
|
}
|
|
2077
2141
|
|
|
2078
|
-
if (
|
|
2142
|
+
if (configuration.auth.clientSecret) {
|
|
2079
2143
|
this.clientSecret = configuration.auth.clientSecret;
|
|
2080
2144
|
return;
|
|
2081
2145
|
}
|
|
2082
2146
|
|
|
2083
|
-
if (
|
|
2147
|
+
if (configuration.auth.clientAssertion) {
|
|
2084
2148
|
this.clientAssertion = ClientAssertion.fromAssertion(configuration.auth.clientAssertion);
|
|
2085
2149
|
return;
|
|
2086
2150
|
}
|
|
@@ -2138,6 +2202,12 @@ Object.defineProperty(exports, 'InteractionRequiredAuthError', {
|
|
|
2138
2202
|
return msalCommon.InteractionRequiredAuthError;
|
|
2139
2203
|
}
|
|
2140
2204
|
});
|
|
2205
|
+
Object.defineProperty(exports, 'InteractionRequiredAuthErrorMessage', {
|
|
2206
|
+
enumerable: true,
|
|
2207
|
+
get: function () {
|
|
2208
|
+
return msalCommon.InteractionRequiredAuthErrorMessage;
|
|
2209
|
+
}
|
|
2210
|
+
});
|
|
2141
2211
|
Object.defineProperty(exports, 'LogLevel', {
|
|
2142
2212
|
enumerable: true,
|
|
2143
2213
|
get: function () {
|
|
@@ -2188,4 +2258,5 @@ exports.NodeStorage = NodeStorage;
|
|
|
2188
2258
|
exports.PublicClientApplication = PublicClientApplication;
|
|
2189
2259
|
exports.TokenCache = TokenCache;
|
|
2190
2260
|
exports.buildAppConfiguration = buildAppConfiguration;
|
|
2261
|
+
exports.version = version;
|
|
2191
2262
|
//# sourceMappingURL=msal-node.cjs.development.js.map
|