@azure/msal-node 1.13.0 → 1.14.1

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.
@@ -1,4 +1,4 @@
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, UrlString, DeviceCodeClient, ServerError, CodeChallengeMethodValues, ClientAuthError, TimeUtils, ClientCredentialClient, OnBehalfOfClient } from '@azure/msal-common';
1
+ import { Constants as Constants$1, ProtocolMode, AzureCloudInstance, LogLevel, StringUtils, AccountEntity, CacheManager, IdTokenEntity, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, ServerTelemetryEntity, AuthorityMetadataEntity, ThrottlingEntity, TokenCacheContext, AuthError, Logger, ResponseMode, AuthenticationScheme, AuthorizationCodeClient, RefreshTokenClient, SilentFlowClient, UsernamePasswordClient, ClientAuthError, OIDC_DEFAULT_SCOPES, ServerTelemetryManager, Authority, AuthorityFactory, UrlString, DeviceCodeClient, ServerError, CodeChallengeMethodValues, TimeUtils, ClientCredentialClient, OnBehalfOfClient } from '@azure/msal-common';
2
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 http, { createServer } from 'http';
4
4
  import https from 'https';
@@ -185,7 +185,7 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
185
185
  if (statusCode < 200 || statusCode > 299) {
186
186
  request.destroy();
187
187
  socket.destroy();
188
- reject(new Error(`HTTP status code ${statusCode}`));
188
+ reject(new Error(` Error connecting to proxy: ${response.statusCode}, ${response == null ? void 0 : response.statusMessage}`));
189
189
  }
190
190
 
