@azure/msal-node 2.7.0-alpha.0 → 2.7.1-alpha.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 (245) hide show
  1. package/README.md +1 -1
  2. package/dist/cache/ITokenCache.d.ts +15 -15
  3. package/dist/cache/NodeStorage.cjs +423 -423
  4. package/dist/cache/NodeStorage.cjs.map +1 -1
  5. package/dist/cache/NodeStorage.d.ts +193 -193
  6. package/dist/cache/NodeStorage.d.ts.map +1 -1
  7. package/dist/cache/NodeStorage.mjs +424 -424
  8. package/dist/cache/NodeStorage.mjs.map +1 -1
  9. package/dist/cache/TokenCache.cjs +265 -265
  10. package/dist/cache/TokenCache.d.ts +90 -90
  11. package/dist/cache/TokenCache.mjs +265 -265
  12. package/dist/cache/distributed/DistributedCachePlugin.cjs +26 -26
  13. package/dist/cache/distributed/DistributedCachePlugin.d.ts +10 -10
  14. package/dist/cache/distributed/DistributedCachePlugin.mjs +26 -26
  15. package/dist/cache/distributed/ICacheClient.d.ts +17 -17
  16. package/dist/cache/distributed/IPartitionManager.d.ts +28 -28
  17. package/dist/cache/serializer/Deserializer.cjs +167 -170
  18. package/dist/cache/serializer/Deserializer.cjs.map +1 -1
  19. package/dist/cache/serializer/Deserializer.d.ts +42 -42
  20. package/dist/cache/serializer/Deserializer.d.ts.map +1 -1
  21. package/dist/cache/serializer/Deserializer.mjs +168 -171
  22. package/dist/cache/serializer/Deserializer.mjs.map +1 -1
  23. package/dist/cache/serializer/Serializer.cjs +137 -137
  24. package/dist/cache/serializer/Serializer.d.ts +39 -39
  25. package/dist/cache/serializer/Serializer.mjs +137 -137
  26. package/dist/cache/serializer/SerializerTypes.d.ts +102 -102
  27. package/dist/client/ClientApplication.cjs +335 -333
  28. package/dist/client/ClientApplication.cjs.map +1 -1
  29. package/dist/client/ClientApplication.d.ts +143 -142
  30. package/dist/client/ClientApplication.d.ts.map +1 -1
  31. package/dist/client/ClientApplication.mjs +336 -334
  32. package/dist/client/ClientApplication.mjs.map +1 -1
  33. package/dist/client/ClientAssertion.cjs +116 -116
  34. package/dist/client/ClientAssertion.d.ts +46 -46
  35. package/dist/client/ClientAssertion.mjs +116 -116
  36. package/dist/client/ClientCredentialClient.cjs +194 -194
  37. package/dist/client/ClientCredentialClient.cjs.map +1 -1
  38. package/dist/client/ClientCredentialClient.d.ts +33 -33
  39. package/dist/client/ClientCredentialClient.d.ts.map +1 -1
  40. package/dist/client/ClientCredentialClient.mjs +195 -195
  41. package/dist/client/ClientCredentialClient.mjs.map +1 -1
  42. package/dist/client/ConfidentialClientApplication.cjs +166 -163
  43. package/dist/client/ConfidentialClientApplication.cjs.map +1 -1
  44. package/dist/client/ConfidentialClientApplication.d.ts +58 -58
  45. package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
  46. package/dist/client/ConfidentialClientApplication.mjs +168 -165
  47. package/dist/client/ConfidentialClientApplication.mjs.map +1 -1
  48. package/dist/client/DeviceCodeClient.cjs +207 -207
  49. package/dist/client/DeviceCodeClient.d.ts +53 -53
  50. package/dist/client/DeviceCodeClient.mjs +207 -207
  51. package/dist/client/IConfidentialClientApplication.d.ts +39 -39
  52. package/dist/client/IPublicClientApplication.d.ts +42 -42
  53. package/dist/client/ManagedIdentityApplication.cjs +75 -80
  54. package/dist/client/ManagedIdentityApplication.cjs.map +1 -1
  55. package/dist/client/ManagedIdentityApplication.d.ts +23 -23
  56. package/dist/client/ManagedIdentityApplication.d.ts.map +1 -1
  57. package/dist/client/ManagedIdentityApplication.mjs +76 -81
  58. package/dist/client/ManagedIdentityApplication.mjs.map +1 -1
  59. package/dist/client/ManagedIdentityClient.cjs +40 -36
  60. package/dist/client/ManagedIdentityClient.cjs.map +1 -1
  61. package/dist/client/ManagedIdentityClient.d.ts +19 -24
  62. package/dist/client/ManagedIdentityClient.d.ts.map +1 -1
  63. package/dist/client/ManagedIdentityClient.mjs +40 -36
  64. package/dist/client/ManagedIdentityClient.mjs.map +1 -1
  65. package/dist/client/ManagedIdentitySources/AppService.cjs +42 -69
  66. package/dist/client/ManagedIdentitySources/AppService.cjs.map +1 -1
  67. package/dist/client/ManagedIdentitySources/AppService.d.ts +16 -16
  68. package/dist/client/ManagedIdentitySources/AppService.d.ts.map +1 -1
  69. package/dist/client/ManagedIdentitySources/AppService.mjs +43 -70
  70. package/dist/client/ManagedIdentitySources/AppService.mjs.map +1 -1
  71. package/dist/client/ManagedIdentitySources/AzureArc.cjs +81 -92
  72. package/dist/client/ManagedIdentitySources/AzureArc.cjs.map +1 -1
  73. package/dist/client/ManagedIdentitySources/AzureArc.d.ts +18 -18
  74. package/dist/client/ManagedIdentitySources/AzureArc.d.ts.map +1 -1
  75. package/dist/client/ManagedIdentitySources/AzureArc.mjs +84 -95
  76. package/dist/client/ManagedIdentitySources/AzureArc.mjs.map +1 -1
  77. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs +116 -77
  78. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.cjs.map +1 -1
  79. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts +30 -18
  80. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.d.ts.map +1 -1
  81. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs +118 -80
  82. package/dist/client/ManagedIdentitySources/BaseManagedIdentitySource.mjs.map +1 -1
  83. package/dist/client/ManagedIdentitySources/CloudShell.cjs +47 -0
  84. package/dist/client/ManagedIdentitySources/CloudShell.cjs.map +1 -0
  85. package/dist/client/ManagedIdentitySources/CloudShell.d.ts +15 -6
  86. package/dist/client/ManagedIdentitySources/CloudShell.d.ts.map +1 -1
  87. package/dist/client/ManagedIdentitySources/CloudShell.mjs +45 -0
  88. package/dist/client/ManagedIdentitySources/CloudShell.mjs.map +1 -0
  89. package/dist/client/ManagedIdentitySources/Imds.cjs +43 -52
  90. package/dist/client/ManagedIdentitySources/Imds.cjs.map +1 -1
  91. package/dist/client/ManagedIdentitySources/Imds.d.ts +12 -12
  92. package/dist/client/ManagedIdentitySources/Imds.d.ts.map +1 -1
  93. package/dist/client/ManagedIdentitySources/Imds.mjs +44 -53
  94. package/dist/client/ManagedIdentitySources/Imds.mjs.map +1 -1
  95. package/dist/client/ManagedIdentitySources/ServiceFabric.cjs +61 -0
  96. package/dist/client/ManagedIdentitySources/ServiceFabric.cjs.map +1 -0
  97. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts +16 -6
  98. package/dist/client/ManagedIdentitySources/ServiceFabric.d.ts.map +1 -1
  99. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs +59 -0
  100. package/dist/client/ManagedIdentitySources/ServiceFabric.mjs.map +1 -0
  101. package/dist/client/OnBehalfOfClient.cjs +202 -202
  102. package/dist/client/OnBehalfOfClient.cjs.map +1 -1
  103. package/dist/client/OnBehalfOfClient.d.ts +47 -47
  104. package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
  105. package/dist/client/OnBehalfOfClient.mjs +203 -203
  106. package/dist/client/OnBehalfOfClient.mjs.map +1 -1
  107. package/dist/client/PublicClientApplication.cjs +229 -229
  108. package/dist/client/PublicClientApplication.d.ts +71 -71
  109. package/dist/client/PublicClientApplication.mjs +229 -229
  110. package/dist/client/UsernamePasswordClient.cjs +95 -95
  111. package/dist/client/UsernamePasswordClient.cjs.map +1 -1
  112. package/dist/client/UsernamePasswordClient.d.ts +25 -25
  113. package/dist/client/UsernamePasswordClient.d.ts.map +1 -1
  114. package/dist/client/UsernamePasswordClient.mjs +96 -96
  115. package/dist/client/UsernamePasswordClient.mjs.map +1 -1
  116. package/dist/config/Configuration.cjs +102 -86
  117. package/dist/config/Configuration.cjs.map +1 -1
  118. package/dist/config/Configuration.d.ts +126 -122
  119. package/dist/config/Configuration.d.ts.map +1 -1
  120. package/dist/config/Configuration.mjs +102 -86
  121. package/dist/config/Configuration.mjs.map +1 -1
  122. package/dist/config/ManagedIdentityId.cjs +48 -48
  123. package/dist/config/ManagedIdentityId.d.ts +11 -11
  124. package/dist/config/ManagedIdentityId.mjs +48 -48
  125. package/dist/config/ManagedIdentityRequestParameters.cjs +28 -29
  126. package/dist/config/ManagedIdentityRequestParameters.cjs.map +1 -1
  127. package/dist/config/ManagedIdentityRequestParameters.d.ts +11 -11
  128. package/dist/config/ManagedIdentityRequestParameters.d.ts.map +1 -1
  129. package/dist/config/ManagedIdentityRequestParameters.mjs +28 -29
  130. package/dist/config/ManagedIdentityRequestParameters.mjs.map +1 -1
  131. package/dist/crypto/CryptoProvider.cjs +75 -75
  132. package/dist/crypto/CryptoProvider.d.ts +52 -52
  133. package/dist/crypto/CryptoProvider.mjs +75 -75
  134. package/dist/crypto/GuidGenerator.cjs +22 -22
  135. package/dist/crypto/GuidGenerator.d.ts +14 -14
  136. package/dist/crypto/GuidGenerator.mjs +22 -22
  137. package/dist/crypto/HashUtils.cjs +13 -13
  138. package/dist/crypto/HashUtils.d.ts +8 -8
  139. package/dist/crypto/HashUtils.mjs +13 -13
  140. package/dist/crypto/PkceGenerator.cjs +49 -49
  141. package/dist/crypto/PkceGenerator.d.ts +22 -22
  142. package/dist/crypto/PkceGenerator.mjs +49 -49
  143. package/dist/error/ManagedIdentityError.cjs +38 -28
  144. package/dist/error/ManagedIdentityError.cjs.map +1 -1
  145. package/dist/error/ManagedIdentityError.d.ts +26 -21
  146. package/dist/error/ManagedIdentityError.d.ts.map +1 -1
  147. package/dist/error/ManagedIdentityError.mjs +39 -29
  148. package/dist/error/ManagedIdentityError.mjs.map +1 -1
  149. package/dist/error/ManagedIdentityErrorCodes.cjs +26 -15
  150. package/dist/error/ManagedIdentityErrorCodes.cjs.map +1 -1
  151. package/dist/error/ManagedIdentityErrorCodes.d.ts +18 -9
  152. package/dist/error/ManagedIdentityErrorCodes.d.ts.map +1 -1
  153. package/dist/error/ManagedIdentityErrorCodes.mjs +23 -14
  154. package/dist/error/ManagedIdentityErrorCodes.mjs.map +1 -1
  155. package/dist/error/NodeAuthError.cjs +85 -85
  156. package/dist/error/NodeAuthError.d.ts +65 -65
  157. package/dist/error/NodeAuthError.mjs +85 -85
  158. package/dist/index.cjs +21 -21
  159. package/dist/index.d.ts +44 -44
  160. package/dist/index.d.ts.map +1 -1
  161. package/dist/index.mjs +1 -1
  162. package/dist/internals.cjs +8 -8
  163. package/dist/internals.d.ts +6 -6
  164. package/dist/internals.mjs +8 -8
  165. package/dist/network/HttpClient.cjs +281 -283
  166. package/dist/network/HttpClient.cjs.map +1 -1
  167. package/dist/network/HttpClient.d.ts +25 -26
  168. package/dist/network/HttpClient.d.ts.map +1 -1
  169. package/dist/network/HttpClient.mjs +281 -283
  170. package/dist/network/HttpClient.mjs.map +1 -1
  171. package/dist/network/HttpClientWithRetries.cjs +44 -0
  172. package/dist/network/HttpClientWithRetries.cjs.map +1 -0
  173. package/dist/network/HttpClientWithRetries.d.ts +12 -0
  174. package/dist/network/HttpClientWithRetries.d.ts.map +1 -0
  175. package/dist/network/HttpClientWithRetries.mjs +42 -0
  176. package/dist/network/HttpClientWithRetries.mjs.map +1 -0
  177. package/dist/network/ILoopbackClient.d.ts +10 -10
  178. package/dist/network/LoopbackClient.cjs +77 -77
  179. package/dist/network/LoopbackClient.d.ts +21 -21
  180. package/dist/network/LoopbackClient.mjs +77 -77
  181. package/dist/packageMetadata.cjs +4 -4
  182. package/dist/packageMetadata.d.ts +2 -2
  183. package/dist/packageMetadata.mjs +4 -4
  184. package/dist/request/AuthorizationCodeRequest.d.ts +21 -21
  185. package/dist/request/AuthorizationUrlRequest.d.ts +33 -33
  186. package/dist/request/ClientCredentialRequest.d.ts +14 -14
  187. package/dist/request/ClientCredentialRequest.d.ts.map +1 -1
  188. package/dist/request/DeviceCodeRequest.d.ts +15 -15
  189. package/dist/request/InteractiveRequest.d.ts +22 -22
  190. package/dist/request/ManagedIdentityRequest.d.ts +8 -8
  191. package/dist/request/ManagedIdentityRequestParams.d.ts +9 -9
  192. package/dist/request/OnBehalfOfRequest.d.ts +14 -14
  193. package/dist/request/RefreshTokenRequest.d.ts +17 -17
  194. package/dist/request/SignOutRequest.d.ts +5 -5
  195. package/dist/request/SilentFlowRequest.d.ts +16 -16
  196. package/dist/request/UsernamePasswordRequest.d.ts +19 -19
  197. package/dist/response/ManagedIdentityTokenResponse.d.ts +24 -24
  198. package/dist/retry/IHttpRetryPolicy.d.ts +6 -0
  199. package/dist/retry/IHttpRetryPolicy.d.ts.map +1 -0
  200. package/dist/retry/LinearRetryPolicy.cjs +47 -0
  201. package/dist/retry/LinearRetryPolicy.cjs.map +1 -0
  202. package/dist/retry/LinearRetryPolicy.d.ts +12 -0
  203. package/dist/retry/LinearRetryPolicy.d.ts.map +1 -0
  204. package/dist/retry/LinearRetryPolicy.mjs +45 -0
  205. package/dist/retry/LinearRetryPolicy.mjs.map +1 -0
  206. package/dist/utils/Constants.cjs +142 -103
  207. package/dist/utils/Constants.cjs.map +1 -1
  208. package/dist/utils/Constants.d.ts +132 -106
  209. package/dist/utils/Constants.d.ts.map +1 -1
  210. package/dist/utils/Constants.mjs +134 -100
  211. package/dist/utils/Constants.mjs.map +1 -1
  212. package/dist/utils/EncodingUtils.cjs +44 -44
  213. package/dist/utils/EncodingUtils.d.ts +26 -26
  214. package/dist/utils/EncodingUtils.mjs +44 -44
  215. package/dist/utils/NetworkUtils.cjs +38 -38
  216. package/dist/utils/NetworkUtils.d.ts +5 -5
  217. package/dist/utils/NetworkUtils.mjs +38 -38
  218. package/package.json +5 -5
  219. package/src/cache/NodeStorage.ts +4 -9
  220. package/src/cache/serializer/Deserializer.ts +1 -5
  221. package/src/client/ClientApplication.ts +24 -10
  222. package/src/client/ClientCredentialClient.ts +14 -6
  223. package/src/client/ConfidentialClientApplication.ts +10 -5
  224. package/src/client/ManagedIdentityApplication.ts +8 -16
  225. package/src/client/ManagedIdentityClient.ts +23 -11
  226. package/src/client/ManagedIdentitySources/AppService.ts +68 -97
  227. package/src/client/ManagedIdentitySources/AzureArc.ts +59 -68
  228. package/src/client/ManagedIdentitySources/BaseManagedIdentitySource.ts +82 -11
  229. package/src/client/ManagedIdentitySources/CloudShell.ts +93 -8
  230. package/src/client/ManagedIdentitySources/Imds.ts +54 -40
  231. package/src/client/ManagedIdentitySources/ServiceFabric.ts +126 -5
  232. package/src/client/OnBehalfOfClient.ts +18 -7
  233. package/src/client/UsernamePasswordClient.ts +16 -7
  234. package/src/config/Configuration.ts +50 -18
  235. package/src/config/ManagedIdentityRequestParameters.ts +1 -6
  236. package/src/error/ManagedIdentityError.ts +15 -4
  237. package/src/error/ManagedIdentityErrorCodes.ts +19 -1
  238. package/src/index.ts +1 -0
  239. package/src/network/HttpClient.ts +27 -39
  240. package/src/network/HttpClientWithRetries.ts +80 -0
  241. package/src/packageMetadata.ts +1 -1
  242. package/src/request/ClientCredentialRequest.ts +6 -3
  243. package/src/retry/IHttpRetryPolicy.ts +18 -0
  244. package/src/retry/LinearRetryPolicy.ts +71 -0
  245. package/src/utils/Constants.ts +47 -10
