@azure/msal-node 3.5.2 → 3.6.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.
Files changed (126) hide show
  1. package/dist/cache/NodeStorage.mjs +1 -1
  2. package/dist/cache/TokenCache.mjs +1 -1
  3. package/dist/cache/distributed/DistributedCachePlugin.mjs +1 -1
  4. package/dist/cache/serializer/Deserializer.mjs +1 -1
  5. package/dist/cache/serializer/Serializer.mjs +1 -1
  6. package/dist/client/ClientApplication.mjs +1 -1
  7. package/dist/client/ClientAssertion.d.ts.map +1 -1
  8. package/dist/client/ClientAssertion.mjs +3 -3
  9. package/dist/client/ClientAssertion.mjs.map +1 -1
  10. package/dist/client/ClientCredentialClient.mjs +1 -1
  11. package/dist/client/ConfidentialClientApplication.mjs +1 -1
  12. package/dist/client/DeviceCodeClient.mjs +1 -1
  13. package/dist/client/ManagedIdentityApplication.d.ts +11 -0
  14. package/dist/client/ManagedIdentityApplication.d.ts.map +1 -1
  15. package/dist/client/ManagedIdentityApplication.mjs +46 -11
  16. package/dist/client/ManagedIdentityApplication.mjs.map +1 -1
  17. package/dist/client/ManagedIdentityClient.mjs +1 -1
  18. package/dist/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
  19. package/dist/client/ManagedIdentitySources/AppService.mjs +6 -5
  20. package/dist/client/ManagedIdentitySources/AppService.mjs.map +1 -1
  21. package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
  22. package/dist/client/ManagedIdentitySources/AzureArc.mjs +8 -8
  23. package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
  24. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
  25. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +11 -2
  26. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
  27. package/dist/client/ManagedIdentitySources/CloudShell.mjs +4 -4
  28. package/dist/client/ManagedIdentitySources/CloudShell.mjs.map +1 -1
  29. package/dist/client/ManagedIdentitySources/Imds.d.ts +32 -0
  30. package/dist/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
  31. package/dist/client/ManagedIdentitySources/Imds.mjs +39 -8
  32. package/dist/client/ManagedIdentitySources/Imds.mjs.map +1 -1
  33. package/dist/client/ManagedIdentitySources/MachineLearning.d.ts.map +1 -1
  34. package/dist/client/ManagedIdentitySources/MachineLearning.mjs +7 -6
  35. package/dist/client/ManagedIdentitySources/MachineLearning.mjs.map +1 -1
  36. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +30 -0
  37. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
  38. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +36 -10
  39. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs.map +1 -1
  40. package/dist/client/OnBehalfOfClient.mjs +1 -1
  41. package/dist/client/PublicClientApplication.mjs +1 -1
  42. package/dist/client/UsernamePasswordClient.mjs +1 -1
  43. package/dist/config/Configuration.d.ts +4 -2
  44. package/dist/config/Configuration.d.ts.map +1 -1
  45. package/dist/config/Configuration.mjs +3 -2
  46. package/dist/config/Configuration.mjs.map +1 -1
  47. package/dist/config/ManagedIdentityId.mjs +1 -1
  48. package/dist/config/ManagedIdentityRequestParameters.mjs +1 -1
  49. package/dist/crypto/CryptoProvider.d.ts.map +1 -1
  50. package/dist/crypto/CryptoProvider.mjs +3 -2
  51. package/dist/crypto/CryptoProvider.mjs.map +1 -1
  52. package/dist/crypto/GuidGenerator.mjs +1 -1
  53. package/dist/crypto/HashUtils.mjs +1 -1
  54. package/dist/crypto/PkceGenerator.d.ts.map +1 -1
  55. package/dist/crypto/PkceGenerator.mjs +3 -3
  56. package/dist/crypto/PkceGenerator.mjs.map +1 -1
  57. package/dist/error/ManagedIdentityError.mjs +1 -1
  58. package/dist/error/ManagedIdentityErrorCodes.mjs +1 -1
  59. package/dist/error/NodeAuthError.mjs +1 -1
  60. package/dist/index.mjs +1 -1
  61. package/dist/internals.mjs +1 -1
  62. package/dist/network/HttpClient.mjs +1 -1
  63. package/dist/network/HttpClientWithRetries.mjs +1 -1
  64. package/dist/network/LoopbackClient.mjs +1 -1
  65. package/dist/packageMetadata.d.ts +1 -1
  66. package/dist/packageMetadata.mjs +2 -2
  67. package/dist/protocol/Authorize.mjs +1 -1
  68. package/dist/request/ManagedIdentityRequest.d.ts +6 -3
  69. package/dist/request/ManagedIdentityRequest.d.ts.map +1 -1
  70. package/dist/retry/DefaultManagedIdentityRetryPolicy.d.ts +1 -0
  71. package/dist/retry/DefaultManagedIdentityRetryPolicy.d.ts.map +1 -1
  72. package/dist/retry/DefaultManagedIdentityRetryPolicy.mjs +3 -3
  73. package/dist/retry/DefaultManagedIdentityRetryPolicy.mjs.map +1 -1
  74. package/dist/retry/ExponentialRetryStrategy.mjs +1 -1
  75. package/dist/retry/ImdsRetryPolicy.mjs +1 -1
  76. package/dist/retry/LinearRetryStrategy.mjs +1 -1
  77. package/dist/utils/Constants.d.ts +20 -6
  78. package/dist/utils/Constants.d.ts.map +1 -1
  79. package/dist/utils/Constants.mjs +20 -8
  80. package/dist/utils/Constants.mjs.map +1 -1
  81. package/dist/utils/EncodingUtils.mjs +4 -4
  82. package/dist/utils/EncodingUtils.mjs.map +1 -1
  83. package/dist/utils/NetworkUtils.mjs +1 -1
  84. package/dist/utils/TimeUtils.mjs +1 -1
  85. package/lib/msal-node.cjs +235 -125
  86. package/lib/msal-node.cjs.map +1 -1
  87. package/lib/types/client/ClientAssertion.d.ts.map +1 -1
  88. package/lib/types/client/ManagedIdentityApplication.d.ts +11 -0
  89. package/lib/types/client/ManagedIdentityApplication.d.ts.map +1 -1
  90. package/lib/types/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
  91. package/lib/types/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
  92. package/lib/types/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
  93. package/lib/types/client/ManagedIdentitySources/Imds.d.ts +32 -0
  94. package/lib/types/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
  95. package/lib/types/client/ManagedIdentitySources/MachineLearning.d.ts.map +1 -1
  96. package/lib/types/client/ManagedIdentitySources/ServiceFabric.d.ts +30 -0
  97. package/lib/types/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
  98. package/lib/types/config/Configuration.d.ts +4 -2
  99. package/lib/types/config/Configuration.d.ts.map +1 -1
  100. package/lib/types/crypto/CryptoProvider.d.ts.map +1 -1
  101. package/lib/types/crypto/PkceGenerator.d.ts.map +1 -1
  102. package/lib/types/packageMetadata.d.ts +1 -1
  103. package/lib/types/request/ManagedIdentityRequest.d.ts +6 -3
  104. package/lib/types/request/ManagedIdentityRequest.d.ts.map +1 -1
  105. package/lib/types/retry/DefaultManagedIdentityRetryPolicy.d.ts +1 -0
  106. package/lib/types/retry/DefaultManagedIdentityRetryPolicy.d.ts.map +1 -1
  107. package/lib/types/utils/Constants.d.ts +20 -6
  108. package/lib/types/utils/Constants.d.ts.map +1 -1
  109. package/package.json +3 -2
  110. package/src/client/ClientAssertion.ts +2 -1
  111. package/src/client/ManagedIdentityApplication.ts +71 -10
  112. package/src/client/ManagedIdentitySources/AppService.ts +6 -6
  113. package/src/client/ManagedIdentitySources/AzureArc.ts +10 -9
  114. package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +28 -1
  115. package/src/client/ManagedIdentitySources/CloudShell.ts +4 -4
  116. package/src/client/ManagedIdentitySources/Imds.ts +40 -10
  117. package/src/client/ManagedIdentitySources/MachineLearning.ts +7 -8
  118. package/src/client/ManagedIdentitySources/ServiceFabric.ts +36 -11
  119. package/src/config/Configuration.ts +5 -1
  120. package/src/crypto/CryptoProvider.ts +3 -3
  121. package/src/crypto/PkceGenerator.ts +3 -3
  122. package/src/packageMetadata.ts +1 -1
  123. package/src/request/ManagedIdentityRequest.ts +6 -3
  124. package/src/retry/DefaultManagedIdentityRetryPolicy.ts +1 -1
  125. package/src/utils/Constants.ts +24 -6
  126. package/src/utils/EncodingUtils.ts +3 -3