191
191
  if (tunnelRequestOptions.timeout) {
@@ -248,8 +248,6 @@ const networkRequestViaProxy = (url, httpMethod, options, timeout) => {
248
248
  if ((statusCode < 200 || statusCode > 299) && // do not destroy the request for the device code flow
249
249
  networkResponse.body["error"] !== Constants.AUTHORIZATION_PENDING) {
250
250
  request.destroy();
251
- socket.destroy();
252
- reject(new Error(`HTTP status code ${statusCode}`));
253
251
  }
254
252
 
255
253
  resolve(networkResponse);
@@ -321,7 +319,6 @@ const networkRequestViaHttps = (url, httpMethod, options, timeout) => {
321
319
  if ((statusCode < 200 || statusCode > 299) && // do not destroy the request for the device code flow
322
320
  networkResponse.body["error"] !== Constants.AUTHORIZATION_PENDING) {
323
321
  request.destroy();
324
- reject(new Error(`HTTP status code ${statusCode}`));
325
322
  }
326
323
 
327
324
  resolve(networkResponse);
@@ -1766,7 +1763,109 @@ class TokenCache {
1766
1763
 
1767
1764
  /* eslint-disable header/header */
1768
1765
  const name = "@azure/msal-node";
1769
- const version = "1.13.0";
1766
+ const version = "1.14.1";
1767
+
1768
+ /*
1769
+ * Copyright (c) Microsoft Corporation. All rights reserved.
1770
+ * Licensed under the MIT License.
1771
+ */
1772
+ /**
1773
+ * NodeAuthErrorMessage class containing string constants used by error codes and messages.
1774
+ */
1775
+
1776
+ const NodeAuthErrorMessage = {
1777
+ invalidLoopbackAddressType: {
1778
+ code: "invalid_loopback_server_address_type",
1779
+ desc: "Loopback server address is not type string. This is unexpected."
1780
+ },
1781
+ unableToLoadRedirectUri: {
1782
+ code: "unable_to_load_redirectUrl",
1783
+ desc: "Loopback server callback was invoked without a url. This is unexpected."
1784
+ },
1785
+ noAuthCodeInResponse: {
1786
+ code: "no_auth_code_in_response",
1787
+ desc: "No auth code found in the server response. Please check your network trace to determine what happened."
1788
+ },
1789
+ noLoopbackServerExists: {
1790
+ code: "no_loopback_server_exists",
1791
+ desc: "No loopback server exists yet."
1792
+ },
1793
+ loopbackServerAlreadyExists: {
1794
+ code: "loopback_server_already_exists",
1795
+ desc: "Loopback server already exists. Cannot create another."
1796
+ },
1797
+ loopbackServerTimeout: {
1798
+ code: "loopback_server_timeout",
1799
+ desc: "Timed out waiting for auth code listener to be registered."
1800
+ },
1801
+ stateNotFoundError: {
1802
+ code: "state_not_found",
1803
+ desc: "State not found. Please verify that the request originated from msal."
1804
+ }
1805
+ };
1806
+ class NodeAuthError extends AuthError {
1807
+ constructor(errorCode, errorMessage) {
1808
+ super(errorCode, errorMessage);
1809
+ this.name = "NodeAuthError";
1810
+ }
1811
+ /**
1812
+ * Creates an error thrown if loopback server address is of type string.
1813
+ */
1814
+
1815
+
1816
+ static createInvalidLoopbackAddressTypeError() {
1817
+ return new NodeAuthError(NodeAuthErrorMessage.invalidLoopbackAddressType.code, `${NodeAuthErrorMessage.invalidLoopbackAddressType.desc}`);
1818
+ }
1819
+ /**
1820
+ * Creates an error thrown if the loopback server is unable to get a url.
1821
+ */
1822
+
1823
+
1824
+ static createUnableToLoadRedirectUrlError() {
1825
+ return new NodeAuthError(NodeAuthErrorMessage.unableToLoadRedirectUri.code, `${NodeAuthErrorMessage.unableToLoadRedirectUri.desc}`);
1826
+ }
1827
+ /**
1828
+ * Creates an error thrown if the server response does not contain an auth code.
1829
+ */
1830
+
1831
+
1832
+ static createNoAuthCodeInResponseError() {
1833
+ return new NodeAuthError(NodeAuthErrorMessage.noAuthCodeInResponse.code, `${NodeAuthErrorMessage.noAuthCodeInResponse.desc}`);
1834
+ }
1835
+ /**
1836
+ * Creates an error thrown if the loopback server has not been spun up yet.
1837
+ */
1838
+
1839
+
1840
+ static createNoLoopbackServerExistsError() {
1841
+ return new NodeAuthError(NodeAuthErrorMessage.noLoopbackServerExists.code, `${NodeAuthErrorMessage.noLoopbackServerExists.desc}`);
1842
+ }
1843
+ /**
1844
+ * Creates an error thrown if a loopback server already exists when attempting to create another one.
1845
+ */
1846
+
1847
+
1848
+ static createLoopbackServerAlreadyExistsError() {
1849
+ return new NodeAuthError(NodeAuthErrorMessage.loopbackServerAlreadyExists.code, `${NodeAuthErrorMessage.loopbackServerAlreadyExists.desc}`);
1850
+ }
1851
+ /**
1852
+ * Creates an error thrown if the loopback server times out registering the auth code listener.
1853
+ */
1854
+
1855
+
1856
+ static createLoopbackServerTimeoutError() {
1857
+ return new NodeAuthError(NodeAuthErrorMessage.loopbackServerTimeout.code, `${NodeAuthErrorMessage.loopbackServerTimeout.desc}`);
1858
+ }
1859
+ /**
1860
+ * Creates an error thrown when the state is not present.
1861
+ */
1862
+
1863
+
1864
+ static createStateNotFoundError() {
1865
+ return new NodeAuthError(NodeAuthErrorMessage.stateNotFoundError.code, NodeAuthErrorMessage.stateNotFoundError.desc);
1866
+ }
1867
+
1868
+ }
1770
1869
 
1771
1870
  /*
1772
1871
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1822,7 +1921,17 @@ class ClientApplication {
1822
1921
 
1823
1922
 
1824
1923
  async acquireTokenByCode(request, authCodePayLoad) {
1825
- this.logger.info("acquireTokenByCode called", request.correlationId);
1924
+ this.logger.info("acquireTokenByCode called");
1925
+
1926
+ if (request.state && authCodePayLoad) {
1927
+ this.logger.info("acquireTokenByCode - validating state");
1928
+ this.validateState(request.state, authCodePayLoad.state || ""); // eslint-disable-next-line no-param-reassign
1929
+
1930
+ authCodePayLoad = { ...authCodePayLoad,
1931
+ state: ""
1932
+ };
1933
+ }
1934
+
1826
1935
  const validRequest = { ...request,
1827
1936
  ...(await this.initializeBaseRequest(request)),
1828
1937
  authenticationScheme: AuthenticationScheme.BEARER
@@ -1947,6 +2056,26 @@ class ClientApplication {
1947
2056
  this.logger.info("getTokenCache called");
1948
2057
  return this.tokenCache;
1949
2058
  }
2059
+ /**
2060
+ * Validates OIDC state by comparing the user cached state with the state received from the server.
2061
+ *
2062
+ * This API is provided for scenarios where you would use OAuth2.0 state parameter to mitigate against
2063
+ * CSRF attacks.
2064
+ * For more information about state, visit https://datatracker.ietf.org/doc/html/rfc6819#section-3.6.
2065
+ * @param state
2066
+ * @param cachedState
2067
+ */
2068
+
2069
+
2070
+ validateState(state, cachedState) {
2071
+ if (!state) {
2072
+ throw NodeAuthError.createStateNotFoundError();
2073
+ }
2074
+
2075
+ if (state !== cachedState) {
2076
+ throw ClientAuthError.createStateMismatchError();
2077
+ }
2078
+ }
1950
2079
  /**
1951
2080
  * Returns the logger instance
1952
2081
  */
@@ -2095,96 +2224,6 @@ class ClientApplication {
2095
2224
 
2096
2225
  }
2097
2226
 
2098
- /*
2099
- * Copyright (c) Microsoft Corporation. All rights reserved.
2100
- * Licensed under the MIT License.
2101
- */
2102
- /**
2103
- * NodeAuthErrorMessage class containing string constants used by error codes and messages.
2104
- */
2105
-
2106
- const NodeAuthErrorMessage = {
2107
- invalidLoopbackAddressType: {
2108
- code: "invalid_loopback_server_address_type",
2109
- desc: "Loopback server address is not type string. This is unexpected."
2110
- },
2111
- unableToLoadRedirectUri: {
2112
- code: "unable_to_load_redirectUrl",
2113
- desc: "Loopback server callback was invoked without a url. This is unexpected."
2114
- },
2115
- noAuthCodeInResponse: {
2116
- code: "no_auth_code_in_response",
2117
- desc: "No auth code found in the server response. Please check your network trace to determine what happened."
2118
- },
2119
- noLoopbackServerExists: {
2120
- code: "no_loopback_server_exists",
2121
- desc: "No loopback server exists yet."
2122
- },
2123
- loopbackServerAlreadyExists: {
2124
- code: "loopback_server_already_exists",
2125
- desc: "Loopback server already exists. Cannot create another."
2126
- },
2127
- loopbackServerTimeout: {
2128
- code: "loopback_server_timeout",
2129
- desc: "Timed out waiting for auth code listener to be registered."
2130
- }
2131
- };
2132
- class NodeAuthError extends AuthError {
2133
- constructor(errorCode, errorMessage) {
2134
- super(errorCode, errorMessage);
2135
- this.name = "NodeAuthError";
2136
- }
2137
- /**
2138
- * Creates an error thrown if loopback server address is of type string.
2139
- */
2140
-
2141
-
2142
- static createInvalidLoopbackAddressTypeError() {
2143
- return new NodeAuthError(NodeAuthErrorMessage.invalidLoopbackAddressType.code, `${NodeAuthErrorMessage.invalidLoopbackAddressType.desc}`);
2144
- }
2145
- /**
2146
- * Creates an error thrown if the loopback server is unable to get a url.
2147
- */
2148
-
2149
-
2150
- static createUnableToLoadRedirectUrlError() {
2151
- return new NodeAuthError(NodeAuthErrorMessage.unableToLoadRedirectUri.code, `${NodeAuthErrorMessage.unableToLoadRedirectUri.desc}`);
2152
- }
2153
- /**
2154
- * Creates an error thrown if the server response does not contain an auth code.
2155
- */
2156
-
2157
-
2158
- static createNoAuthCodeInResponseError() {
2159
- return new NodeAuthError(NodeAuthErrorMessage.noAuthCodeInResponse.code, `${NodeAuthErrorMessage.noAuthCodeInResponse.desc}`);
2160
- }
2161
- /**
2162
- * Creates an error thrown if the loopback server has not been spun up yet.
2163
- */
2164
-
2165
-
2166
- static createNoLoopbackServerExistsError() {
2167
- return new NodeAuthError(NodeAuthErrorMessage.noLoopbackServerExists.code, `${NodeAuthErrorMessage.noLoopbackServerExists.desc}`);
2168
- }
2169
- /**
2170
- * Creates an error thrown if a loopback server already exists when attempting to create another one.
2171
- */
2172
-
2173
-
2174
- static createLoopbackServerAlreadyExistsError() {
2175
- return new NodeAuthError(NodeAuthErrorMessage.loopbackServerAlreadyExists.code, `${NodeAuthErrorMessage.loopbackServerAlreadyExists.desc}`);
2176
- }
2177
- /**
2178
- * Creates an error thrown if the loopback server times out registering the auth code listener.
2179
- */
2180
-
2181
-
2182
- static createLoopbackServerTimeoutError() {
2183
- return new NodeAuthError(NodeAuthErrorMessage.loopbackServerTimeout.code, `${NodeAuthErrorMessage.loopbackServerTimeout.desc}`);
2184
- }
2185
-
2186
- }
2187
-
2188
2227
  /*
2189
2228
  * Copyright (c) Microsoft Corporation. All rights reserved.
2190
2229
  * Licensed under the MIT License.
@@ -2593,8 +2632,13 @@ class ConfidentialClientApplication extends ClientApplication {
2593
2632
  };
2594
2633
  }
2595
2634
 
2635
+ const baseRequest = await this.initializeBaseRequest(request); // valid base request should not contain oidc scopes in this grant type
2636
+
2637
+ const validBaseRequest = { ...baseRequest,
2638
+ scopes: baseRequest.scopes.filter(scope => !OIDC_DEFAULT_SCOPES.includes(scope))
2639
+ };
2596
2640
  const validRequest = { ...request,
2597
- ...(await this.initializeBaseRequest(request)),
2641
+ ...validBaseRequest,
2598
2642
  clientAssertion
2599
2643
  };
2600
2644
  const azureRegionConfiguration = {