@@ -20,16 +20,13 @@ import https from "https";
20
20
  export class HttpClient implements INetworkModule {
21
21
  private proxyUrl: string;
22
22
  private customAgentOptions: http.AgentOptions | https.AgentOptions;
23
- private managedIdentity: boolean;
24
23
 
25
24
  constructor(
26
25
  proxyUrl?: string,
27
- customAgentOptions?: http.AgentOptions | https.AgentOptions,
28
- managedIdentity?: boolean
26
+ customAgentOptions?: http.AgentOptions | https.AgentOptions
29
27
  ) {
30
28
  this.proxyUrl = proxyUrl || "";
31
29
  this.customAgentOptions = customAgentOptions || {};
32
- this.managedIdentity = managedIdentity || false;
33
30
  }
34
31
 
35
32
  /**
@@ -39,7 +36,8 @@ export class HttpClient implements INetworkModule {
39
36
  */
40
37
  async sendGetRequestAsync<T>(
41
38
  url: string,
42
- options?: NetworkRequestOptions
39
+ options?: NetworkRequestOptions,
40
+ timeout?: number
43
41
  ): Promise<NetworkResponse<T>> {
44
42
  if (this.proxyUrl) {
45
43
  return networkRequestViaProxy(
@@ -47,7 +45,8 @@ export class HttpClient implements INetworkModule {
47
45
  this.proxyUrl,
48
46
  HttpMethod.GET,
49
47
  options,
50
- this.customAgentOptions as http.AgentOptions
48
+ this.customAgentOptions as http.AgentOptions,
49
+ timeout
51
50
  );
52
51
  } else {
53
52
  return networkRequestViaHttps(
@@ -55,8 +54,7 @@ export class HttpClient implements INetworkModule {
55
54
  HttpMethod.GET,
56
55
  options,
57
56
  this.customAgentOptions as https.AgentOptions,
58
- undefined,
59
- this.managedIdentity
57
+ timeout
60
58
  );
61
59
  }
62
60
  }
@@ -68,8 +66,7 @@ export class HttpClient implements INetworkModule {
68
66
  */
69
67
  async sendPostRequestAsync<T>(
70
68
  url: string,
71
- options?: NetworkRequestOptions,
72
- cancellationToken?: number
69
+ options?: NetworkRequestOptions
73
70
  ): Promise<NetworkResponse<T>> {
74
71
  if (this.proxyUrl) {
75
72
  return networkRequestViaProxy(
@@ -77,17 +74,14 @@ export class HttpClient implements INetworkModule {
77
74
  this.proxyUrl,
78
75
  HttpMethod.POST,
79
76
  options,
80
- this.customAgentOptions as http.AgentOptions,
81
- cancellationToken
77
+ this.customAgentOptions as http.AgentOptions
82
78
  );
83
79
  } else {
84
80
  return networkRequestViaHttps(
85
81
  url,
86
82
  HttpMethod.POST,
87
83
  options,
88
- this.customAgentOptions as https.AgentOptions,
89
- cancellationToken,
90
- this.managedIdentity
84
+ this.customAgentOptions as https.AgentOptions
91
85
  );
92
86
  }
93
87
  }
@@ -114,10 +108,6 @@ const networkRequestViaProxy = <T>(
114
108
  headers: headers,
115
109
  };
116
110
 
117
- if (timeout) {
118
- tunnelRequestOptions.timeout = timeout;
119
- }
120
-
121
111
  if (agentOptions && Object.keys(agentOptions).length) {
122
112
  tunnelRequestOptions.agent = new http.Agent(agentOptions);
123
113
  }
@@ -130,6 +120,11 @@ const networkRequestViaProxy = <T>(
130
120
  "Content-Type: application/x-www-form-urlencoded\r\n" +
131
121
  `Content-Length: ${body.length}\r\n` +
132
122
  `\r\n${body}`;
123
+ } else {
124
+ // optional timeout is only for get requests (regionDiscovery, for example)
125
+ if (timeout) {
126
+ tunnelRequestOptions.timeout = timeout;
127
+ }
133
128
  }
134
129
  const outgoingRequestString =
135
130
  `${httpMethod.toUpperCase()} ${destinationUrl.href} HTTP/1.1\r\n` +
@@ -141,7 +136,7 @@ const networkRequestViaProxy = <T>(
141
136
  return new Promise<NetworkResponse<T>>((resolve, reject) => {
142
137
  const request = http.request(tunnelRequestOptions);
143
138
 
144
- if (tunnelRequestOptions.timeout) {
139
+ if (timeout) {
145
140
  request.on("timeout", () => {
146
141
  request.destroy();
147
142
  reject(new Error("Request time out"));
@@ -170,14 +165,6 @@ const networkRequestViaProxy = <T>(
170
165
  )
171
166
  );
172
167
  }
173
- if (tunnelRequestOptions.timeout) {
174
- socket.setTimeout(tunnelRequestOptions.timeout);
175
- socket.on("timeout", () => {
176
- request.destroy();
177
- socket.destroy();
178
- reject(new Error("Request time out"));
179
- });
180
- }
181
168
 
182
169
  // make a request over an HTTP tunnel
183
170
  socket.write(outgoingRequestString);
@@ -283,8 +270,7 @@ const networkRequestViaHttps = <T>(
283
270
  httpMethod: string,
284
271
  options?: NetworkRequestOptions,
285
272
  agentOptions?: https.AgentOptions,
286
- timeout?: number,
287
- managedIdentity?: boolean
273
+ timeout?: number
288
274
  ): Promise<NetworkResponse<T>> => {
289
275
  const isPostRequest = httpMethod === HttpMethod.POST;
290
276
  const body: string = options?.body || "";
@@ -297,10 +283,6 @@ const networkRequestViaHttps = <T>(
297
283
  ...NetworkUtils.urlToHttpOptions(url),
298
284
  };
299
285
 
300
- if (timeout) {
301
- customOptions.timeout = timeout;
302
- }
303
-
304
286
  if (agentOptions && Object.keys(agentOptions).length) {
305
287
  customOptions.agent = new https.Agent(agentOptions);
306
288
  }
@@ -311,16 +293,26 @@ const networkRequestViaHttps = <T>(
311
293
  ...customOptions.headers,
312
294
  "Content-Length": body.length,
313
295
  };
296
+ } else {
297
+ // optional timeout is only for get requests (regionDiscovery, for example)
298
+ if (timeout) {
299
+ customOptions.timeout = timeout;
300
+ }
314
301
  }
315
302
 
316
303
  return new Promise<NetworkResponse<T>>((resolve, reject) => {
317
304
  let request: http.ClientRequest;
318
- if (managedIdentity) {
305
+ // managed identity sources use http instead of https
306
+ if (customOptions.protocol === "http:") {
319
307
  request = http.request(customOptions);
320
308
  } else {
321
309
  request = https.request(customOptions);
322
310
  }
323
311
 
312
+ if (isPostRequest) {
313
+ request.write(body);
314
+ }
315
+
324
316
  if (timeout) {
325
317
  request.on("timeout", () => {
326
318
  request.destroy();
@@ -328,10 +320,6 @@ const networkRequestViaHttps = <T>(
328
320
  });
329
321
  }
330
322
 
331
- if (isPostRequest) {
332
- request.write(body);
333
- }
334
-
335
323
  request.end();
336
324
 
337
325
  request.on("response", (response) => {
@@ -0,0 +1,80 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import {
7
+ HeaderNames,
8
+ INetworkModule,
9
+ NetworkRequestOptions,
10
+ NetworkResponse,
11
+ } from "@azure/msal-common";
12
+ import { IHttpRetryPolicy } from "../retry/IHttpRetryPolicy";
13
+ import { HttpMethod } from "../utils/Constants";
14
+
15
+ export class HttpClientWithRetries implements INetworkModule {
16
+ private httpClientNoRetries: INetworkModule;
17
+ private retryPolicy: IHttpRetryPolicy;
18
+
19
+ constructor(
20
+ httpClientNoRetries: INetworkModule,
21
+ retryPolicy: IHttpRetryPolicy
22
+ ) {
23
+ this.httpClientNoRetries = httpClientNoRetries;
24
+ this.retryPolicy = retryPolicy;
25
+ }
26
+
27
+ private async sendNetworkRequestAsyncHelper<T>(
28
+ httpMethod: HttpMethod,
29
+ url: string,
30
+ options?: NetworkRequestOptions
31
+ ): Promise<NetworkResponse<T>> {
32
+ if (httpMethod === HttpMethod.GET) {
33
+ return this.httpClientNoRetries.sendGetRequestAsync(url, options);
34
+ } else {
35
+ return this.httpClientNoRetries.sendPostRequestAsync(url, options);
36
+ }
37
+ }
38
+
39
+ private async sendNetworkRequestAsync<T>(
40
+ httpMethod: HttpMethod,
41
+ url: string,
42
+ options?: NetworkRequestOptions
43
+ ): Promise<NetworkResponse<T>> {
44
+ // the underlying network module (custom or HttpClient) will make the call
45
+ let response: NetworkResponse<T> =
46
+ await this.sendNetworkRequestAsyncHelper(httpMethod, url, options);
47
+
48
+ let currentRetry: number = 0;
49
+ while (
50
+ await this.retryPolicy.pauseForRetry(
51
+ response.status,
52
+ currentRetry,
53
+ response.headers[HeaderNames.RETRY_AFTER]
54
+ )
55
+ ) {
56
+ response = await this.sendNetworkRequestAsyncHelper(
57
+ httpMethod,
58
+ url,
59
+ options
60
+ );
61
+ currentRetry++;
62
+ }
63
+
64
+ return response;
65
+ }
66
+
67
+ public async sendGetRequestAsync<T>(
68
+ url: string,
69
+ options?: NetworkRequestOptions
70
+ ): Promise<NetworkResponse<T>> {
71
+ return this.sendNetworkRequestAsync(HttpMethod.GET, url, options);
72
+ }
73
+
74
+ public async sendPostRequestAsync<T>(
75
+ url: string,
76
+ options?: NetworkRequestOptions
77
+ ): Promise<NetworkResponse<T>> {
78
+ return this.sendNetworkRequestAsync(HttpMethod.POST, url, options);
79
+ }
80
+ }
@@ -1,3 +1,3 @@
1
1
  /* eslint-disable header/header */
2
2
  export const name = "@azure/msal-node";
3
- export const version = "2.7.0-alpha.0";
3
+ export const version = "2.7.1-alpha.0";
@@ -3,7 +3,10 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { CommonClientCredentialRequest } from "@azure/msal-common";
6
+ import {
7
+ ClientAssertionCallback,
8
+ CommonClientCredentialRequest,
9
+ } from "@azure/msal-common";
7
10
 
8
11
  /**
9
12
  * CommonClientCredentialRequest
@@ -11,7 +14,7 @@ import { CommonClientCredentialRequest } from "@azure/msal-common";
11
14
  * - authority - URL of the authority, the security token service (STS) from which MSAL will acquire tokens.
12
15
  * - correlationId - Unique GUID set per request to trace a request end-to-end for telemetry purposes.
13
16
  * - skipCache - Skip token cache lookup and force request to authority to get a a new token. Defaults to false.
14
- * - clientAssertion - A Base64Url-encoded signed JWT assertion string used in the Client Credential flow
17
+ * - clientAssertion - An assertion string or a callback function that returns an assertion string (both are Base64Url-encoded signed JWTs) used in the Client Credential flow
15
18
  * - tokenQueryParameters - String to string map of custom query parameters added to the /token call
16
19
  * @public
17
20
  */
@@ -25,5 +28,5 @@ export type ClientCredentialRequest = Partial<
25
28
  | "storeInCache"
26
29
  >
27
30
  > & {
28
- clientAssertion?: string;
31
+ clientAssertion?: string | ClientAssertionCallback;
29
32
  };
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import http from "http";
7
+
8
+ export interface IHttpRetryPolicy {
9
+ /*
10
+ * if retry conditions occur, pauses and returns true
11
+ * otherwise return false
12
+ */
13
+ pauseForRetry(
14
+ httpStatusCode: number,
15
+ currentRetry: number,
16
+ retryAfterHeader: http.IncomingHttpHeaders["retry-after"]
17
+ ): Promise<boolean>;
18
+ }
@@ -0,0 +1,71 @@
1
+ /*
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import http from "http";
7
+ import { IHttpRetryPolicy } from "./IHttpRetryPolicy";
8
+
9
+ export class LinearRetryPolicy implements IHttpRetryPolicy {
10
+ maxRetries: number;
11
+ retryDelay: number;
12
+ httpStatusCodesToRetryOn: Array<number>;
13
+
14
+ constructor(
15
+ maxRetries: number,
16
+ retryDelay: number,
17
+ httpStatusCodesToRetryOn: Array<number>
18
+ ) {
19
+ this.maxRetries = maxRetries;
20
+ this.retryDelay = retryDelay;
21
+ this.httpStatusCodesToRetryOn = httpStatusCodesToRetryOn;
22
+ }
23
+
24
+ private retryAfterMillisecondsToSleep(
25
+ retryHeader: http.IncomingHttpHeaders["retry-after"]
26
+ ): number {
27
+ if (!retryHeader) {
28
+ return 0;
29
+ }
30
+
31
+ // retry-after header is in seconds
32
+ let millisToSleep = Math.round(parseFloat(retryHeader) * 1000);
33
+
34
+ /*
35
+ * retry-after header is in HTTP Date format
36
+ * <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT
37
+ */
38
+ if (isNaN(millisToSleep)) {
39
+ millisToSleep = Math.max(
40
+ 0,
41
+ // .valueOf() is needed to subtract dates in TypeScript
42
+ new Date(retryHeader).valueOf() - new Date().valueOf()
43
+ );
44
+ }
45
+
46
+ return millisToSleep;
47
+ }
48
+
49
+ async pauseForRetry(
50
+ httpStatusCode: number,
51
+ currentRetry: number,
52
+ retryAfterHeader: http.IncomingHttpHeaders["retry-after"]
53
+ ): Promise<boolean> {
54
+ if (
55
+ this.httpStatusCodesToRetryOn.includes(httpStatusCode) &&
56
+ currentRetry < this.maxRetries
57
+ ) {
58
+ const retryAfterDelay: number =
59
+ this.retryAfterMillisecondsToSleep(retryAfterHeader);
60
+
61
+ await new Promise((resolve) => {
62
+ // retryAfterHeader value of 0 evaluates to false, and this.retryDelay will be used
63
+ return setTimeout(resolve, retryAfterDelay || this.retryDelay);
64
+ });
65
+
66
+ return true;
67
+ }
68
+
69
+ return false;
70
+ }
71
+ }
@@ -3,20 +3,45 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ import { HttpStatus } from "@azure/msal-common";
7
+
6
8
  // MSI Constants. Docs for MSI are available here https://docs.microsoft.com/azure/app-service/overview-managed-identity
7
9
  export const AUTHORIZATION_HEADER_NAME: string = "Authorization";
8
10
  export const METADATA_HEADER_NAME: string = "Metadata";
9
- export const SECRET_HEADER_NAME: string = "X-IDENTITY-HEADER";
10
-
11
- export const MANAGED_IDENTITY_CLIENT_ID = "client_id";
12
- export const MANAGED_IDENTITY_OBJECT_ID = "object_id";
13
- export const MANAGED_IDENTITY_RESOURCE_ID = "mi_res_id";
11
+ export const APP_SERVICE_SECRET_HEADER_NAME: string = "X-IDENTITY-HEADER";
12
+ export const SERVICE_FABRIC_SECRET_HEADER_NAME: string = "secret";
13
+ export const API_VERSION_QUERY_PARAMETER_NAME: string = "api-version";
14
+ export const RESOURCE_BODY_OR_QUERY_PARAMETER_NAME: string = "resource";
14
15
  export const DEFAULT_MANAGED_IDENTITY_ID = "system_assigned_managed_identity";
15
16
  export const MANAGED_IDENTITY_DEFAULT_TENANT = "managed_identity";
16
17
  export const DEFAULT_AUTHORITY_FOR_MANAGED_IDENTITY = `https://login.microsoftonline.com/${MANAGED_IDENTITY_DEFAULT_TENANT}/`;
17
18
 
18
- export const MANAGED_IDENTITY_TIMEOUT_ERROR: string =
19
- "[Managed Identity] Authentication unavailable. The request to the managed identity endpoint timed out.";
19
+ /**
20
+ * Managed Identity Environment Variable Names
21
+ */
22
+ export const ManagedIdentityEnvironmentVariableNames = {
23
+ AZURE_POD_IDENTITY_AUTHORITY_HOST: "AZURE_POD_IDENTITY_AUTHORITY_HOST",
24
+ IDENTITY_ENDPOINT: "IDENTITY_ENDPOINT",
25
+ IDENTITY_HEADER: "IDENTITY_HEADER",
26
+ IDENTITY_SERVER_THUMBPRINT: "IDENTITY_SERVER_THUMBPRINT",
27
+ IMDS_ENDPOINT: "IMDS_ENDPOINT",
28
+ MSI_ENDPOINT: "MSI_ENDPOINT",
29
+ } as const;
30
+ export type ManagedIdentityEnvironmentVariableNames =
31
+ (typeof ManagedIdentityEnvironmentVariableNames)[keyof typeof ManagedIdentityEnvironmentVariableNames];
32
+
33
+ /**
34
+ * Managed Identity Source Names
35
+ */
36
+ export const ManagedIdentitySourceNames = {
37
+ APP_SERVICE: "App Service",
38
+ AZURE_ARC: "Azure Arc",
39
+ CLOUD_SHELL: "Cloud Shell",
40
+ IMDS: "IMDS",
41
+ SERVICE_FABRIC: "Service Fabric",
42
+ } as const;
43
+ export type ManagedIdentitySourceNames =
44
+ (typeof ManagedIdentitySourceNames)[keyof typeof ManagedIdentitySourceNames];
20
45
 
21
46
  /**
22
47
  * Managed Identity Ids
@@ -40,9 +65,10 @@ export const HttpMethod = {
40
65
  export type HttpMethod = (typeof HttpMethod)[keyof typeof HttpMethod];
41
66
 
42
67
  export const ProxyStatus = {
43
- SUCCESS_RANGE_START: 200,
44
- SUCCESS_RANGE_END: 299,
45
- SERVER_ERROR: 500,
68
+ SUCCESS: HttpStatus.SUCCESS,
69
+ SUCCESS_RANGE_START: HttpStatus.SUCCESS_RANGE_START,
70
+ SUCCESS_RANGE_END: HttpStatus.SUCCESS_RANGE_END,
71
+ SERVER_ERROR: HttpStatus.SERVER_ERROR,
46
72
  } as const;
47
73
  export type ProxyStatus = (typeof ProxyStatus)[keyof typeof ProxyStatus];
48
74
 
@@ -128,3 +154,14 @@ export const LOOPBACK_SERVER_CONSTANTS = {
128
154
  INTERVAL_MS: 100,
129
155
  TIMEOUT_MS: 5000,
130
156
  };
157
+
158
+ export const MANAGED_IDENTITY_MAX_RETRIES = 3;
159
+ export const MANAGED_IDENTITY_RETRY_DELAY = 1000;
160
+ export const MANAGED_IDENTITY_HTTP_STATUS_CODES_TO_RETRY_ON = [
161
+ HttpStatus.NOT_FOUND,
162
+ HttpStatus.REQUEST_TIMEOUT,
163
+ HttpStatus.TOO_MANY_REQUESTS,
164
+ HttpStatus.SERVER_ERROR,
165
+ HttpStatus.SERVICE_UNAVAILABLE,
166
+ HttpStatus.GATEWAY_TIMEOUT,
167
+ ];