@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
package/dist/msal-node.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Constants as Constants$1, ProtocolMode, LogLevel, StringUtils, AccountEntity, CacheManager, IdTokenEntity, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, ServerTelemetryEntity, AuthorityMetadataEntity, ThrottlingEntity, TokenCacheContext, Logger, ResponseMode, AuthenticationScheme, AuthorizationCodeClient, 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, LogLevel, Logger, PromptValue, ProtocolMode, ResponseMode, ServerError, TokenCacheContext } from '@azure/msal-common';
|
|
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';
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
import { v4 } from 'uuid';
|
|
5
5
|
import crypto from 'crypto';
|
|
@@ -106,7 +106,11 @@ class HttpClient {
|
|
|
106
106
|
const request = {
|
|
107
107
|
method: HttpMethod.GET,
|
|
108
108
|
url: url,
|
|
109
|
+
|
|
110
|
+
/* istanbul ignore next */
|
|
109
111
|
headers: options && options.headers,
|
|
112
|
+
|
|
113
|
+
/* istanbul ignore next */
|
|
110
114
|
validateStatus: () => true
|
|
111
115
|
};
|
|
112
116
|
const response = await axios(request);
|
|
@@ -127,9 +131,15 @@ class HttpClient {
|
|
|
127
131
|
const request = {
|
|
128
132
|
method: HttpMethod.POST,
|
|
129
133
|
url: url,
|
|
134
|
+
|
|
135
|
+
/* istanbul ignore next */
|
|
130
136
|
data: options && options.body || "",
|
|
131
137
|
timeout: cancellationToken,
|
|
138
|
+
|
|
139
|
+
/* istanbul ignore next */
|
|
132
140
|
headers: options && options.headers,
|
|
141
|
+
|
|
142
|
+
/* istanbul ignore next */
|
|
133
143
|
validateStatus: () => true
|
|
134
144
|
};
|
|
135
145
|
const response = await axios(request);
|
|
@@ -320,8 +330,25 @@ class PkceGenerator {
|
|
|
320
330
|
|
|
321
331
|
|
|
322
332
|
generateCodeVerifier() {
|
|
323
|
-
const
|
|
324
|
-
const
|
|
333
|
+
const charArr = [];
|
|
334
|
+
const maxNumber = 256 - 256 % CharSet.CV_CHARSET.length;
|
|
335
|
+
|
|
336
|
+
while (charArr.length <= RANDOM_OCTET_SIZE) {
|
|
337
|
+
const byte = crypto.randomBytes(1)[0];
|
|
338
|
+
|
|
339
|
+
if (byte >= maxNumber) {
|
|
340
|
+
/*
|
|
341
|
+
* Ignore this number to maintain randomness.
|
|
342
|
+
* Including it would result in an unequal distribution of characters after doing the modulo
|
|
343
|
+
*/
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const index = byte % CharSet.CV_CHARSET.length;
|
|
348
|
+
charArr.push(CharSet.CV_CHARSET[index]);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const verifier = charArr.join("");
|
|
325
352
|
return EncodingUtils.base64EncodeUrl(verifier);
|
|
326
353
|
}
|
|
327
354
|
/**
|
|
@@ -342,22 +369,6 @@ class PkceGenerator {
|
|
|
342
369
|
sha256(buffer) {
|
|
343
370
|
return crypto.createHash(Hash.SHA256).update(buffer).digest();
|
|
344
371
|
}
|
|
345
|
-
/**
|
|
346
|
-
* Accepted characters; reference: https://tools.ietf.org/html/rfc7636#section-4.1
|
|
347
|
-
* @param buffer
|
|
348
|
-
*/
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
bufferToCVString(buffer) {
|
|
352
|
-
const charArr = [];
|
|
353
|
-
|
|
354
|
-
for (let i = 0; i < buffer.byteLength; i += 1) {
|
|
355
|
-
const index = buffer[i] % CharSet.CV_CHARSET.length;
|
|
356
|
-
charArr.push(CharSet.CV_CHARSET[index]);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
return charArr.join("");
|
|
360
|
-
}
|
|
361
372
|
|
|
362
373
|
}
|
|
363
374
|
|
|
@@ -419,6 +430,23 @@ class CryptoProvider {
|
|
|
419
430
|
getPublicKeyThumbprint() {
|
|
420
431
|
throw new Error("Method not implemented.");
|
|
421
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
* Removes cryptographic keypair from key store matching the keyId passed in
|
|
435
|
+
* @param kid
|
|
436
|
+
*/
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
removeTokenBindingKey() {
|
|
440
|
+
throw new Error("Method not implemented.");
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Removes all cryptographic keys from Keystore
|
|
444
|
+
*/
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
clearKeystore() {
|
|
448
|
+
throw new Error("Method not implemented.");
|
|
449
|
+
}
|
|
422
450
|
/**
|
|
423
451
|
* Signs the given object as a jwt payload with private key retrieved by given kid - currently not implemented for node
|
|
424
452
|
*/
|
|
@@ -1176,7 +1204,7 @@ class NodeStorage extends CacheManager {
|
|
|
1176
1204
|
*/
|
|
1177
1205
|
|
|
1178
1206
|
|
|
1179
|
-
clear() {
|
|
1207
|
+
async clear() {
|
|
1180
1208
|
this.logger.trace("Clearing cache entries created by MSAL"); // read inMemoryCache
|
|
1181
1209
|
|
|
1182
1210
|
const cacheKeys = this.getKeys(); // delete each element
|
|
@@ -1360,7 +1388,7 @@ class TokenCache {
|
|
|
1360
1388
|
await this.persistence.beforeCacheAccess(cacheContext);
|
|
1361
1389
|
}
|
|
1362
1390
|
|
|
1363
|
-
this.storage.removeAccount(AccountEntity.generateAccountCacheKey(account));
|
|
1391
|
+
await this.storage.removeAccount(AccountEntity.generateAccountCacheKey(account));
|
|
1364
1392
|
} finally {
|
|
1365
1393
|
if (this.persistence && cacheContext) {
|
|
1366
1394
|
await this.persistence.afterCacheAccess(cacheContext);
|
|
@@ -1489,7 +1517,7 @@ class TokenCache {
|
|
|
1489
1517
|
|
|
1490
1518
|
/* eslint-disable header/header */
|
|
1491
1519
|
const name = "@azure/msal-node";
|
|
1492
|
-
const version = "1.
|
|
1520
|
+
const version = "1.4.0";
|
|
1493
1521
|
|
|
1494
1522
|
/*
|
|
1495
1523
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1558,6 +1586,10 @@ class ClientApplication {
|
|
|
1558
1586
|
this.logger.verbose("Auth code client created", validRequest.correlationId);
|
|
1559
1587
|
return authorizationCodeClient.acquireToken(validRequest);
|
|
1560
1588
|
} catch (e) {
|
|
1589
|
+
if (e instanceof AuthError) {
|
|
1590
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1561
1593
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
1562
1594
|
throw e;
|
|
1563
1595
|
}
|
|
@@ -1585,6 +1617,10 @@ class ClientApplication {
|
|
|
1585
1617
|
this.logger.verbose("Refresh token client created", validRequest.correlationId);
|
|
1586
1618
|
return refreshTokenClient.acquireToken(validRequest);
|
|
1587
1619
|
} catch (e) {
|
|
1620
|
+
if (e instanceof AuthError) {
|
|
1621
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1588
1624
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
1589
1625
|
throw e;
|
|
1590
1626
|
}
|
|
@@ -1612,6 +1648,10 @@ class ClientApplication {
|
|
|
1612
1648
|
this.logger.verbose("Silent flow client created", validRequest.correlationId);
|
|
1613
1649
|
return silentFlowClient.acquireToken(validRequest);
|
|
1614
1650
|
} catch (e) {
|
|
1651
|
+
if (e instanceof AuthError) {
|
|
1652
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1615
1655
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
1616
1656
|
throw e;
|
|
1617
1657
|
}
|
|
@@ -1641,6 +1681,10 @@ class ClientApplication {
|
|
|
1641
1681
|
this.logger.verbose("Username password client created", validRequest.correlationId);
|
|
1642
1682
|
return usernamePasswordClient.acquireToken(validRequest);
|
|
1643
1683
|
} catch (e) {
|
|
1684
|
+
if (e instanceof AuthError) {
|
|
1685
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1644
1688
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
1645
1689
|
throw e;
|
|
1646
1690
|
}
|
|
@@ -1832,6 +1876,10 @@ class PublicClientApplication extends ClientApplication {
|
|
|
1832
1876
|
this.logger.verbose("Device code client created", validRequest.correlationId);
|
|
1833
1877
|
return deviceCodeClient.acquireToken(validRequest);
|
|
1834
1878
|
} catch (e) {
|
|
1879
|
+
if (e instanceof AuthError) {
|
|
1880
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1835
1883
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
1836
1884
|
throw e;
|
|
1837
1885
|
}
|
|
@@ -1917,13 +1965,13 @@ class ClientAssertion {
|
|
|
1917
1965
|
const issuedAt = TimeUtils.nowSeconds();
|
|
1918
1966
|
this.expirationTime = issuedAt + 600;
|
|
1919
1967
|
const header = {
|
|
1920
|
-
|
|
1921
|
-
|
|
1968
|
+
alg: JwtConstants.RSA_256,
|
|
1969
|
+
x5t: EncodingUtils.base64EncodeUrl(this.thumbprint, "hex")
|
|
1922
1970
|
};
|
|
1923
1971
|
|
|
1924
1972
|
if (this.publicCertificate) {
|
|
1925
1973
|
Object.assign(header, {
|
|
1926
|
-
|
|
1974
|
+
x5c: this.publicCertificate
|
|
1927
1975
|
});
|
|
1928
1976
|
}
|
|
1929
1977
|
|
|
@@ -1936,7 +1984,7 @@ class ClientAssertion {
|
|
|
1936
1984
|
[JwtConstants.JWT_ID]: cryptoProvider.createNewGuid()
|
|
1937
1985
|
};
|
|
1938
1986
|
this.jwt = sign(payload, this.privateKey, {
|
|
1939
|
-
header
|
|
1987
|
+
header
|
|
1940
1988
|
});
|
|
1941
1989
|
return this.jwt;
|
|
1942
1990
|
}
|
|
@@ -2032,6 +2080,10 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2032
2080
|
this.logger.verbose("Client credential client created", validRequest.correlationId);
|
|
2033
2081
|
return clientCredentialClient.acquireToken(validRequest);
|
|
2034
2082
|
} catch (e) {
|
|
2083
|
+
if (e instanceof AuthError) {
|
|
2084
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2035
2087
|
serverTelemetryManager.cacheFailedRequest(e);
|
|
2036
2088
|
throw e;
|
|
2037
2089
|
}
|
|
@@ -2054,28 +2106,40 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2054
2106
|
const validRequest = { ...request,
|
|
2055
2107
|
...this.initializeBaseRequest(request)
|
|
2056
2108
|
};
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2109
|
+
|
|
2110
|
+
try {
|
|
2111
|
+
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId);
|
|
2112
|
+
const oboClient = new OnBehalfOfClient(clientCredentialConfig);
|
|
2113
|
+
this.logger.verbose("On behalf of client created", validRequest.correlationId);
|
|
2114
|
+
return oboClient.acquireToken(validRequest);
|
|
2115
|
+
} catch (e) {
|
|
2116
|
+
if (e instanceof AuthError) {
|
|
2117
|
+
e.setCorrelationId(validRequest.correlationId);
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
throw e;
|
|
2121
|
+
}
|
|
2061
2122
|
}
|
|
2062
2123
|
|
|
2063
2124
|
setClientCredential(configuration) {
|
|
2064
2125
|
const clientSecretNotEmpty = !StringUtils.isEmpty(configuration.auth.clientSecret);
|
|
2065
2126
|
const clientAssertionNotEmpty = !StringUtils.isEmpty(configuration.auth.clientAssertion);
|
|
2066
|
-
const certificate = configuration.auth.clientCertificate
|
|
2127
|
+
const certificate = configuration.auth.clientCertificate || {
|
|
2128
|
+
thumbprint: "",
|
|
2129
|
+
privateKey: ""
|
|
2130
|
+
};
|
|
2067
2131
|
const certificateNotEmpty = !StringUtils.isEmpty(certificate.thumbprint) || !StringUtils.isEmpty(certificate.privateKey); // Check that at most one credential is set on the application
|
|
2068
2132
|
|
|
2069
2133
|
if (clientSecretNotEmpty && clientAssertionNotEmpty || clientAssertionNotEmpty && certificateNotEmpty || clientSecretNotEmpty && certificateNotEmpty) {
|
|
2070
2134
|
throw ClientAuthError.createInvalidCredentialError();
|
|
2071
2135
|
}
|
|
2072
2136
|
|
|
2073
|
-
if (
|
|
2137
|
+
if (configuration.auth.clientSecret) {
|
|
2074
2138
|
this.clientSecret = configuration.auth.clientSecret;
|
|
2075
2139
|
return;
|
|
2076
2140
|
}
|
|
2077
2141
|
|
|
2078
|
-
if (
|
|
2142
|
+
if (configuration.auth.clientAssertion) {
|
|
2079
2143
|
this.clientAssertion = ClientAssertion.fromAssertion(configuration.auth.clientAssertion);
|
|
2080
2144
|
return;
|
|
2081
2145
|
}
|
|
@@ -2091,5 +2155,5 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2091
2155
|
|
|
2092
2156
|
}
|
|
2093
2157
|
|
|
2094
|
-
export { ClientApplication, ClientAssertion, ConfidentialClientApplication, CryptoProvider, NodeStorage, PublicClientApplication, TokenCache, buildAppConfiguration };
|
|
2158
|
+
export { ClientApplication, ClientAssertion, ConfidentialClientApplication, CryptoProvider, NodeStorage, PublicClientApplication, TokenCache, buildAppConfiguration, version };
|
|
2095
2159
|
//# sourceMappingURL=msal-node.esm.js.map
|