@@ -24,7 +24,11 @@ import { ManagedIdentityId } from "../../config/ManagedIdentityId.js";
24
24
  import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters.js";
25
25
  import { CryptoProvider } from "../../crypto/CryptoProvider.js";
26
26
  import { ManagedIdentityRequest } from "../../request/ManagedIdentityRequest.js";
27
- import { HttpMethod, ManagedIdentityIdType } from "../../utils/Constants.js";
27
+ import {
28
+ HttpMethod,
29
+ ManagedIdentityIdType,
30
+ ManagedIdentityQueryParameters,
31
+ } from "../../utils/Constants.js";
28
32
  import { ManagedIdentityTokenResponse } from "../../response/ManagedIdentityTokenResponse.js";
29
33
  import { NodeStorage } from "../../cache/NodeStorage.js";
30
34
  import {
@@ -146,6 +150,29 @@ export abstract class BaseManagedIdentitySource {
146
150
  managedIdentityId
147
151
  );
148
152
 
153
+ if (managedIdentityRequest.revokedTokenSha256Hash) {
154
+ this.logger.info(
155
+ `[Managed Identity] The following claims are present in the request: ${managedIdentityRequest.claims}`
156
+ );
157
+
158
+ networkRequest.queryParameters[
159
+ ManagedIdentityQueryParameters.SHA256_TOKEN_TO_REFRESH
160
+ ] = managedIdentityRequest.revokedTokenSha256Hash;
161
+ }
162
+
163
+ if (managedIdentityRequest.clientCapabilities?.length) {
164
+ const clientCapabilities: string =
165
+ managedIdentityRequest.clientCapabilities.toString();
166
+
167
+ this.logger.info(
168
+ `[Managed Identity] The following client capabilities are present in the request: ${clientCapabilities}`
169
+ );
170
+
171
+ networkRequest.queryParameters[
172
+ ManagedIdentityQueryParameters.XMS_CC
173
+ ] = clientCapabilities;
174
+ }
175
+
149
176
  const headers: Record<string, string> = networkRequest.headers;
150
177
  headers[HeaderNames.CONTENT_TYPE] = Constants.URL_FORM_CONTENT_TYPE;
151
178
 
@@ -10,11 +10,11 @@ import { NodeStorage } from "../../cache/NodeStorage.js";
10
10
  import { CryptoProvider } from "../../crypto/CryptoProvider.js";
11
11
  import {
12
12
  HttpMethod,
13
- METADATA_HEADER_NAME,
14
13
  ManagedIdentityEnvironmentVariableNames,
14
+ ManagedIdentityHeaders,
15
15
  ManagedIdentityIdType,
16
+ ManagedIdentityQueryParameters,
16
17
  ManagedIdentitySourceNames,
17
- RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
18
18
  } from "../../utils/Constants.js";
19
19
  import {
20
20
  ManagedIdentityErrorCodes,
@@ -109,9 +109,9 @@ export class CloudShell extends BaseManagedIdentitySource {
109
109
  this.msiEndpoint
110
110
  );
111
111
 
112
- request.headers[METADATA_HEADER_NAME] = "true";
112
+ request.headers[ManagedIdentityHeaders.METADATA_HEADER_NAME] = "true";
113
113
 
114
- request.bodyParameters[RESOURCE_BODY_OR_QUERY_PARAMETER_NAME] =
114
+ request.bodyParameters[ManagedIdentityQueryParameters.RESOURCE] =
115
115
  resource;
116
116
 
117
117
  return request;
@@ -9,27 +9,37 @@ import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRe
9
9
  import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource.js";
10
10
  import { CryptoProvider } from "../../crypto/CryptoProvider.js";
11
11
  import {
12
- API_VERSION_QUERY_PARAMETER_NAME,
13
12
  HttpMethod,
14
- METADATA_HEADER_NAME,
15
13
  ManagedIdentityEnvironmentVariableNames,
14
+ ManagedIdentityHeaders,
16
15
  ManagedIdentityIdType,
16
+ ManagedIdentityQueryParameters,
17
17
  ManagedIdentitySourceNames,
18
- RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
19
18
  } from "../../utils/Constants.js";
20
19
  import { NodeStorage } from "../../cache/NodeStorage.js";
21
20
  import { ImdsRetryPolicy } from "../../retry/ImdsRetryPolicy.js";
22
21
 
23
- // IMDS constants. Docs for IMDS are available here https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/how-to-use-vm-token#get-a-token-using-http
22
+ // Documentation for IMDS is available at https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/how-to-use-vm-token#get-a-token-using-http
23
+
24
24
  const IMDS_TOKEN_PATH: string = "/metadata/identity/oauth2/token";
25
25
  const DEFAULT_IMDS_ENDPOINT: string = `http://169.254.169.254${IMDS_TOKEN_PATH}`;
26
-
27
26
  const IMDS_API_VERSION: string = "2018-02-01";
28
27
 
29
- // Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs
28
+ /**
29
+ * Original source of code: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/src/ImdsManagedIdentitySource.cs
30
+ */
30
31
  export class Imds extends BaseManagedIdentitySource {
31
32
  private identityEndpoint: string;
32
33
 
34
+ /**
35
+ * Constructs an Imds instance.
36
+ * @param logger - Logger instance for logging.
37
+ * @param nodeStorage - NodeStorage instance for caching.
38
+ * @param networkClient - Network client for HTTP requests.
39
+ * @param cryptoProvider - CryptoProvider for cryptographic operations.
40
+ * @param disableInternalRetries - Whether to disable internal retry logic.
41
+ * @param identityEndpoint - The IMDS endpoint to use.
42
+ */
33
43
  constructor(
34
44
  logger: Logger,
35
45
  nodeStorage: NodeStorage,
@@ -49,6 +59,18 @@ export class Imds extends BaseManagedIdentitySource {
49
59
  this.identityEndpoint = identityEndpoint;
50
60
  }
51
61
 
62
+ /**
63
+ * Attempts to create an Imds instance by determining the correct endpoint.
64
+ * If the AZURE_POD_IDENTITY_AUTHORITY_HOST environment variable is set, it uses that as the endpoint.
65
+ * Otherwise, it falls back to the default IMDS endpoint.
66
+ *
67
+ * @param logger - Logger instance for logging.
68
+ * @param nodeStorage - NodeStorage instance for caching.
69
+ * @param networkClient - Network client for HTTP requests.
70
+ * @param cryptoProvider - CryptoProvider for cryptographic operations.
71
+ * @param disableInternalRetries - Whether to disable internal retry logic.
72
+ * @returns An instance of Imds configured with the appropriate endpoint.
73
+ */
52
74
  public static tryCreate(
53
75
  logger: Logger,
54
76
  nodeStorage: NodeStorage,
@@ -102,6 +124,14 @@ export class Imds extends BaseManagedIdentitySource {
102
124
  );
103
125
  }
104
126
 
127
+ /**
128
+ * Creates a ManagedIdentityRequestParameters object for acquiring a token from IMDS.
129
+ * Sets the required headers and query parameters for the IMDS token request.
130
+ *
131
+ * @param resource - The resource URI for which the token is requested.
132
+ * @param managedIdentityId - The managed identity ID (system-assigned or user-assigned).
133
+ * @returns A ManagedIdentityRequestParameters object configured for IMDS.
134
+ */
105
135
  public createRequest(
106
136
  resource: string,
107
137
  managedIdentityId: ManagedIdentityId
@@ -112,11 +142,11 @@ export class Imds extends BaseManagedIdentitySource {
112
142
  this.identityEndpoint
113
143
  );
114
144
 
115
- request.headers[METADATA_HEADER_NAME] = "true";
145
+ request.headers[ManagedIdentityHeaders.METADATA_HEADER_NAME] = "true";
116
146
 
117
- request.queryParameters[API_VERSION_QUERY_PARAMETER_NAME] =
147
+ request.queryParameters[ManagedIdentityQueryParameters.API_VERSION] =
118
148
  IMDS_API_VERSION;
119
- request.queryParameters[RESOURCE_BODY_OR_QUERY_PARAMETER_NAME] =
149
+ request.queryParameters[ManagedIdentityQueryParameters.RESOURCE] =
120
150
  resource;
121
151
 
122
152
  if (
@@ -130,7 +160,7 @@ export class Imds extends BaseManagedIdentitySource {
130
160
  ] = managedIdentityId.id;
131
161
  }
132
162
 
133
- // bodyParameters calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity
163
+ // The bodyParameters are calculated in BaseManagedIdentity.acquireTokenWithManagedIdentity.
134
164
 
135
165
  request.retryPolicy = new ImdsRetryPolicy();
136
166
 
@@ -7,13 +7,11 @@ import { INetworkModule, Logger } from "@azure/msal-common/node";
7
7
  import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource.js";
8
8
  import {
9
9
  HttpMethod,
10
- API_VERSION_QUERY_PARAMETER_NAME,
11
- RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
12
10
  ManagedIdentityEnvironmentVariableNames,
13
11
  ManagedIdentitySourceNames,
14
12
  ManagedIdentityIdType,
15
- METADATA_HEADER_NAME,
16
- ML_AND_SF_SECRET_HEADER_NAME,
13
+ ManagedIdentityQueryParameters,
14
+ ManagedIdentityHeaders,
17
15
  } from "../../utils/Constants.js";
18
16
  import { CryptoProvider } from "../../crypto/CryptoProvider.js";
19
17
  import { ManagedIdentityRequestParameters } from "../../config/ManagedIdentityRequestParameters.js";
@@ -107,12 +105,13 @@ export class MachineLearning extends BaseManagedIdentitySource {
107
105
  this.msiEndpoint
108
106
  );
109
107
 
110
- request.headers[METADATA_HEADER_NAME] = "true";
111
- request.headers[ML_AND_SF_SECRET_HEADER_NAME] = this.secret;
108
+ request.headers[ManagedIdentityHeaders.METADATA_HEADER_NAME] = "true";
109
+ request.headers[ManagedIdentityHeaders.ML_AND_SF_SECRET_HEADER_NAME] =
110
+ this.secret;
112
111
 
113
- request.queryParameters[API_VERSION_QUERY_PARAMETER_NAME] =
112
+ request.queryParameters[ManagedIdentityQueryParameters.API_VERSION] =
114
113
  MACHINE_LEARNING_MSI_API_VERSION;
115
- request.queryParameters[RESOURCE_BODY_OR_QUERY_PARAMETER_NAME] =
114
+ request.queryParameters[ManagedIdentityQueryParameters.RESOURCE] =
116
115
  resource;
117
116
 
118
117
  if (
@@ -10,16 +10,14 @@ import { BaseManagedIdentitySource } from "./BaseManagedIdentitySource.js";
10
10
  import { NodeStorage } from "../../cache/NodeStorage.js";
11
11
  import { CryptoProvider } from "../../crypto/CryptoProvider.js";
12
12
  import {
13
- API_VERSION_QUERY_PARAMETER_NAME,
14
13
  HttpMethod,
15
14
  ManagedIdentityEnvironmentVariableNames,
16
15
  ManagedIdentityIdType,
17
16
  ManagedIdentitySourceNames,
18
- RESOURCE_BODY_OR_QUERY_PARAMETER_NAME,
19
- ML_AND_SF_SECRET_HEADER_NAME,
17
+ ManagedIdentityQueryParameters,
18
+ ManagedIdentityHeaders,
20
19
  } from "../../utils/Constants.js";
21
20
 
22
- // MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
23
21
  const SERVICE_FABRIC_MSI_API_VERSION: string = "2019-07-01-preview";
24
22
 
25
23
  /**
@@ -29,6 +27,16 @@ export class ServiceFabric extends BaseManagedIdentitySource {
29
27
  private identityEndpoint: string;
30
28
  private identityHeader: string;
31
29
 
30
+ /**
31
+ * Constructs a new ServiceFabric managed identity source.
32
+ * @param logger Logger instance for logging
33
+ * @param nodeStorage NodeStorage instance for caching
34
+ * @param networkClient Network client for HTTP requests
35
+ * @param cryptoProvider Crypto provider for cryptographic operations
36
+ * @param disableInternalRetries Whether to disable internal retry logic
37
+ * @param identityEndpoint The Service Fabric managed identity endpoint
38
+ * @param identityHeader The Service Fabric managed identity secret header
39
+ */
32
40
  constructor(
33
41
  logger: Logger,
34
42
  nodeStorage: NodeStorage,
@@ -50,6 +58,10 @@ export class ServiceFabric extends BaseManagedIdentitySource {
50
58
  this.identityHeader = identityHeader;
51
59
  }
52
60
 
61
+ /**
62
+ * Retrieves the environment variables required for Service Fabric managed identity.
63
+ * @returns An array containing the identity endpoint, identity header, and identity server thumbprint.
64
+ */
53
65
  public static getEnvironmentVariables(): Array<string | undefined> {
54
66
  const identityEndpoint: string | undefined =
55
67
  process.env[
@@ -68,6 +80,16 @@ export class ServiceFabric extends BaseManagedIdentitySource {
68
80
  return [identityEndpoint, identityHeader, identityServerThumbprint];
69
81
  }
70
82
 
83
+ /**
84
+ * Attempts to create a ServiceFabric managed identity source if all required environment variables are present.
85
+ * @param logger Logger instance for logging
86
+ * @param nodeStorage NodeStorage instance for caching
87
+ * @param networkClient Network client for HTTP requests
88
+ * @param cryptoProvider Crypto provider for cryptographic operations
89
+ * @param disableInternalRetries Whether to disable internal retry logic
90
+ * @param managedIdentityId Managed identity identifier
91
+ * @returns A ServiceFabric instance if environment variables are set, otherwise null
92
+ */
71
93
  public static tryCreate(
72
94
  logger: Logger,
73
95
  nodeStorage: NodeStorage,
@@ -79,10 +101,6 @@ export class ServiceFabric extends BaseManagedIdentitySource {
79
101
  const [identityEndpoint, identityHeader, identityServerThumbprint] =
80
102
  ServiceFabric.getEnvironmentVariables();
81
103
 
82
- /*
83
- * if either of the identity endpoint, identity header, or identity server thumbprint
84
- * environment variables are undefined, this MSI provider is unavailable.
85
- */
86
104
  if (!identityEndpoint || !identityHeader || !identityServerThumbprint) {
87
105
  logger.info(
88
106
  `[Managed Identity] ${ManagedIdentitySourceNames.SERVICE_FABRIC} managed identity is unavailable because one or all of the '${ManagedIdentityEnvironmentVariableNames.IDENTITY_HEADER}', '${ManagedIdentityEnvironmentVariableNames.IDENTITY_ENDPOINT}' or '${ManagedIdentityEnvironmentVariableNames.IDENTITY_SERVER_THUMBPRINT}' environment variables are not defined.`
@@ -121,6 +139,12 @@ export class ServiceFabric extends BaseManagedIdentitySource {
121
139
  );
122
140
  }
123
141
 
142
+ /**
143
+ * Creates the request parameters for acquiring a token from the Service Fabric cluster.
144
+ * @param resource - The resource URI for which the token is requested.
145
+ * @param managedIdentityId - The managed identity ID (system-assigned or user-assigned).
146
+ * @returns A ManagedIdentityRequestParameters object configured for Service Fabric.
147
+ */
124
148
  public createRequest(
125
149
  resource: string,
126
150
  managedIdentityId: ManagedIdentityId
@@ -131,11 +155,12 @@ export class ServiceFabric extends BaseManagedIdentitySource {
131
155
  this.identityEndpoint
132
156
  );
133
157
 
134
- request.headers[ML_AND_SF_SECRET_HEADER_NAME] = this.identityHeader;
158
+ request.headers[ManagedIdentityHeaders.ML_AND_SF_SECRET_HEADER_NAME] =
159
+ this.identityHeader;
135
160
 
136
- request.queryParameters[API_VERSION_QUERY_PARAMETER_NAME] =
161
+ request.queryParameters[ManagedIdentityQueryParameters.API_VERSION] =
137
162
  SERVICE_FABRIC_MSI_API_VERSION;
138
- request.queryParameters[RESOURCE_BODY_OR_QUERY_PARAMETER_NAME] =
163
+ request.queryParameters[ManagedIdentityQueryParameters.RESOURCE] =
139
164
  resource;
140
165
 
141
166
  if (
@@ -134,6 +134,7 @@ export type ManagedIdentityIdParams = {
134
134
 
135
135
  /** @public */
136
136
  export type ManagedIdentityConfiguration = {
137
+ clientCapabilities?: Array<string>;
137
138
  managedIdentityIdParams?: ManagedIdentityIdParams;
138
139
  system?: NodeSystemOptions;
139
140
  };
@@ -246,14 +247,16 @@ export function buildAppConfiguration({
246
247
 
247
248
  /** @internal */
248
249
  export type ManagedIdentityNodeConfiguration = {
250
+ clientCapabilities?: Array<string>;
251
+ disableInternalRetries: boolean;
249
252
  managedIdentityId: ManagedIdentityId;
250
253
  system: Required<
251
254
  Pick<NodeSystemOptions, "loggerOptions" | "networkClient">
252
255
  >;
253
- disableInternalRetries: boolean;
254
256
  };
255
257
 
256
258
  export function buildManagedIdentityConfiguration({
259
+ clientCapabilities,
257
260
  managedIdentityIdParams,
258
261
  system,
259
262
  }: ManagedIdentityConfiguration): ManagedIdentityNodeConfiguration {
@@ -277,6 +280,7 @@ export function buildManagedIdentityConfiguration({
277
280
  }
278
281
 
279
282
  return {
283
+ clientCapabilities: clientCapabilities || [],
280
284
  managedIdentityId: managedIdentityId,
281
285
  system: {
282
286
  loggerOptions,
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { ICrypto, PkceCodes } from "@azure/msal-common/node";
6
+ import { EncodingTypes, ICrypto, PkceCodes } from "@azure/msal-common/node";
7
7
  import { GuidGenerator } from "./GuidGenerator.js";
8
8
  import { EncodingUtils } from "../utils/EncodingUtils.js";
9
9
  import { PkceGenerator } from "./PkceGenerator.js";
@@ -106,8 +106,8 @@ export class CryptoProvider implements ICrypto {
106
106
  */
107
107
  async hashString(plainText: string): Promise<string> {
108
108
  return EncodingUtils.base64EncodeUrl(
109
- this.hashUtils.sha256(plainText).toString("base64"),
110
- "base64"
109
+ this.hashUtils.sha256(plainText).toString(EncodingTypes.BASE64),
110
+ EncodingTypes.BASE64
111
111
  );
112
112
  }
113
113
  }
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { Constants, PkceCodes } from "@azure/msal-common/node";
6
+ import { Constants, EncodingTypes, PkceCodes } from "@azure/msal-common/node";
7
7
  import { CharSet, RANDOM_OCTET_SIZE } from "../utils/Constants.js";
8
8
  import { EncodingUtils } from "../utils/EncodingUtils.js";
9
9
  import { HashUtils } from "./HashUtils.js";
@@ -56,8 +56,8 @@ export class PkceGenerator {
56
56
  */
57
57
  private generateCodeChallengeFromVerifier(codeVerifier: string): string {
58
58
  return EncodingUtils.base64EncodeUrl(
59
- this.hashUtils.sha256(codeVerifier).toString("base64"),
60
- "base64"
59
+ this.hashUtils.sha256(codeVerifier).toString(EncodingTypes.BASE64),
60
+ EncodingTypes.BASE64
61
61
  );
62
62
  }
63
63
  }
@@ -1,3 +1,3 @@
1
1
  /* eslint-disable header/header */
2
2
  export const name = "@azure/msal-node";
3
- export const version = "3.5.2";
3
+ export const version = "3.6.0";
@@ -8,8 +8,11 @@ import { ManagedIdentityRequestParams } from "./ManagedIdentityRequestParams.js"
8
8
 
9
9
  /**
10
10
  * ManagedIdentityRequest
11
- * - forceRefresh - forces managed identity requests to skip the cache and make network calls if true
12
- * - resource - resource requested to access the protected API. It should be of the form "{ResourceIdUri}" or {ResourceIdUri/.default}. For instance https://management.azure.net or, for Microsoft Graph, https://graph.microsoft.com/.default
11
+ * - clientCapabilities - an array of capabilities to be added to all network requests as part of the `xms_cc` claim
12
+ * - revokedTokenSha256Hash - a SHA256 hash of the token that was revoked. The managed identity will revoke the token based on the SHA256 hash of the token, not the token itself. This is to prevent the token from being leaked in transit.
13
13
  */
14
14
  export type ManagedIdentityRequest = ManagedIdentityRequestParams &
15
- CommonClientCredentialRequest;
15
+ CommonClientCredentialRequest & {
16
+ clientCapabilities?: Array<string>;
17
+ revokedTokenSha256Hash?: string;
18
+ };
@@ -8,7 +8,7 @@ import { HttpStatus, Logger } from "@azure/msal-common";
8
8
  import { IHttpRetryPolicy } from "./IHttpRetryPolicy.js";
9
9
  import { LinearRetryStrategy } from "./LinearRetryStrategy.js";
10
10
 
11
- const DEFAULT_MANAGED_IDENTITY_MAX_RETRIES: number = 3;
11
+ export const DEFAULT_MANAGED_IDENTITY_MAX_RETRIES: number = 3; // referenced in unit test
12
12
  const DEFAULT_MANAGED_IDENTITY_RETRY_DELAY_MS: number = 1000;
13
13
  const DEFAULT_MANAGED_IDENTITY_HTTP_STATUS_CODES_TO_RETRY_ON: Array<number> = [
14
14
  HttpStatus.NOT_FOUND,
@@ -8,16 +8,34 @@ import { DefaultManagedIdentityRetryPolicy } from "../retry/DefaultManagedIdenti
8
8
  import { ImdsRetryPolicy } from "../retry/ImdsRetryPolicy.js";
9
9
 
10
10
  // MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
11
- export const AUTHORIZATION_HEADER_NAME: string = "Authorization";
12
- export const METADATA_HEADER_NAME: string = "Metadata";
13
- export const APP_SERVICE_SECRET_HEADER_NAME: string = "X-IDENTITY-HEADER";
14
- export const ML_AND_SF_SECRET_HEADER_NAME: string = "secret";
15
- export const API_VERSION_QUERY_PARAMETER_NAME: string = "api-version";
16
- export const RESOURCE_BODY_OR_QUERY_PARAMETER_NAME: string = "resource";
17
11
  export const DEFAULT_MANAGED_IDENTITY_ID = "system_assigned_managed_identity";
18
12
  export const MANAGED_IDENTITY_DEFAULT_TENANT = "managed_identity";
19
13
  export const DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY = `https://login.microsoftonline.com/${MANAGED_IDENTITY_DEFAULT_TENANT}/`;
20
14
 
15
+ /**
16
+ * Managed Identity Headers - used in network requests
17
+ */
18
+ export const ManagedIdentityHeaders = {
19
+ AUTHORIZATION_HEADER_NAME: "Authorization",
20
+ METADATA_HEADER_NAME: "Metadata",
21
+ APP_SERVICE_SECRET_HEADER_NAME: "X-IDENTITY-HEADER",
22
+ ML_AND_SF_SECRET_HEADER_NAME: "secret",
23
+ } as const;
24
+ export type ManagedIdentityHeaders =
25
+ (typeof ManagedIdentityHeaders)[keyof typeof ManagedIdentityHeaders];
26
+
27
+ /**
28
+ * Managed Identity Query Parameters - used in network requests
29
+ */
30
+ export const ManagedIdentityQueryParameters = {
31
+ API_VERSION: "api-version",
32
+ RESOURCE: "resource",
33
+ SHA256_TOKEN_TO_REFRESH: "token_sha256_to_refresh",
34
+ XMS_CC: "xms_cc",
35
+ } as const;
36
+ export type ManagedIdentityQueryParameters =
37
+ (typeof ManagedIdentityQueryParameters)[keyof typeof ManagedIdentityQueryParameters];
38
+
21
39
  /**
22
40
  * Managed Identity Environment Variable Names
23
41
  */
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { Constants } from "@azure/msal-common/node";
6
+ import { Constants, EncodingTypes } from "@azure/msal-common/node";
7
7
 
8
8
  export class EncodingUtils {
9
9
  /**
@@ -13,7 +13,7 @@ export class EncodingUtils {
13
13
  * @param str text
14
14
  */
15
15
  static base64Encode(str: string, encoding?: BufferEncoding): string {
16
- return Buffer.from(str, encoding).toString("base64");
16
+ return Buffer.from(str, encoding).toString(EncodingTypes.BASE64);
17
17
  }
18
18
 
19
19
  /**
@@ -34,7 +34,7 @@ export class EncodingUtils {
34
34
  * @param base64Str Base64 encoded text
35
35
  */
36
36
  static base64Decode(base64Str: string): string {
37
- return Buffer.from(base64Str, "base64").toString("utf8");
37
+ return Buffer.from(base64Str, EncodingTypes.BASE64).toString("utf8");
38
38
  }
39
39
 
40
40
  /**