@azure/identity 4.10.3-alpha.20250714.3 → 4.11.0-alpha.20250717.4

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 (343) hide show
  1. package/README.md +19 -1
  2. package/dist/browser/client/identityClient.js +30 -18
  3. package/dist/browser/client/identityClient.js.map +1 -1
  4. package/dist/browser/constants.d.ts +1 -1
  5. package/dist/browser/constants.d.ts.map +1 -1
  6. package/dist/browser/constants.js +1 -1
  7. package/dist/browser/constants.js.map +1 -1
  8. package/dist/browser/credentials/brokerCredential.d.ts +35 -0
  9. package/dist/browser/credentials/brokerCredential.d.ts.map +1 -0
  10. package/dist/browser/credentials/brokerCredential.js +69 -0
  11. package/dist/browser/credentials/brokerCredential.js.map +1 -0
  12. package/dist/browser/credentials/chainedTokenCredential.js +1 -1
  13. package/dist/browser/credentials/chainedTokenCredential.js.map +1 -1
  14. package/dist/browser/credentials/clientSecretCredential-browser.mjs.map +1 -1
  15. package/dist/browser/credentials/clientSecretCredential.js +7 -2
  16. package/dist/browser/credentials/interactiveBrowserCredential-browser.mjs.map +1 -1
  17. package/dist/browser/credentials/interactiveBrowserCredential.js +19 -6
  18. package/dist/browser/credentials/managedIdentityCredential/imdsMsi.js +4 -6
  19. package/dist/browser/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  20. package/dist/browser/credentials/managedIdentityCredential/imdsRetryPolicy.js +2 -2
  21. package/dist/browser/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
  22. package/dist/browser/credentials/managedIdentityCredential/tokenExchangeMsi.js +7 -1
  23. package/dist/browser/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
  24. package/dist/browser/credentials/usernamePasswordCredential-browser.mjs.map +1 -1
  25. package/dist/browser/credentials/usernamePasswordCredential.js +7 -1
  26. package/dist/browser/credentials/visualStudioCodeCredentialOptions.d.ts +0 -4
  27. package/dist/browser/credentials/visualStudioCodeCredentialOptions.d.ts.map +1 -1
  28. package/dist/browser/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
  29. package/dist/browser/credentials/visualStudioCodeCredentialPlugin.d.ts +0 -4
  30. package/dist/browser/credentials/visualStudioCodeCredentialPlugin.d.ts.map +1 -1
  31. package/dist/browser/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
  32. package/dist/browser/errors.js +21 -0
  33. package/dist/browser/errors.js.map +1 -1
  34. package/dist/browser/msal/browserFlows/msalBrowserCommon.js +15 -15
  35. package/dist/browser/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  36. package/dist/browser/msal/nodeFlows/msalClient.d.ts +13 -0
  37. package/dist/browser/msal/nodeFlows/msalClient.d.ts.map +1 -1
  38. package/dist/browser/msal/nodeFlows/msalClient.js +127 -94
  39. package/dist/browser/msal/nodeFlows/msalClient.js.map +1 -1
  40. package/dist/browser/msal/nodeFlows/msalPlugins.d.ts +19 -1
  41. package/dist/browser/msal/nodeFlows/msalPlugins.d.ts.map +1 -1
  42. package/dist/browser/msal/nodeFlows/msalPlugins.js +61 -16
  43. package/dist/browser/msal/nodeFlows/msalPlugins.js.map +1 -1
  44. package/dist/browser/msal/utils.js +3 -4
  45. package/dist/browser/msal/utils.js.map +1 -1
  46. package/dist/browser/plugins/provider.d.ts +2 -2
  47. package/dist/browser/plugins/provider.d.ts.map +1 -1
  48. package/dist/browser/plugins/provider.js.map +1 -1
  49. package/dist/browser/regionalAuthority.js +1 -2
  50. package/dist/browser/regionalAuthority.js.map +1 -1
  51. package/dist/browser/tokenProvider.js +1 -2
  52. package/dist/browser/tokenProvider.js.map +1 -1
  53. package/dist/browser/util/logging.js +6 -2
  54. package/dist/browser/util/logging.js.map +1 -1
  55. package/dist/browser/util/processMultiTenantRequest-browser.mjs.map +1 -1
  56. package/dist/browser/util/processMultiTenantRequest.js +1 -2
  57. package/dist/browser/util/processUtils.d.ts +1 -1
  58. package/dist/browser/util/processUtils.d.ts.map +1 -1
  59. package/dist/browser/util/processUtils.js +1 -1
  60. package/dist/browser/util/processUtils.js.map +1 -1
  61. package/dist/commonjs/client/identityClient.js +30 -18
  62. package/dist/commonjs/client/identityClient.js.map +1 -1
  63. package/dist/commonjs/constants.d.ts +1 -1
  64. package/dist/commonjs/constants.d.ts.map +1 -1
  65. package/dist/commonjs/constants.js +1 -1
  66. package/dist/commonjs/constants.js.map +1 -1
  67. package/dist/commonjs/credentials/authorizationCodeCredential.js +17 -3
  68. package/dist/commonjs/credentials/authorizationCodeCredential.js.map +1 -1
  69. package/dist/commonjs/credentials/azureCliCredential.js +15 -12
  70. package/dist/commonjs/credentials/azureCliCredential.js.map +1 -1
  71. package/dist/commonjs/credentials/azureDeveloperCliCredential.js +12 -10
  72. package/dist/commonjs/credentials/azureDeveloperCliCredential.js.map +1 -1
  73. package/dist/commonjs/credentials/azurePipelinesCredential.js +9 -5
  74. package/dist/commonjs/credentials/azurePipelinesCredential.js.map +1 -1
  75. package/dist/commonjs/credentials/azurePowerShellCredential.js +10 -7
  76. package/dist/commonjs/credentials/azurePowerShellCredential.js.map +1 -1
  77. package/dist/commonjs/credentials/brokerCredential.d.ts +35 -0
  78. package/dist/commonjs/credentials/brokerCredential.d.ts.map +1 -0
  79. package/dist/commonjs/credentials/brokerCredential.js +73 -0
  80. package/dist/commonjs/credentials/brokerCredential.js.map +1 -0
  81. package/dist/commonjs/credentials/chainedTokenCredential.js +1 -1
  82. package/dist/commonjs/credentials/chainedTokenCredential.js.map +1 -1
  83. package/dist/commonjs/credentials/clientAssertionCredential.js +11 -2
  84. package/dist/commonjs/credentials/clientAssertionCredential.js.map +1 -1
  85. package/dist/commonjs/credentials/clientCertificateCredential.js +19 -9
  86. package/dist/commonjs/credentials/clientCertificateCredential.js.map +1 -1
  87. package/dist/commonjs/credentials/clientSecretCredential.js +10 -2
  88. package/dist/commonjs/credentials/clientSecretCredential.js.map +1 -1
  89. package/dist/commonjs/credentials/defaultAzureCredential.d.ts +18 -0
  90. package/dist/commonjs/credentials/defaultAzureCredential.d.ts.map +1 -1
  91. package/dist/commonjs/credentials/defaultAzureCredential.js +69 -19
  92. package/dist/commonjs/credentials/defaultAzureCredential.js.map +1 -1
  93. package/dist/commonjs/credentials/deviceCodeCredential.js +24 -10
  94. package/dist/commonjs/credentials/deviceCodeCredential.js.map +1 -1
  95. package/dist/commonjs/credentials/environmentCredential.js +4 -6
  96. package/dist/commonjs/credentials/environmentCredential.js.map +1 -1
  97. package/dist/commonjs/credentials/interactiveBrowserCredential.js +30 -11
  98. package/dist/commonjs/credentials/interactiveBrowserCredential.js.map +1 -1
  99. package/dist/commonjs/credentials/managedIdentityCredential/imdsMsi.js +4 -6
  100. package/dist/commonjs/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  101. package/dist/commonjs/credentials/managedIdentityCredential/imdsRetryPolicy.js +2 -2
  102. package/dist/commonjs/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
  103. package/dist/commonjs/credentials/managedIdentityCredential/index.js +28 -18
  104. package/dist/commonjs/credentials/managedIdentityCredential/index.js.map +1 -1
  105. package/dist/commonjs/credentials/managedIdentityCredential/tokenExchangeMsi.js +7 -1
  106. package/dist/commonjs/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
  107. package/dist/commonjs/credentials/onBehalfOfCredential.js +13 -1
  108. package/dist/commonjs/credentials/onBehalfOfCredential.js.map +1 -1
  109. package/dist/commonjs/credentials/usernamePasswordCredential.js +10 -2
  110. package/dist/commonjs/credentials/usernamePasswordCredential.js.map +1 -1
  111. package/dist/commonjs/credentials/visualStudioCodeCredential.d.ts +15 -26
  112. package/dist/commonjs/credentials/visualStudioCodeCredential.d.ts.map +1 -1
  113. package/dist/commonjs/credentials/visualStudioCodeCredential.js +69 -130
  114. package/dist/commonjs/credentials/visualStudioCodeCredential.js.map +1 -1
  115. package/dist/commonjs/credentials/visualStudioCodeCredentialOptions.d.ts +0 -4
  116. package/dist/commonjs/credentials/visualStudioCodeCredentialOptions.d.ts.map +1 -1
  117. package/dist/commonjs/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
  118. package/dist/commonjs/credentials/visualStudioCodeCredentialPlugin.d.ts +0 -4
  119. package/dist/commonjs/credentials/visualStudioCodeCredentialPlugin.d.ts.map +1 -1
  120. package/dist/commonjs/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
  121. package/dist/commonjs/credentials/workloadIdentityCredential.js +5 -3
  122. package/dist/commonjs/credentials/workloadIdentityCredential.js.map +1 -1
  123. package/dist/commonjs/errors.js +21 -0
  124. package/dist/commonjs/errors.js.map +1 -1
  125. package/dist/commonjs/msal/browserFlows/msalBrowserCommon.js +15 -15
  126. package/dist/commonjs/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  127. package/dist/commonjs/msal/nodeFlows/msalClient.d.ts +13 -0
  128. package/dist/commonjs/msal/nodeFlows/msalClient.d.ts.map +1 -1
  129. package/dist/commonjs/msal/nodeFlows/msalClient.js +127 -94
  130. package/dist/commonjs/msal/nodeFlows/msalClient.js.map +1 -1
  131. package/dist/commonjs/msal/nodeFlows/msalPlugins.d.ts +19 -1
  132. package/dist/commonjs/msal/nodeFlows/msalPlugins.d.ts.map +1 -1
  133. package/dist/commonjs/msal/nodeFlows/msalPlugins.js +63 -17
  134. package/dist/commonjs/msal/nodeFlows/msalPlugins.js.map +1 -1
  135. package/dist/commonjs/msal/utils.js +3 -4
  136. package/dist/commonjs/msal/utils.js.map +1 -1
  137. package/dist/commonjs/plugins/consumer.d.ts.map +1 -1
  138. package/dist/commonjs/plugins/consumer.js +1 -2
  139. package/dist/commonjs/plugins/consumer.js.map +1 -1
  140. package/dist/commonjs/plugins/provider.d.ts +2 -2
  141. package/dist/commonjs/plugins/provider.d.ts.map +1 -1
  142. package/dist/commonjs/plugins/provider.js.map +1 -1
  143. package/dist/commonjs/regionalAuthority.js +1 -2
  144. package/dist/commonjs/regionalAuthority.js.map +1 -1
  145. package/dist/commonjs/tokenProvider.js +1 -2
  146. package/dist/commonjs/tokenProvider.js.map +1 -1
  147. package/dist/commonjs/util/logging.js +6 -2
  148. package/dist/commonjs/util/logging.js.map +1 -1
  149. package/dist/commonjs/util/processMultiTenantRequest.js +2 -3
  150. package/dist/commonjs/util/processMultiTenantRequest.js.map +1 -1
  151. package/dist/commonjs/util/processUtils.d.ts +1 -1
  152. package/dist/commonjs/util/processUtils.d.ts.map +1 -1
  153. package/dist/commonjs/util/processUtils.js +2 -2
  154. package/dist/commonjs/util/processUtils.js.map +1 -1
  155. package/dist/esm/client/identityClient.js +30 -18
  156. package/dist/esm/client/identityClient.js.map +1 -1
  157. package/dist/esm/constants.d.ts +1 -1
  158. package/dist/esm/constants.d.ts.map +1 -1
  159. package/dist/esm/constants.js +1 -1
  160. package/dist/esm/constants.js.map +1 -1
  161. package/dist/esm/credentials/authorizationCodeCredential.js +17 -3
  162. package/dist/esm/credentials/authorizationCodeCredential.js.map +1 -1
  163. package/dist/esm/credentials/azureCliCredential.js +15 -12
  164. package/dist/esm/credentials/azureCliCredential.js.map +1 -1
  165. package/dist/esm/credentials/azureDeveloperCliCredential.js +12 -10
  166. package/dist/esm/credentials/azureDeveloperCliCredential.js.map +1 -1
  167. package/dist/esm/credentials/azurePipelinesCredential.js +9 -5
  168. package/dist/esm/credentials/azurePipelinesCredential.js.map +1 -1
  169. package/dist/esm/credentials/azurePowerShellCredential.js +10 -7
  170. package/dist/esm/credentials/azurePowerShellCredential.js.map +1 -1
  171. package/dist/esm/credentials/brokerCredential.d.ts +35 -0
  172. package/dist/esm/credentials/brokerCredential.d.ts.map +1 -0
  173. package/dist/esm/credentials/brokerCredential.js +69 -0
  174. package/dist/esm/credentials/brokerCredential.js.map +1 -0
  175. package/dist/esm/credentials/chainedTokenCredential.js +1 -1
  176. package/dist/esm/credentials/chainedTokenCredential.js.map +1 -1
  177. package/dist/esm/credentials/clientAssertionCredential.js +11 -2
  178. package/dist/esm/credentials/clientAssertionCredential.js.map +1 -1
  179. package/dist/esm/credentials/clientCertificateCredential.js +19 -9
  180. package/dist/esm/credentials/clientCertificateCredential.js.map +1 -1
  181. package/dist/esm/credentials/clientSecretCredential.js +10 -2
  182. package/dist/esm/credentials/clientSecretCredential.js.map +1 -1
  183. package/dist/esm/credentials/defaultAzureCredential.d.ts +18 -0
  184. package/dist/esm/credentials/defaultAzureCredential.d.ts.map +1 -1
  185. package/dist/esm/credentials/defaultAzureCredential.js +67 -19
  186. package/dist/esm/credentials/defaultAzureCredential.js.map +1 -1
  187. package/dist/esm/credentials/deviceCodeCredential.js +24 -10
  188. package/dist/esm/credentials/deviceCodeCredential.js.map +1 -1
  189. package/dist/esm/credentials/environmentCredential.js +4 -6
  190. package/dist/esm/credentials/environmentCredential.js.map +1 -1
  191. package/dist/esm/credentials/interactiveBrowserCredential.js +30 -11
  192. package/dist/esm/credentials/interactiveBrowserCredential.js.map +1 -1
  193. package/dist/esm/credentials/managedIdentityCredential/imdsMsi.js +4 -6
  194. package/dist/esm/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  195. package/dist/esm/credentials/managedIdentityCredential/imdsRetryPolicy.js +2 -2
  196. package/dist/esm/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
  197. package/dist/esm/credentials/managedIdentityCredential/index.js +28 -18
  198. package/dist/esm/credentials/managedIdentityCredential/index.js.map +1 -1
  199. package/dist/esm/credentials/managedIdentityCredential/tokenExchangeMsi.js +7 -1
  200. package/dist/esm/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
  201. package/dist/esm/credentials/onBehalfOfCredential.js +13 -1
  202. package/dist/esm/credentials/onBehalfOfCredential.js.map +1 -1
  203. package/dist/esm/credentials/usernamePasswordCredential.js +10 -2
  204. package/dist/esm/credentials/usernamePasswordCredential.js.map +1 -1
  205. package/dist/esm/credentials/visualStudioCodeCredential.d.ts +15 -26
  206. package/dist/esm/credentials/visualStudioCodeCredential.d.ts.map +1 -1
  207. package/dist/esm/credentials/visualStudioCodeCredential.js +69 -128
  208. package/dist/esm/credentials/visualStudioCodeCredential.js.map +1 -1
  209. package/dist/esm/credentials/visualStudioCodeCredentialOptions.d.ts +0 -4
  210. package/dist/esm/credentials/visualStudioCodeCredentialOptions.d.ts.map +1 -1
  211. package/dist/esm/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
  212. package/dist/esm/credentials/visualStudioCodeCredentialPlugin.d.ts +0 -4
  213. package/dist/esm/credentials/visualStudioCodeCredentialPlugin.d.ts.map +1 -1
  214. package/dist/esm/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
  215. package/dist/esm/credentials/workloadIdentityCredential.js +5 -3
  216. package/dist/esm/credentials/workloadIdentityCredential.js.map +1 -1
  217. package/dist/esm/errors.js +21 -0
  218. package/dist/esm/errors.js.map +1 -1
  219. package/dist/esm/msal/browserFlows/msalBrowserCommon.js +15 -15
  220. package/dist/esm/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  221. package/dist/esm/msal/nodeFlows/msalClient.d.ts +13 -0
  222. package/dist/esm/msal/nodeFlows/msalClient.d.ts.map +1 -1
  223. package/dist/esm/msal/nodeFlows/msalClient.js +127 -94
  224. package/dist/esm/msal/nodeFlows/msalClient.js.map +1 -1
  225. package/dist/esm/msal/nodeFlows/msalPlugins.d.ts +19 -1
  226. package/dist/esm/msal/nodeFlows/msalPlugins.d.ts.map +1 -1
  227. package/dist/esm/msal/nodeFlows/msalPlugins.js +61 -16
  228. package/dist/esm/msal/nodeFlows/msalPlugins.js.map +1 -1
  229. package/dist/esm/msal/utils.js +3 -4
  230. package/dist/esm/msal/utils.js.map +1 -1
  231. package/dist/esm/plugins/consumer.d.ts.map +1 -1
  232. package/dist/esm/plugins/consumer.js +2 -3
  233. package/dist/esm/plugins/consumer.js.map +1 -1
  234. package/dist/esm/plugins/provider.d.ts +2 -2
  235. package/dist/esm/plugins/provider.d.ts.map +1 -1
  236. package/dist/esm/plugins/provider.js.map +1 -1
  237. package/dist/esm/regionalAuthority.js +1 -2
  238. package/dist/esm/regionalAuthority.js.map +1 -1
  239. package/dist/esm/tokenProvider.js +1 -2
  240. package/dist/esm/tokenProvider.js.map +1 -1
  241. package/dist/esm/util/logging.js +6 -2
  242. package/dist/esm/util/logging.js.map +1 -1
  243. package/dist/esm/util/processMultiTenantRequest.js +2 -3
  244. package/dist/esm/util/processMultiTenantRequest.js.map +1 -1
  245. package/dist/esm/util/processUtils.d.ts +1 -1
  246. package/dist/esm/util/processUtils.d.ts.map +1 -1
  247. package/dist/esm/util/processUtils.js +1 -1
  248. package/dist/esm/util/processUtils.js.map +1 -1
  249. package/dist/workerd/client/identityClient.js +30 -18
  250. package/dist/workerd/client/identityClient.js.map +1 -1
  251. package/dist/workerd/constants.d.ts +1 -1
  252. package/dist/workerd/constants.d.ts.map +1 -1
  253. package/dist/workerd/constants.js +1 -1
  254. package/dist/workerd/constants.js.map +1 -1
  255. package/dist/workerd/credentials/authorizationCodeCredential.js +17 -3
  256. package/dist/workerd/credentials/authorizationCodeCredential.js.map +1 -1
  257. package/dist/workerd/credentials/azureCliCredential.js +15 -12
  258. package/dist/workerd/credentials/azureCliCredential.js.map +1 -1
  259. package/dist/workerd/credentials/azureDeveloperCliCredential.js +12 -10
  260. package/dist/workerd/credentials/azureDeveloperCliCredential.js.map +1 -1
  261. package/dist/workerd/credentials/azurePipelinesCredential.js +9 -5
  262. package/dist/workerd/credentials/azurePipelinesCredential.js.map +1 -1
  263. package/dist/workerd/credentials/azurePowerShellCredential.js +10 -7
  264. package/dist/workerd/credentials/azurePowerShellCredential.js.map +1 -1
  265. package/dist/workerd/credentials/brokerCredential.d.ts +35 -0
  266. package/dist/workerd/credentials/brokerCredential.d.ts.map +1 -0
  267. package/dist/workerd/credentials/brokerCredential.js +69 -0
  268. package/dist/workerd/credentials/brokerCredential.js.map +1 -0
  269. package/dist/workerd/credentials/chainedTokenCredential.js +1 -1
  270. package/dist/workerd/credentials/chainedTokenCredential.js.map +1 -1
  271. package/dist/workerd/credentials/clientAssertionCredential.js +11 -2
  272. package/dist/workerd/credentials/clientAssertionCredential.js.map +1 -1
  273. package/dist/workerd/credentials/clientCertificateCredential.js +19 -9
  274. package/dist/workerd/credentials/clientCertificateCredential.js.map +1 -1
  275. package/dist/workerd/credentials/clientSecretCredential.js +10 -2
  276. package/dist/workerd/credentials/clientSecretCredential.js.map +1 -1
  277. package/dist/workerd/credentials/defaultAzureCredential.d.ts +18 -0
  278. package/dist/workerd/credentials/defaultAzureCredential.d.ts.map +1 -1
  279. package/dist/workerd/credentials/defaultAzureCredential.js +67 -19
  280. package/dist/workerd/credentials/defaultAzureCredential.js.map +1 -1
  281. package/dist/workerd/credentials/deviceCodeCredential.js +24 -10
  282. package/dist/workerd/credentials/deviceCodeCredential.js.map +1 -1
  283. package/dist/workerd/credentials/environmentCredential.js +4 -6
  284. package/dist/workerd/credentials/environmentCredential.js.map +1 -1
  285. package/dist/workerd/credentials/interactiveBrowserCredential.js +30 -11
  286. package/dist/workerd/credentials/interactiveBrowserCredential.js.map +1 -1
  287. package/dist/workerd/credentials/managedIdentityCredential/imdsMsi.js +4 -6
  288. package/dist/workerd/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  289. package/dist/workerd/credentials/managedIdentityCredential/imdsRetryPolicy.js +2 -2
  290. package/dist/workerd/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
  291. package/dist/workerd/credentials/managedIdentityCredential/index.js +28 -18
  292. package/dist/workerd/credentials/managedIdentityCredential/index.js.map +1 -1
  293. package/dist/workerd/credentials/managedIdentityCredential/tokenExchangeMsi.js +7 -1
  294. package/dist/workerd/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
  295. package/dist/workerd/credentials/onBehalfOfCredential.js +13 -1
  296. package/dist/workerd/credentials/onBehalfOfCredential.js.map +1 -1
  297. package/dist/workerd/credentials/usernamePasswordCredential.js +10 -2
  298. package/dist/workerd/credentials/usernamePasswordCredential.js.map +1 -1
  299. package/dist/workerd/credentials/visualStudioCodeCredential.d.ts +15 -26
  300. package/dist/workerd/credentials/visualStudioCodeCredential.d.ts.map +1 -1
  301. package/dist/workerd/credentials/visualStudioCodeCredential.js +69 -128
  302. package/dist/workerd/credentials/visualStudioCodeCredential.js.map +1 -1
  303. package/dist/workerd/credentials/visualStudioCodeCredentialOptions.d.ts +0 -4
  304. package/dist/workerd/credentials/visualStudioCodeCredentialOptions.d.ts.map +1 -1
  305. package/dist/workerd/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
  306. package/dist/workerd/credentials/visualStudioCodeCredentialPlugin.d.ts +0 -4
  307. package/dist/workerd/credentials/visualStudioCodeCredentialPlugin.d.ts.map +1 -1
  308. package/dist/workerd/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
  309. package/dist/workerd/credentials/workloadIdentityCredential.js +5 -3
  310. package/dist/workerd/credentials/workloadIdentityCredential.js.map +1 -1
  311. package/dist/workerd/errors.js +21 -0
  312. package/dist/workerd/errors.js.map +1 -1
  313. package/dist/workerd/msal/browserFlows/msalBrowserCommon.js +15 -15
  314. package/dist/workerd/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  315. package/dist/workerd/msal/nodeFlows/msalClient.d.ts +13 -0
  316. package/dist/workerd/msal/nodeFlows/msalClient.d.ts.map +1 -1
  317. package/dist/workerd/msal/nodeFlows/msalClient.js +127 -94
  318. package/dist/workerd/msal/nodeFlows/msalClient.js.map +1 -1
  319. package/dist/workerd/msal/nodeFlows/msalPlugins.d.ts +19 -1
  320. package/dist/workerd/msal/nodeFlows/msalPlugins.d.ts.map +1 -1
  321. package/dist/workerd/msal/nodeFlows/msalPlugins.js +61 -16
  322. package/dist/workerd/msal/nodeFlows/msalPlugins.js.map +1 -1
  323. package/dist/workerd/msal/utils.js +3 -4
  324. package/dist/workerd/msal/utils.js.map +1 -1
  325. package/dist/workerd/plugins/consumer.d.ts.map +1 -1
  326. package/dist/workerd/plugins/consumer.js +2 -3
  327. package/dist/workerd/plugins/consumer.js.map +1 -1
  328. package/dist/workerd/plugins/provider.d.ts +2 -2
  329. package/dist/workerd/plugins/provider.d.ts.map +1 -1
  330. package/dist/workerd/plugins/provider.js.map +1 -1
  331. package/dist/workerd/regionalAuthority.js +1 -2
  332. package/dist/workerd/regionalAuthority.js.map +1 -1
  333. package/dist/workerd/tokenProvider.js +1 -2
  334. package/dist/workerd/tokenProvider.js.map +1 -1
  335. package/dist/workerd/util/logging.js +6 -2
  336. package/dist/workerd/util/logging.js.map +1 -1
  337. package/dist/workerd/util/processMultiTenantRequest.js +2 -3
  338. package/dist/workerd/util/processMultiTenantRequest.js.map +1 -1
  339. package/dist/workerd/util/processUtils.d.ts +1 -1
  340. package/dist/workerd/util/processUtils.d.ts.map +1 -1
  341. package/dist/workerd/util/processUtils.js +1 -1
  342. package/dist/workerd/util/processUtils.js.map +1 -1
  343. package/package.json +2 -2
@@ -23,6 +23,11 @@ function defaultDeviceCodePromptCallback(deviceCodeInfo) {
23
23
  * that the user can enter into https://microsoft.com/devicelogin.
24
24
  */
25
25
  class DeviceCodeCredential {
26
+ tenantId;
27
+ additionallyAllowedTenantIds;
28
+ disableAutomaticAuthentication;
29
+ msalClient;
30
+ userPromptCallback;
26
31
  /**
27
32
  * Creates an instance of DeviceCodeCredential with the details needed
28
33
  * to initiate the device code authorization flow with Microsoft Entra ID.
@@ -46,14 +51,17 @@ class DeviceCodeCredential {
46
51
  * @param options - Options for configuring the client which makes the authentication requests.
47
52
  */
48
53
  constructor(options) {
49
- var _a, _b;
50
- this.tenantId = options === null || options === void 0 ? void 0 : options.tenantId;
51
- this.additionallyAllowedTenantIds = (0, tenantIdUtils_js_1.resolveAdditionallyAllowedTenantIds)(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
52
- const clientId = (_a = options === null || options === void 0 ? void 0 : options.clientId) !== null && _a !== void 0 ? _a : constants_js_1.DeveloperSignOnClientId;
53
- const tenantId = (0, tenantIdUtils_js_1.resolveTenantId)(logger, options === null || options === void 0 ? void 0 : options.tenantId, clientId);
54
- this.userPromptCallback = (_b = options === null || options === void 0 ? void 0 : options.userPromptCallback) !== null && _b !== void 0 ? _b : defaultDeviceCodePromptCallback;
55
- this.msalClient = (0, msalClient_js_1.createMsalClient)(clientId, tenantId, Object.assign(Object.assign({}, options), { logger, tokenCredentialOptions: options || {} }));
56
- this.disableAutomaticAuthentication = options === null || options === void 0 ? void 0 : options.disableAutomaticAuthentication;
54
+ this.tenantId = options?.tenantId;
55
+ this.additionallyAllowedTenantIds = (0, tenantIdUtils_js_1.resolveAdditionallyAllowedTenantIds)(options?.additionallyAllowedTenants);
56
+ const clientId = options?.clientId ?? constants_js_1.DeveloperSignOnClientId;
57
+ const tenantId = (0, tenantIdUtils_js_1.resolveTenantId)(logger, options?.tenantId, clientId);
58
+ this.userPromptCallback = options?.userPromptCallback ?? defaultDeviceCodePromptCallback;
59
+ this.msalClient = (0, msalClient_js_1.createMsalClient)(clientId, tenantId, {
60
+ ...options,
61
+ logger,
62
+ tokenCredentialOptions: options || {},
63
+ });
64
+ this.disableAutomaticAuthentication = options?.disableAutomaticAuthentication;
57
65
  }
58
66
  /**
59
67
  * Authenticates with Microsoft Entra ID and returns an access token if successful.
@@ -71,7 +79,10 @@ class DeviceCodeCredential {
71
79
  return tracing_js_1.tracingClient.withSpan(`${this.constructor.name}.getToken`, options, async (newOptions) => {
72
80
  newOptions.tenantId = (0, tenantIdUtils_js_1.processMultiTenantRequest)(this.tenantId, newOptions, this.additionallyAllowedTenantIds, logger);
73
81
  const arrayScopes = (0, scopeUtils_js_1.ensureScopes)(scopes);
74
- return this.msalClient.getTokenByDeviceCode(arrayScopes, this.userPromptCallback, Object.assign(Object.assign({}, newOptions), { disableAutomaticAuthentication: this.disableAutomaticAuthentication }));
82
+ return this.msalClient.getTokenByDeviceCode(arrayScopes, this.userPromptCallback, {
83
+ ...newOptions,
84
+ disableAutomaticAuthentication: this.disableAutomaticAuthentication,
85
+ });
75
86
  });
76
87
  }
77
88
  /**
@@ -87,7 +98,10 @@ class DeviceCodeCredential {
87
98
  async authenticate(scopes, options = {}) {
88
99
  return tracing_js_1.tracingClient.withSpan(`${this.constructor.name}.authenticate`, options, async (newOptions) => {
89
100
  const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];
90
- await this.msalClient.getTokenByDeviceCode(arrayScopes, this.userPromptCallback, Object.assign(Object.assign({}, newOptions), { disableAutomaticAuthentication: false }));
101
+ await this.msalClient.getTokenByDeviceCode(arrayScopes, this.userPromptCallback, {
102
+ ...newOptions,
103
+ disableAutomaticAuthentication: false, // this method should always allow user interaction
104
+ });
91
105
  return this.msalClient.getActiveAccount();
92
106
  });
93
107
  }
@@ -1 +1 @@
1
- {"version":3,"file":"deviceCodeCredential.js","sourceRoot":"","sources":["../../../src/credentials/deviceCodeCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AA2BlC,0EAEC;AA1BD,+DAIkC;AAOlC,mDAAsD;AACtD,yDAAqD;AACrD,mDAAmD;AAEnD,mEAAmE;AACnE,kDAA0D;AAE1D,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,sBAAsB,CAAC,CAAC;AAExD;;;GAGG;AACH,SAAgB,+BAA+B,CAAC,cAA8B;IAC5E,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,MAAa,oBAAoB;IAO/B;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,YAAY,OAAqC;;QAC/C,IAAI,CAAC,QAAQ,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,CAAC;QAClC,IAAI,CAAC,4BAA4B,GAAG,IAAA,sDAAmC,EACrE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,0BAA0B,CACpC,CAAC;QACF,MAAM,QAAQ,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,sCAAuB,CAAC;QAC9D,MAAM,QAAQ,GAAG,IAAA,kCAAe,EAAC,MAAM,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAA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C,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YAC9D,MAAM,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC,WAAW,EAAE,IAAI,CAAC,kBAAkB,kCAC1E,UAAU,KACb,8BAA8B,EAAE,KAAK,IACrC,CAAC;YACH,OAAO,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC;QAC5C,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAzGD,oDAyGC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n resolveTenantId,\n} from \"../util/tenantIdUtils.js\";\nimport type {\n DeviceCodeCredentialOptions,\n DeviceCodeInfo,\n DeviceCodePromptCallback,\n} from \"./deviceCodeCredentialOptions.js\";\nimport type { AuthenticationRecord } from \"../msal/types.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { tracingClient } from \"../util/tracing.js\";\nimport type { MsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { DeveloperSignOnClientId } from \"../constants.js\";\n\nconst logger = credentialLogger(\"DeviceCodeCredential\");\n\n/**\n * Method that logs the user code from the DeviceCodeCredential.\n * @param deviceCodeInfo - The device code.\n */\nexport function defaultDeviceCodePromptCallback(deviceCodeInfo: DeviceCodeInfo): void {\n console.log(deviceCodeInfo.message);\n}\n\n/**\n * Enables authentication to Microsoft Entra ID using a device code\n * that the user can enter into https://microsoft.com/devicelogin.\n */\nexport class DeviceCodeCredential implements TokenCredential {\n private tenantId?: string;\n private additionallyAllowedTenantIds: string[];\n private disableAutomaticAuthentication?: boolean;\n private msalClient: MsalClient;\n private userPromptCallback: DeviceCodePromptCallback;\n\n /**\n * Creates an instance of DeviceCodeCredential with the details needed\n * to initiate the device code authorization flow with Microsoft Entra ID.\n *\n * A message will be logged, giving users a code that they can use to authenticate once they go to https://microsoft.com/devicelogin\n *\n * Developers can configure how this message is shown by passing a custom `userPromptCallback`:\n *\n * ```ts snippet:device_code_credential_example\n * import { DeviceCodeCredential } from \"@azure/identity\";\n *\n * const credential = new DeviceCodeCredential({\n * tenantId: process.env.AZURE_TENANT_ID,\n * clientId: process.env.AZURE_CLIENT_ID,\n * userPromptCallback: (info) => {\n * console.log(\"CUSTOMIZED PROMPT CALLBACK\", info.message);\n * },\n * });\n * ```\n *\n * @param options - Options for configuring the client which makes the authentication requests.\n */\n constructor(options?: DeviceCodeCredentialOptions) {\n this.tenantId = options?.tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n const clientId = options?.clientId ?? DeveloperSignOnClientId;\n const tenantId = resolveTenantId(logger, options?.tenantId, clientId);\n this.userPromptCallback = options?.userPromptCallback ?? defaultDeviceCodePromptCallback;\n this.msalClient = createMsalClient(clientId, tenantId, {\n ...options,\n logger,\n tokenCredentialOptions: options || {},\n });\n this.disableAutomaticAuthentication = options?.disableAutomaticAuthentication;\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * If the user provided the option `disableAutomaticAuthentication`,\n * once the token can't be retrieved silently,\n * this method won't attempt to request user interaction to retrieve the token.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(\n `${this.constructor.name}.getToken`,\n options,\n async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = ensureScopes(scopes);\n return this.msalClient.getTokenByDeviceCode(arrayScopes, this.userPromptCallback, {\n ...newOptions,\n disableAutomaticAuthentication: this.disableAutomaticAuthentication,\n });\n },\n );\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * If the token can't be retrieved silently, this method will always generate a challenge for the user.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async authenticate(\n scopes: string | string[],\n options: GetTokenOptions = {},\n ): Promise<AuthenticationRecord | undefined> {\n return tracingClient.withSpan(\n `${this.constructor.name}.authenticate`,\n options,\n async (newOptions) => {\n const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];\n await this.msalClient.getTokenByDeviceCode(arrayScopes, this.userPromptCallback, {\n ...newOptions,\n disableAutomaticAuthentication: false, // this method should always allow user interaction\n });\n return this.msalClient.getActiveAccount();\n },\n );\n }\n}\n"]}
1
+ {"version":3,"file":"deviceCodeCredential.js","sourceRoot":"","sources":["../../../src/credentials/deviceCodeCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AA2BlC,0EAEC;AA1BD,+DAIkC;AAOlC,mDAAsD;AACtD,yDAAqD;AACrD,mDAAmD;AAEnD,mEAAmE;AACnE,kDAA0D;AAE1D,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,sBAAsB,CAAC,CAAC;AAExD;;;GAGG;AACH,SAAgB,+BAA+B,CAAC,cAA8B;IAC5E,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,MAAa,oBAAoB;IACvB,QAAQ,CAAU;IAClB,4BAA4B,CAAW;IACvC,8BAA8B,CAAW;IACzC,UAAU,CAAa;IACvB,kBAAkB,CAA2B;IAErD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,YAAY,OAAqC;QAC/C,IAAI,CAAC,QAAQ,GAAG,OAAO,E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ACzB,UAA2B,EAAE;QAE7B,OAAO,0BAAa,CAAC,QAAQ,CAC3B,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,eAAe,EACvC,OAAO,EACP,KAAK,EAAE,UAAU,EAAE,EAAE;YACnB,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YAC9D,MAAM,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC,WAAW,EAAE,IAAI,CAAC,kBAAkB,EAAE;gBAC/E,GAAG,UAAU;gBACb,8BAA8B,EAAE,KAAK,EAAE,mDAAmD;aAC3F,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC;QAC5C,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAzGD,oDAyGC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n resolveTenantId,\n} from \"../util/tenantIdUtils.js\";\nimport type {\n DeviceCodeCredentialOptions,\n DeviceCodeInfo,\n DeviceCodePromptCallback,\n} from \"./deviceCodeCredentialOptions.js\";\nimport type { AuthenticationRecord } from \"../msal/types.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { tracingClient } from \"../util/tracing.js\";\nimport type { MsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { DeveloperSignOnClientId } from \"../constants.js\";\n\nconst logger = credentialLogger(\"DeviceCodeCredential\");\n\n/**\n * Method that logs the user code from the DeviceCodeCredential.\n * @param deviceCodeInfo - The device code.\n */\nexport function defaultDeviceCodePromptCallback(deviceCodeInfo: DeviceCodeInfo): void {\n console.log(deviceCodeInfo.message);\n}\n\n/**\n * Enables authentication to Microsoft Entra ID using a device code\n * that the user can enter into https://microsoft.com/devicelogin.\n */\nexport class DeviceCodeCredential implements TokenCredential {\n private tenantId?: string;\n private additionallyAllowedTenantIds: string[];\n private disableAutomaticAuthentication?: boolean;\n private msalClient: MsalClient;\n private userPromptCallback: DeviceCodePromptCallback;\n\n /**\n * Creates an instance of DeviceCodeCredential with the details needed\n * to initiate the device code authorization flow with Microsoft Entra ID.\n *\n * A message will be logged, giving users a code that they can use to authenticate once they go to https://microsoft.com/devicelogin\n *\n * Developers can configure how this message is shown by passing a custom `userPromptCallback`:\n *\n * ```ts snippet:device_code_credential_example\n * import { DeviceCodeCredential } from \"@azure/identity\";\n *\n * const credential = new DeviceCodeCredential({\n * tenantId: process.env.AZURE_TENANT_ID,\n * clientId: process.env.AZURE_CLIENT_ID,\n * userPromptCallback: (info) => {\n * console.log(\"CUSTOMIZED PROMPT CALLBACK\", info.message);\n * },\n * });\n * ```\n *\n * @param options - Options for configuring the client which makes the authentication requests.\n */\n constructor(options?: DeviceCodeCredentialOptions) {\n this.tenantId = options?.tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n const clientId = options?.clientId ?? DeveloperSignOnClientId;\n const tenantId = resolveTenantId(logger, options?.tenantId, clientId);\n this.userPromptCallback = options?.userPromptCallback ?? defaultDeviceCodePromptCallback;\n this.msalClient = createMsalClient(clientId, tenantId, {\n ...options,\n logger,\n tokenCredentialOptions: options || {},\n });\n this.disableAutomaticAuthentication = options?.disableAutomaticAuthentication;\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * If the user provided the option `disableAutomaticAuthentication`,\n * once the token can't be retrieved silently,\n * this method won't attempt to request user interaction to retrieve the token.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(\n `${this.constructor.name}.getToken`,\n options,\n async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = ensureScopes(scopes);\n return this.msalClient.getTokenByDeviceCode(arrayScopes, this.userPromptCallback, {\n ...newOptions,\n disableAutomaticAuthentication: this.disableAutomaticAuthentication,\n });\n },\n );\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * If the token can't be retrieved silently, this method will always generate a challenge for the user.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async authenticate(\n scopes: string | string[],\n options: GetTokenOptions = {},\n ): Promise<AuthenticationRecord | undefined> {\n return tracingClient.withSpan(\n `${this.constructor.name}.authenticate`,\n options,\n async (newOptions) => {\n const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];\n await this.msalClient.getTokenByDeviceCode(arrayScopes, this.userPromptCallback, {\n ...newOptions,\n disableAutomaticAuthentication: false, // this method should always allow user interaction\n });\n return this.msalClient.getActiveAccount();\n },\n );\n }\n}\n"]}
@@ -30,15 +30,13 @@ exports.AllSupportedEnvironmentVariables = [
30
30
  "AZURE_CLIENT_SEND_CERTIFICATE_CHAIN",
31
31
  ];
32
32
  function getAdditionallyAllowedTenants() {
33
- var _a;
34
- const additionallyAllowedValues = (_a = process.env.AZURE_ADDITIONALLY_ALLOWED_TENANTS) !== null && _a !== void 0 ? _a : "";
33
+ const additionallyAllowedValues = process.env.AZURE_ADDITIONALLY_ALLOWED_TENANTS ?? "";
35
34
  return additionallyAllowedValues.split(";");
36
35
  }
37
36
  const credentialName = "EnvironmentCredential";
38
37
  const logger = (0, logging_js_1.credentialLogger)(credentialName);
39
38
  function getSendCertificateChain() {
40
- var _a;
41
- const sendCertificateChain = ((_a = process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN) !== null && _a !== void 0 ? _a : "").toLowerCase();
39
+ const sendCertificateChain = (process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN ?? "").toLowerCase();
42
40
  const result = sendCertificateChain === "true" || sendCertificateChain === "1";
43
41
  logger.verbose(`AZURE_CLIENT_SEND_CERTIFICATE_CHAIN: ${process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN}; sendCertificateChain: ${result}`);
44
42
  return result;
@@ -47,6 +45,7 @@ function getSendCertificateChain() {
47
45
  * Enables authentication to Microsoft Entra ID using a client secret or certificate.
48
46
  */
49
47
  class EnvironmentCredential {
48
+ _credential = undefined;
50
49
  /**
51
50
  * Creates an instance of the EnvironmentCredential class and decides what credential to use depending on the available environment variables.
52
51
  *
@@ -74,13 +73,12 @@ class EnvironmentCredential {
74
73
  */
75
74
  constructor(options) {
76
75
  // Keep track of any missing environment variables for error details
77
- this._credential = undefined;
78
76
  const assigned = (0, logging_js_1.processEnvVars)(exports.AllSupportedEnvironmentVariables).assigned.join(", ");
79
77
  logger.info(`Found the following environment variables: ${assigned}`);
80
78
  const tenantId = process.env.AZURE_TENANT_ID, clientId = process.env.AZURE_CLIENT_ID, clientSecret = process.env.AZURE_CLIENT_SECRET;
81
79
  const additionallyAllowedTenantIds = getAdditionallyAllowedTenants();
82
80
  const sendCertificateChain = getSendCertificateChain();
83
- const newOptions = Object.assign(Object.assign({}, options), { additionallyAllowedTenantIds, sendCertificateChain });
81
+ const newOptions = { ...options, additionallyAllowedTenantIds, sendCertificateChain };
84
82
  if (tenantId) {
85
83
  (0, tenantIdUtils_js_1.checkTenantId)(logger, tenantId);
86
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"environmentCredential.js","sourceRoot":"","sources":["../../../src/credentials/environmentCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAwClC,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AM,mBAAmB,CAAC;gBAC5B,CAAC;YACH,CAAC;YACD,MAAM,IAAI,sCAA0B,CAClC,GAAG,cAAc,sJAAsJ,CACxK,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAtHD,sDAsHC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport { AuthenticationError, CredentialUnavailableError } from \"../errors.js\";\nimport { credentialLogger, formatError, formatSuccess, processEnvVars } from \"../util/logging.js\";\n\nimport { ClientCertificateCredential } from \"./clientCertificateCredential.js\";\nimport { ClientSecretCredential } from \"./clientSecretCredential.js\";\nimport type { EnvironmentCredentialOptions } from \"./environmentCredentialOptions.js\";\nimport { UsernamePasswordCredential } from \"./usernamePasswordCredential.js\";\nimport { checkTenantId } from \"../util/tenantIdUtils.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\n/**\n * Contains the list of all supported environment variable names so that an\n * appropriate error message can be generated when no credentials can be\n * configured.\n *\n * @internal\n */\nexport const AllSupportedEnvironmentVariables = [\n \"AZURE_TENANT_ID\",\n \"AZURE_CLIENT_ID\",\n \"AZURE_CLIENT_SECRET\",\n \"AZURE_CLIENT_CERTIFICATE_PATH\",\n \"AZURE_CLIENT_CERTIFICATE_PASSWORD\",\n \"AZURE_USERNAME\",\n \"AZURE_PASSWORD\",\n \"AZURE_ADDITIONALLY_ALLOWED_TENANTS\",\n \"AZURE_CLIENT_SEND_CERTIFICATE_CHAIN\",\n];\n\nfunction getAdditionallyAllowedTenants(): string[] {\n const additionallyAllowedValues = process.env.AZURE_ADDITIONALLY_ALLOWED_TENANTS ?? \"\";\n return additionallyAllowedValues.split(\";\");\n}\n\nconst credentialName = \"EnvironmentCredential\";\nconst logger = credentialLogger(credentialName);\n\nexport function getSendCertificateChain(): boolean {\n const sendCertificateChain = (\n process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN ?? \"\"\n ).toLowerCase();\n const result = sendCertificateChain === \"true\" || sendCertificateChain === \"1\";\n logger.verbose(\n `AZURE_CLIENT_SEND_CERTIFICATE_CHAIN: ${process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN}; sendCertificateChain: ${result}`,\n );\n return result;\n}\n\n/**\n * Enables authentication to Microsoft Entra ID using a client secret or certificate.\n */\nexport class EnvironmentCredential implements TokenCredential {\n private _credential?:\n | ClientSecretCredential\n | ClientCertificateCredential\n | UsernamePasswordCredential = undefined;\n /**\n * Creates an instance of the EnvironmentCredential class and decides what credential to use depending on the available environment variables.\n *\n * Required environment variables:\n * - `AZURE_TENANT_ID`: The Microsoft Entra tenant (directory) ID.\n * - `AZURE_CLIENT_ID`: The client (application) ID of an App Registration in the tenant.\n *\n * If setting the AZURE_TENANT_ID, then you can also set the additionally allowed tenants\n * - `AZURE_ADDITIONALLY_ALLOWED_TENANTS`: For multi-tenant applications, specifies additional tenants for which the credential may acquire tokens with a single semicolon delimited string. Use * to allow all tenants.\n *\n * Environment variables used for client credential authentication:\n * - `AZURE_CLIENT_SECRET`: A client secret that was generated for the App Registration.\n * - `AZURE_CLIENT_CERTIFICATE_PATH`: The path to a PEM certificate to use during the authentication, instead of the client secret.\n * - `AZURE_CLIENT_CERTIFICATE_PASSWORD`: (optional) password for the certificate file.\n * - `AZURE_CLIENT_SEND_CERTIFICATE_CHAIN`: (optional) indicates that the certificate chain should be set in x5c header to support subject name / issuer based authentication.\n *\n * Username and password authentication is deprecated, since it doesn't support multifactor authentication (MFA). See https://aka.ms/azsdk/identity/mfa for more details. Users can still provide environment variables for this authentication method:\n * - `AZURE_USERNAME`: Username to authenticate with.\n * - `AZURE_PASSWORD`: Password to authenticate with.\n *\n * If the environment variables required to perform the authentication are missing, a {@link CredentialUnavailableError} will be thrown.\n * If the authentication fails, or if there's an unknown error, an {@link AuthenticationError} will be thrown.\n *\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(options?: EnvironmentCredentialOptions) {\n // Keep track of any missing environment variables for error details\n\n const assigned = processEnvVars(AllSupportedEnvironmentVariables).assigned.join(\", \");\n logger.info(`Found the following environment variables: ${assigned}`);\n\n const tenantId = process.env.AZURE_TENANT_ID,\n clientId = process.env.AZURE_CLIENT_ID,\n clientSecret = process.env.AZURE_CLIENT_SECRET;\n\n const additionallyAllowedTenantIds = getAdditionallyAllowedTenants();\n const sendCertificateChain = getSendCertificateChain();\n const newOptions = { ...options, additionallyAllowedTenantIds, sendCertificateChain };\n\n if (tenantId) {\n checkTenantId(logger, tenantId);\n }\n\n if (tenantId && clientId && clientSecret) {\n logger.info(\n `Invoking ClientSecretCredential with tenant ID: ${tenantId}, clientId: ${clientId} and clientSecret: [REDACTED]`,\n );\n this._credential = new ClientSecretCredential(tenantId, clientId, clientSecret, newOptions);\n return;\n }\n\n const certificatePath = process.env.AZURE_CLIENT_CERTIFICATE_PATH;\n const certificatePassword = process.env.AZURE_CLIENT_CERTIFICATE_PASSWORD;\n if (tenantId && clientId && certificatePath) {\n logger.info(\n `Invoking ClientCertificateCredential with tenant ID: ${tenantId}, clientId: ${clientId} and certificatePath: ${certificatePath}`,\n );\n this._credential = new ClientCertificateCredential(\n tenantId,\n clientId,\n { certificatePath, certificatePassword },\n newOptions,\n );\n return;\n }\n\n const username = process.env.AZURE_USERNAME;\n const password = process.env.AZURE_PASSWORD;\n if (tenantId && clientId && username && password) {\n logger.info(\n `Invoking UsernamePasswordCredential with tenant ID: ${tenantId}, clientId: ${clientId} and username: ${username}`,\n );\n\n logger.warning(\n \"Environment is configured to use username and password authentication. This authentication method is deprecated, as it doesn't support multifactor authentication (MFA). Use a more secure credential. For more details, see https://aka.ms/azsdk/identity/mfa.\",\n );\n this._credential = new UsernamePasswordCredential(\n tenantId,\n clientId,\n username,\n password,\n newOptions,\n );\n }\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - Optional parameters. See {@link GetTokenOptions}.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(`${credentialName}.getToken`, options, async (newOptions) => {\n if (this._credential) {\n try {\n const result = await this._credential.getToken(scopes, newOptions);\n logger.getToken.info(formatSuccess(scopes));\n return result;\n } catch (err: any) {\n const authenticationError = new AuthenticationError(400, {\n error: `${credentialName} authentication failed. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.`,\n error_description: err.message.toString().split(\"More details:\").join(\"\"),\n });\n logger.getToken.info(formatError(scopes, authenticationError));\n throw authenticationError;\n }\n }\n throw new CredentialUnavailableError(\n `${credentialName} is unavailable. No underlying credential could be used. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.`,\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"environmentCredential.js","sourceRoot":"","sources":["../../../src/credentials/environmentCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAwClC,0DASC;AA9CD,4CAA+E;AAC/E,mDAAkG;AAElG,qFAA+E;AAC/E,2EAAqE;AAErE,mFAA6E;AAC7E,+DAAyD;AACzD,mDAAmD;AAEnD;;;;;;GAMG;AACU,QAAA,gCAAgC,GAAG;IAC9C,iBAAiB;IACjB,iBAAiB;IACjB,qBAAqB;IACrB,+BAA+B;IAC/B,mCAAmC;IACnC,gBAAgB;IAChB,gBAAgB;IAChB,oCAAoC;IACpC,qCAAqC;CACtC,CAAC;AAEF,SAAS,6BAA6B;IACpC,MAAM,yBAAyB,GAAG,OAAO,CAAC,GAAG,CAAC,kCAAkC,IAAI,EAAE,CAAC;IACvF,OAAO,yBAAyB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAC/C,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,cAAc,CAAC,CAAC;AAEhD,SAAgB,uBAAuB;IACrC,MAAM,oBAAoB,GAAG,CAC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MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;oBACnE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAA,0BAAa,EAAC,MAAM,CAAC,CAAC,CAAC;oBAC5C,OAAO,MAAM,CAAC;gBAChB,CAAC;gBAAC,OAAO,GAAQ,EAAE,CAAC;oBAClB,MAAM,mBAAmB,GAAG,IAAI,+BAAmB,CAAC,GAAG,EAAE;wBACvD,KAAK,EAAE,GAAG,cAAc,qHAAqH;wBAC7I,iBAAiB,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;qBAC1E,CAAC,CAAC;oBACH,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAA,wBAAW,EAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC;oBAC/D,MAAM,mBAAmB,CAAC;gBAC5B,CAAC;YACH,CAAC;YACD,MAAM,IAAI,sCAA0B,CAClC,GAAG,cAAc,sJAAsJ,CACxK,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAtHD,sDAsHC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport { AuthenticationError, CredentialUnavailableError } from \"../errors.js\";\nimport { credentialLogger, formatError, formatSuccess, processEnvVars } from \"../util/logging.js\";\n\nimport { ClientCertificateCredential } from \"./clientCertificateCredential.js\";\nimport { ClientSecretCredential } from \"./clientSecretCredential.js\";\nimport type { EnvironmentCredentialOptions } from \"./environmentCredentialOptions.js\";\nimport { UsernamePasswordCredential } from \"./usernamePasswordCredential.js\";\nimport { checkTenantId } from \"../util/tenantIdUtils.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\n/**\n * Contains the list of all supported environment variable names so that an\n * appropriate error message can be generated when no credentials can be\n * configured.\n *\n * @internal\n */\nexport const AllSupportedEnvironmentVariables = [\n \"AZURE_TENANT_ID\",\n \"AZURE_CLIENT_ID\",\n \"AZURE_CLIENT_SECRET\",\n \"AZURE_CLIENT_CERTIFICATE_PATH\",\n \"AZURE_CLIENT_CERTIFICATE_PASSWORD\",\n \"AZURE_USERNAME\",\n \"AZURE_PASSWORD\",\n \"AZURE_ADDITIONALLY_ALLOWED_TENANTS\",\n \"AZURE_CLIENT_SEND_CERTIFICATE_CHAIN\",\n];\n\nfunction getAdditionallyAllowedTenants(): string[] {\n const additionallyAllowedValues = process.env.AZURE_ADDITIONALLY_ALLOWED_TENANTS ?? \"\";\n return additionallyAllowedValues.split(\";\");\n}\n\nconst credentialName = \"EnvironmentCredential\";\nconst logger = credentialLogger(credentialName);\n\nexport function getSendCertificateChain(): boolean {\n const sendCertificateChain = (\n process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN ?? \"\"\n ).toLowerCase();\n const result = sendCertificateChain === \"true\" || sendCertificateChain === \"1\";\n logger.verbose(\n `AZURE_CLIENT_SEND_CERTIFICATE_CHAIN: ${process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN}; sendCertificateChain: ${result}`,\n );\n return result;\n}\n\n/**\n * Enables authentication to Microsoft Entra ID using a client secret or certificate.\n */\nexport class EnvironmentCredential implements TokenCredential {\n private _credential?:\n | ClientSecretCredential\n | ClientCertificateCredential\n | UsernamePasswordCredential = undefined;\n /**\n * Creates an instance of the EnvironmentCredential class and decides what credential to use depending on the available environment variables.\n *\n * Required environment variables:\n * - `AZURE_TENANT_ID`: The Microsoft Entra tenant (directory) ID.\n * - `AZURE_CLIENT_ID`: The client (application) ID of an App Registration in the tenant.\n *\n * If setting the AZURE_TENANT_ID, then you can also set the additionally allowed tenants\n * - `AZURE_ADDITIONALLY_ALLOWED_TENANTS`: For multi-tenant applications, specifies additional tenants for which the credential may acquire tokens with a single semicolon delimited string. Use * to allow all tenants.\n *\n * Environment variables used for client credential authentication:\n * - `AZURE_CLIENT_SECRET`: A client secret that was generated for the App Registration.\n * - `AZURE_CLIENT_CERTIFICATE_PATH`: The path to a PEM certificate to use during the authentication, instead of the client secret.\n * - `AZURE_CLIENT_CERTIFICATE_PASSWORD`: (optional) password for the certificate file.\n * - `AZURE_CLIENT_SEND_CERTIFICATE_CHAIN`: (optional) indicates that the certificate chain should be set in x5c header to support subject name / issuer based authentication.\n *\n * Username and password authentication is deprecated, since it doesn't support multifactor authentication (MFA). See https://aka.ms/azsdk/identity/mfa for more details. Users can still provide environment variables for this authentication method:\n * - `AZURE_USERNAME`: Username to authenticate with.\n * - `AZURE_PASSWORD`: Password to authenticate with.\n *\n * If the environment variables required to perform the authentication are missing, a {@link CredentialUnavailableError} will be thrown.\n * If the authentication fails, or if there's an unknown error, an {@link AuthenticationError} will be thrown.\n *\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(options?: EnvironmentCredentialOptions) {\n // Keep track of any missing environment variables for error details\n\n const assigned = processEnvVars(AllSupportedEnvironmentVariables).assigned.join(\", \");\n logger.info(`Found the following environment variables: ${assigned}`);\n\n const tenantId = process.env.AZURE_TENANT_ID,\n clientId = process.env.AZURE_CLIENT_ID,\n clientSecret = process.env.AZURE_CLIENT_SECRET;\n\n const additionallyAllowedTenantIds = getAdditionallyAllowedTenants();\n const sendCertificateChain = getSendCertificateChain();\n const newOptions = { ...options, additionallyAllowedTenantIds, sendCertificateChain };\n\n if (tenantId) {\n checkTenantId(logger, tenantId);\n }\n\n if (tenantId && clientId && clientSecret) {\n logger.info(\n `Invoking ClientSecretCredential with tenant ID: ${tenantId}, clientId: ${clientId} and clientSecret: [REDACTED]`,\n );\n this._credential = new ClientSecretCredential(tenantId, clientId, clientSecret, newOptions);\n return;\n }\n\n const certificatePath = process.env.AZURE_CLIENT_CERTIFICATE_PATH;\n const certificatePassword = process.env.AZURE_CLIENT_CERTIFICATE_PASSWORD;\n if (tenantId && clientId && certificatePath) {\n logger.info(\n `Invoking ClientCertificateCredential with tenant ID: ${tenantId}, clientId: ${clientId} and certificatePath: ${certificatePath}`,\n );\n this._credential = new ClientCertificateCredential(\n tenantId,\n clientId,\n { certificatePath, certificatePassword },\n newOptions,\n );\n return;\n }\n\n const username = process.env.AZURE_USERNAME;\n const password = process.env.AZURE_PASSWORD;\n if (tenantId && clientId && username && password) {\n logger.info(\n `Invoking UsernamePasswordCredential with tenant ID: ${tenantId}, clientId: ${clientId} and username: ${username}`,\n );\n\n logger.warning(\n \"Environment is configured to use username and password authentication. This authentication method is deprecated, as it doesn't support multifactor authentication (MFA). Use a more secure credential. For more details, see https://aka.ms/azsdk/identity/mfa.\",\n );\n this._credential = new UsernamePasswordCredential(\n tenantId,\n clientId,\n username,\n password,\n newOptions,\n );\n }\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - Optional parameters. See {@link GetTokenOptions}.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(`${credentialName}.getToken`, options, async (newOptions) => {\n if (this._credential) {\n try {\n const result = await this._credential.getToken(scopes, newOptions);\n logger.getToken.info(formatSuccess(scopes));\n return result;\n } catch (err: any) {\n const authenticationError = new AuthenticationError(400, {\n error: `${credentialName} authentication failed. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.`,\n error_description: err.message.toString().split(\"More details:\").join(\"\"),\n });\n logger.getToken.info(formatError(scopes, authenticationError));\n throw authenticationError;\n }\n }\n throw new CredentialUnavailableError(\n `${credentialName} is unavailable. No underlying credential could be used. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.`,\n );\n });\n }\n}\n"]}
@@ -15,6 +15,12 @@ const logger = (0, logging_js_1.credentialLogger)("InteractiveBrowserCredential"
15
15
  * using the interactive login flow.
16
16
  */
17
17
  class InteractiveBrowserCredential {
18
+ tenantId;
19
+ additionallyAllowedTenantIds;
20
+ msalClient;
21
+ disableAutomaticAuthentication;
22
+ browserCustomizationOptions;
23
+ loginHint;
18
24
  /**
19
25
  * Creates an instance of InteractiveBrowserCredential with the details needed.
20
26
  *
@@ -28,28 +34,31 @@ class InteractiveBrowserCredential {
28
34
  * @param options - Options for configuring the client which makes the authentication requests.
29
35
  */
30
36
  constructor(options) {
31
- var _a, _b, _c, _d, _e;
32
37
  this.tenantId = (0, tenantIdUtils_js_1.resolveTenantId)(logger, options.tenantId, options.clientId);
33
- this.additionallyAllowedTenantIds = (0, tenantIdUtils_js_1.resolveAdditionallyAllowedTenantIds)(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
34
- const msalClientOptions = Object.assign(Object.assign({}, options), { tokenCredentialOptions: options, logger });
38
+ this.additionallyAllowedTenantIds = (0, tenantIdUtils_js_1.resolveAdditionallyAllowedTenantIds)(options?.additionallyAllowedTenants);
39
+ const msalClientOptions = {
40
+ ...options,
41
+ tokenCredentialOptions: options,
42
+ logger,
43
+ };
35
44
  const ibcNodeOptions = options;
36
45
  this.browserCustomizationOptions = ibcNodeOptions.browserCustomizationOptions;
37
46
  this.loginHint = ibcNodeOptions.loginHint;
38
- if ((_a = ibcNodeOptions === null || ibcNodeOptions === void 0 ? void 0 : ibcNodeOptions.brokerOptions) === null || _a === void 0 ? void 0 : _a.enabled) {
39
- if (!((_b = ibcNodeOptions === null || ibcNodeOptions === void 0 ? void 0 : ibcNodeOptions.brokerOptions) === null || _b === void 0 ? void 0 : _b.parentWindowHandle)) {
47
+ if (ibcNodeOptions?.brokerOptions?.enabled) {
48
+ if (!ibcNodeOptions?.brokerOptions?.parentWindowHandle) {
40
49
  throw new Error("In order to do WAM authentication, `parentWindowHandle` under `brokerOptions` is a required parameter");
41
50
  }
42
51
  else {
43
52
  msalClientOptions.brokerOptions = {
44
53
  enabled: true,
45
54
  parentWindowHandle: ibcNodeOptions.brokerOptions.parentWindowHandle,
46
- legacyEnableMsaPassthrough: (_c = ibcNodeOptions.brokerOptions) === null || _c === void 0 ? void 0 : _c.legacyEnableMsaPassthrough,
47
- useDefaultBrokerAccount: (_d = ibcNodeOptions.brokerOptions) === null || _d === void 0 ? void 0 : _d.useDefaultBrokerAccount,
55
+ legacyEnableMsaPassthrough: ibcNodeOptions.brokerOptions?.legacyEnableMsaPassthrough,
56
+ useDefaultBrokerAccount: ibcNodeOptions.brokerOptions?.useDefaultBrokerAccount,
48
57
  };
49
58
  }
50
59
  }
51
- this.msalClient = (0, msalClient_js_1.createMsalClient)((_e = options.clientId) !== null && _e !== void 0 ? _e : constants_js_1.DeveloperSignOnClientId, this.tenantId, msalClientOptions);
52
- this.disableAutomaticAuthentication = options === null || options === void 0 ? void 0 : options.disableAutomaticAuthentication;
60
+ this.msalClient = (0, msalClient_js_1.createMsalClient)(options.clientId ?? constants_js_1.DeveloperSignOnClientId, this.tenantId, msalClientOptions);
61
+ this.disableAutomaticAuthentication = options?.disableAutomaticAuthentication;
53
62
  }
54
63
  /**
55
64
  * Authenticates with Microsoft Entra ID and returns an access token if successful.
@@ -67,7 +76,12 @@ class InteractiveBrowserCredential {
67
76
  return tracing_js_1.tracingClient.withSpan(`${this.constructor.name}.getToken`, options, async (newOptions) => {
68
77
  newOptions.tenantId = (0, tenantIdUtils_js_1.processMultiTenantRequest)(this.tenantId, newOptions, this.additionallyAllowedTenantIds, logger);
69
78
  const arrayScopes = (0, scopeUtils_js_1.ensureScopes)(scopes);
70
- return this.msalClient.getTokenByInteractiveRequest(arrayScopes, Object.assign(Object.assign({}, newOptions), { disableAutomaticAuthentication: this.disableAutomaticAuthentication, browserCustomizationOptions: this.browserCustomizationOptions, loginHint: this.loginHint }));
79
+ return this.msalClient.getTokenByInteractiveRequest(arrayScopes, {
80
+ ...newOptions,
81
+ disableAutomaticAuthentication: this.disableAutomaticAuthentication,
82
+ browserCustomizationOptions: this.browserCustomizationOptions,
83
+ loginHint: this.loginHint,
84
+ });
71
85
  });
72
86
  }
73
87
  /**
@@ -86,7 +100,12 @@ class InteractiveBrowserCredential {
86
100
  async authenticate(scopes, options = {}) {
87
101
  return tracing_js_1.tracingClient.withSpan(`${this.constructor.name}.authenticate`, options, async (newOptions) => {
88
102
  const arrayScopes = (0, scopeUtils_js_1.ensureScopes)(scopes);
89
- await this.msalClient.getTokenByInteractiveRequest(arrayScopes, Object.assign(Object.assign({}, newOptions), { disableAutomaticAuthentication: false, browserCustomizationOptions: this.browserCustomizationOptions, loginHint: this.loginHint }));
103
+ await this.msalClient.getTokenByInteractiveRequest(arrayScopes, {
104
+ ...newOptions,
105
+ disableAutomaticAuthentication: false, // this method should always allow user interaction
106
+ browserCustomizationOptions: this.browserCustomizationOptions,
107
+ loginHint: this.loginHint,
108
+ });
90
109
  return this.msalClient.getActiveAccount();
91
110
  });
92
111
  }
@@ -1 +1 @@
1
- {"version":3,"file":"interactiveBrowserCredential.js","sourceRoot":"","sources":["../../../src/credentials/interactiveBrowserCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAOlC,+DAIkC;AAGlC,mDAAsD;AACtD,yDAAqD;AACrD,mDAAmD;AAEnD,mEAAmE;AACnE,kDAA0D;AAE1D,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,8BAA8B,CAAC,CAAC;AAEhE;;;GAGG;AACH,MAAa,4BAA4B;IAQvC;;;;;;;;;;;OAWG;IACH,YACE,OAA+F;;QAE/F,IAAI,CAAC,QAAQ,GAAG,IAAA,kCAAe,EAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC5E,IAAI,CAAC,4BAA4B,GAAG,IAAA,sDAAmC,EACrE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,0BAA0B,CACpC,CAAC;QAEF,MAAM,iBAAiB,mCAClB,OAAO,KACV,sBAAsB,EAAE,OAAO,EAC/B,MAAM,GACP,CAAC;QACF,MAAM,cAAc,GAAG,OAAkD,CAAC;QAC1E,IAAI,CAAC,2BA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AG,IAAA,4BAAY,EAAC,MAAM,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC,UAAU,CAAC,4BAA4B,CAAC,WAAW,kCAC1D,UAAU,KACb,8BAA8B,EAAE,IAAI,CAAC,8BAA8B,EACnE,2BAA2B,EAAE,IAAI,CAAC,2BAA2B,EAC7D,SAAS,EAAE,IAAI,CAAC,SAAS,IACzB,CAAC;QACL,CAAC,CACF,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,YAAY,CAChB,MAAyB,EACzB,UAA2B,EAAE;QAE7B,OAAO,0BAAa,CAAC,QAAQ,CAC3B,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,eAAe,EACvC,OAAO,EACP,KAAK,EAAE,UAAU,EAAE,EAAE;YACnB,MAAM,WAAW,GAAG,IAAA,4BAAY,EAAC,MAAM,CAAC,CAAC;YACzC,MAAM,IAAI,CAAC,UAAU,CAAC,4BAA4B,CAAC,WAAW,kCACzD,UAAU,KACb,8BAA8B,EAAE,KAAK,EACrC,2BAA2B,EAAE,IAAI,CAAC,2BAA2B,EAC7D,SAAS,EAAE,IAAI,CAAC,SAAS,IACzB,CAAC;YACH,OAAO,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC;QAC5C,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AA7HD,oEA6HC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type {\n InteractiveBrowserCredentialInBrowserOptions,\n InteractiveBrowserCredentialNodeOptions,\n} from \"./interactiveBrowserCredentialOptions.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n resolveTenantId,\n} from \"../util/tenantIdUtils.js\";\n\nimport type { AuthenticationRecord } from \"../msal/types.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { tracingClient } from \"../util/tracing.js\";\nimport type { MsalClient, MsalClientOptions } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { DeveloperSignOnClientId } from \"../constants.js\";\n\nconst logger = credentialLogger(\"InteractiveBrowserCredential\");\n\n/**\n * Enables authentication to Microsoft Entra ID inside of the web browser\n * using the interactive login flow.\n */\nexport class InteractiveBrowserCredential implements TokenCredential {\n private tenantId?: string;\n private additionallyAllowedTenantIds: string[];\n private msalClient: MsalClient;\n private disableAutomaticAuthentication?: boolean;\n private browserCustomizationOptions: InteractiveBrowserCredentialNodeOptions[\"browserCustomizationOptions\"];\n private loginHint?: string;\n\n /**\n * Creates an instance of InteractiveBrowserCredential with the details needed.\n *\n * This credential uses the [Authorization Code Flow](https://learn.microsoft.com/entra/identity-platform/v2-oauth2-auth-code-flow).\n * On Node.js, it will open a browser window while it listens for a redirect response from the authentication service.\n * On browsers, it authenticates via popups. The `loginStyle` optional parameter can be set to `redirect` to authenticate by redirecting the user to an Azure secure login page, which then will redirect the user back to the web application where the authentication started.\n *\n * For Node.js, if a `clientId` is provided, the Microsoft Entra application will need to be configured to have a \"Mobile and desktop applications\" redirect endpoint.\n * Follow our guide on [setting up Redirect URIs for Desktop apps that calls to web APIs](https://learn.microsoft.com/entra/identity-platform/scenario-desktop-app-registration#redirect-uris).\n *\n * @param options - Options for configuring the client which makes the authentication requests.\n */\n constructor(\n options: InteractiveBrowserCredentialNodeOptions | InteractiveBrowserCredentialInBrowserOptions,\n ) {\n this.tenantId = resolveTenantId(logger, options.tenantId, options.clientId);\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n const msalClientOptions: MsalClientOptions = {\n ...options,\n tokenCredentialOptions: options,\n logger,\n };\n const ibcNodeOptions = options as InteractiveBrowserCredentialNodeOptions;\n this.browserCustomizationOptions = ibcNodeOptions.browserCustomizationOptions;\n this.loginHint = ibcNodeOptions.loginHint;\n if (ibcNodeOptions?.brokerOptions?.enabled) {\n if (!ibcNodeOptions?.brokerOptions?.parentWindowHandle) {\n throw new Error(\n \"In order to do WAM authentication, `parentWindowHandle` under `brokerOptions` is a required parameter\",\n );\n } else {\n msalClientOptions.brokerOptions = {\n enabled: true,\n parentWindowHandle: ibcNodeOptions.brokerOptions.parentWindowHandle,\n legacyEnableMsaPassthrough: ibcNodeOptions.brokerOptions?.legacyEnableMsaPassthrough,\n useDefaultBrokerAccount: ibcNodeOptions.brokerOptions?.useDefaultBrokerAccount,\n };\n }\n }\n this.msalClient = createMsalClient(\n options.clientId ?? DeveloperSignOnClientId,\n this.tenantId,\n msalClientOptions,\n );\n this.disableAutomaticAuthentication = options?.disableAutomaticAuthentication;\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * If the user provided the option `disableAutomaticAuthentication`,\n * once the token can't be retrieved silently,\n * this method won't attempt to request user interaction to retrieve the token.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(\n `${this.constructor.name}.getToken`,\n options,\n async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = ensureScopes(scopes);\n return this.msalClient.getTokenByInteractiveRequest(arrayScopes, {\n ...newOptions,\n disableAutomaticAuthentication: this.disableAutomaticAuthentication,\n browserCustomizationOptions: this.browserCustomizationOptions,\n loginHint: this.loginHint,\n });\n },\n );\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * If the token can't be retrieved silently, this method will always generate a challenge for the user.\n *\n * On Node.js, this credential has [Proof Key for Code Exchange (PKCE)](https://datatracker.ietf.org/doc/html/rfc7636) enabled by default.\n * PKCE is a security feature that mitigates authentication code interception attacks.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async authenticate(\n scopes: string | string[],\n options: GetTokenOptions = {},\n ): Promise<AuthenticationRecord | undefined> {\n return tracingClient.withSpan(\n `${this.constructor.name}.authenticate`,\n options,\n async (newOptions) => {\n const arrayScopes = ensureScopes(scopes);\n await this.msalClient.getTokenByInteractiveRequest(arrayScopes, {\n ...newOptions,\n disableAutomaticAuthentication: false, // this method should always allow user interaction\n browserCustomizationOptions: this.browserCustomizationOptions,\n loginHint: this.loginHint,\n });\n return this.msalClient.getActiveAccount();\n },\n );\n }\n}\n"]}
1
+ {"version":3,"file":"interactiveBrowserCredential.js","sourceRoot":"","sources":["../../../src/credentials/interactiveBrowserCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAOlC,+DAIkC;AAGlC,mDAAsD;AACtD,yDAAqD;AACrD,mDAAmD;AAEnD,mEAAmE;AACnE,kDAA0D;AAE1D,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,8BAA8B,CAAC,CAAC;AAEhE;;;GAGG;AACH,MAAa,4BAA4B;IAC/B,QAAQ,CAAU;IAClB,4BAA4B,CAAW;IACvC,UAAU,CAAa;IACvB,8BAA8B,CAAW;IACzC,2BAA2B,CAAyE;IACpG,SAAS,CAAU;IAE3B;;;;;;;;;;;OAWG;IACH,YACE,OAA+F;QAE/F,IAAI,CAAC,QAAQ,GAAG,IAAA,kCAAe,EAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC5E,IAAI,CAAC,4BAA4B,GAAG,IAAA,sDAAmC,EACrE,OAAO,EAAE,0BAA0B,CACpC,CAAC;QAEF,MAAM,iBAAiB,GAAsB;YAC3C,GAAG,OAAO;YACV,sBAAsB,EAAE,OAA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C;YACzC,OAAO,IAAI,CAAC,UAAU,CAAC,4BAA4B,CAAC,WAAW,EAAE;gBAC/D,GAAG,UAAU;gBACb,8BAA8B,EAAE,IAAI,CAAC,8BAA8B;gBACnE,2BAA2B,EAAE,IAAI,CAAC,2BAA2B;gBAC7D,SAAS,EAAE,IAAI,CAAC,SAAS;aAC1B,CAAC,CAAC;QACL,CAAC,CACF,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,YAAY,CAChB,MAAyB,EACzB,UAA2B,EAAE;QAE7B,OAAO,0BAAa,CAAC,QAAQ,CAC3B,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,eAAe,EACvC,OAAO,EACP,KAAK,EAAE,UAAU,EAAE,EAAE;YACnB,MAAM,WAAW,GAAG,IAAA,4BAAY,EAAC,MAAM,CAAC,CAAC;YACzC,MAAM,IAAI,CAAC,UAAU,CAAC,4BAA4B,CAAC,WAAW,EAAE;gBAC9D,GAAG,UAAU;gBACb,8BAA8B,EAAE,KAAK,EAAE,mDAAmD;gBAC1F,2BAA2B,EAAE,IAAI,CAAC,2BAA2B;gBAC7D,SAAS,EAAE,IAAI,CAAC,SAAS;aAC1B,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC;QAC5C,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AA7HD,oEA6HC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type {\n InteractiveBrowserCredentialInBrowserOptions,\n InteractiveBrowserCredentialNodeOptions,\n} from \"./interactiveBrowserCredentialOptions.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n resolveTenantId,\n} from \"../util/tenantIdUtils.js\";\n\nimport type { AuthenticationRecord } from \"../msal/types.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { tracingClient } from \"../util/tracing.js\";\nimport type { MsalClient, MsalClientOptions } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { DeveloperSignOnClientId } from \"../constants.js\";\n\nconst logger = credentialLogger(\"InteractiveBrowserCredential\");\n\n/**\n * Enables authentication to Microsoft Entra ID inside of the web browser\n * using the interactive login flow.\n */\nexport class InteractiveBrowserCredential implements TokenCredential {\n private tenantId?: string;\n private additionallyAllowedTenantIds: string[];\n private msalClient: MsalClient;\n private disableAutomaticAuthentication?: boolean;\n private browserCustomizationOptions: InteractiveBrowserCredentialNodeOptions[\"browserCustomizationOptions\"];\n private loginHint?: string;\n\n /**\n * Creates an instance of InteractiveBrowserCredential with the details needed.\n *\n * This credential uses the [Authorization Code Flow](https://learn.microsoft.com/entra/identity-platform/v2-oauth2-auth-code-flow).\n * On Node.js, it will open a browser window while it listens for a redirect response from the authentication service.\n * On browsers, it authenticates via popups. The `loginStyle` optional parameter can be set to `redirect` to authenticate by redirecting the user to an Azure secure login page, which then will redirect the user back to the web application where the authentication started.\n *\n * For Node.js, if a `clientId` is provided, the Microsoft Entra application will need to be configured to have a \"Mobile and desktop applications\" redirect endpoint.\n * Follow our guide on [setting up Redirect URIs for Desktop apps that calls to web APIs](https://learn.microsoft.com/entra/identity-platform/scenario-desktop-app-registration#redirect-uris).\n *\n * @param options - Options for configuring the client which makes the authentication requests.\n */\n constructor(\n options: InteractiveBrowserCredentialNodeOptions | InteractiveBrowserCredentialInBrowserOptions,\n ) {\n this.tenantId = resolveTenantId(logger, options.tenantId, options.clientId);\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n const msalClientOptions: MsalClientOptions = {\n ...options,\n tokenCredentialOptions: options,\n logger,\n };\n const ibcNodeOptions = options as InteractiveBrowserCredentialNodeOptions;\n this.browserCustomizationOptions = ibcNodeOptions.browserCustomizationOptions;\n this.loginHint = ibcNodeOptions.loginHint;\n if (ibcNodeOptions?.brokerOptions?.enabled) {\n if (!ibcNodeOptions?.brokerOptions?.parentWindowHandle) {\n throw new Error(\n \"In order to do WAM authentication, `parentWindowHandle` under `brokerOptions` is a required parameter\",\n );\n } else {\n msalClientOptions.brokerOptions = {\n enabled: true,\n parentWindowHandle: ibcNodeOptions.brokerOptions.parentWindowHandle,\n legacyEnableMsaPassthrough: ibcNodeOptions.brokerOptions?.legacyEnableMsaPassthrough,\n useDefaultBrokerAccount: ibcNodeOptions.brokerOptions?.useDefaultBrokerAccount,\n };\n }\n }\n this.msalClient = createMsalClient(\n options.clientId ?? DeveloperSignOnClientId,\n this.tenantId,\n msalClientOptions,\n );\n this.disableAutomaticAuthentication = options?.disableAutomaticAuthentication;\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * If the user provided the option `disableAutomaticAuthentication`,\n * once the token can't be retrieved silently,\n * this method won't attempt to request user interaction to retrieve the token.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(\n `${this.constructor.name}.getToken`,\n options,\n async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = ensureScopes(scopes);\n return this.msalClient.getTokenByInteractiveRequest(arrayScopes, {\n ...newOptions,\n disableAutomaticAuthentication: this.disableAutomaticAuthentication,\n browserCustomizationOptions: this.browserCustomizationOptions,\n loginHint: this.loginHint,\n });\n },\n );\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * If the token can't be retrieved silently, this method will always generate a challenge for the user.\n *\n * On Node.js, this credential has [Proof Key for Code Exchange (PKCE)](https://datatracker.ietf.org/doc/html/rfc7636) enabled by default.\n * PKCE is a security feature that mitigates authentication code interception attacks.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async authenticate(\n scopes: string | string[],\n options: GetTokenOptions = {},\n ): Promise<AuthenticationRecord | undefined> {\n return tracingClient.withSpan(\n `${this.constructor.name}.authenticate`,\n options,\n async (newOptions) => {\n const arrayScopes = ensureScopes(scopes);\n await this.msalClient.getTokenByInteractiveRequest(arrayScopes, {\n ...newOptions,\n disableAutomaticAuthentication: false, // this method should always allow user interaction\n browserCustomizationOptions: this.browserCustomizationOptions,\n loginHint: this.loginHint,\n });\n return this.msalClient.getActiveAccount();\n },\n );\n }\n}\n"]}
@@ -17,14 +17,13 @@ const imdsEndpointPath = "/metadata/identity/oauth2/token";
17
17
  * The response indicates the availability of IMSD service; otherwise the request would time out.
18
18
  */
19
19
  function prepareInvalidRequestOptions(scopes) {
20
- var _a;
21
20
  const resource = (0, utils_js_1.mapScopesToResource)(scopes);
22
21
  if (!resource) {
23
22
  throw new Error(`${msiName}: Multiple scopes are not supported.`);
24
23
  }
25
24
  // Pod Identity will try to process this request even if the Metadata header is missing.
26
25
  // We can exclude the request query to ensure no IMDS endpoint tries to process the ping request.
27
- const url = new URL(imdsEndpointPath, (_a = process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST) !== null && _a !== void 0 ? _a : imdsHost);
26
+ const url = new URL(imdsEndpointPath, process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST ?? imdsHost);
28
27
  const rawHeaders = {
29
28
  Accept: "application/json",
30
29
  // intentionally leave out the Metadata header to invoke an error from IMDS endpoint.
@@ -58,8 +57,7 @@ exports.imdsMsi = {
58
57
  throw new Error("Missing IdentityClient");
59
58
  }
60
59
  const requestOptions = prepareInvalidRequestOptions(resource);
61
- return tracing_js_1.tracingClient.withSpan("ManagedIdentityCredential-pingImdsEndpoint", getTokenOptions !== null && getTokenOptions !== void 0 ? getTokenOptions : {}, async (updatedOptions) => {
62
- var _a, _b;
60
+ return tracing_js_1.tracingClient.withSpan("ManagedIdentityCredential-pingImdsEndpoint", getTokenOptions ?? {}, async (updatedOptions) => {
63
61
  requestOptions.tracingOptions = updatedOptions.tracingOptions;
64
62
  // Create a request with a timeout since we expect that
65
63
  // not having a "Metadata" header should cause an error to be
@@ -67,7 +65,7 @@ exports.imdsMsi = {
67
65
  const request = (0, core_rest_pipeline_1.createPipelineRequest)(requestOptions);
68
66
  // Default to 1000 if the default of 0 is used.
69
67
  // Negative values can still be used to disable the timeout.
70
- request.timeout = ((_a = updatedOptions.requestOptions) === null || _a === void 0 ? void 0 : _a.timeout) || 1000;
68
+ request.timeout = updatedOptions.requestOptions?.timeout || 1000;
71
69
  // This MSI uses the imdsEndpoint to get the token, which only uses http://
72
70
  request.allowInsecureConnection = true;
73
71
  let response;
@@ -87,7 +85,7 @@ exports.imdsMsi = {
87
85
  return false;
88
86
  }
89
87
  if (response.status === 403) {
90
- if ((_b = response.bodyAsText) === null || _b === void 0 ? void 0 : _b.includes("unreachable")) {
88
+ if (response.bodyAsText?.includes("unreachable")) {
91
89
  logger.info(`${msiName}: The Azure IMDS endpoint is unavailable`);
92
90
  logger.info(`${msiName}: ${response.bodyAsText}`);
93
91
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"imdsMsi.js","sourceRoot":"","sources":["../../../../src/credentials/managedIdentityCredential/imdsMsi.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,kEAAqF;AACrF,gDAA2C;AAG3C,sDAAyD;AACzD,yCAAiD;AACjD,sDAAsD;AAGtD,MAAM,OAAO,GAAG,kCAAkC,CAAC;AACnD,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,OAAO,CAAC,CAAC;AAEzC,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAC1C,MAAM,gBAAgB,GAAG,iCAAiC,CAA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GAAG,OAAO,0CAA0C,CAAC,CAAC;oBAClE,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;oBAClD,OAAO,KAAK,CAAC;gBACf,CAAC;YACH,CAAC;YACD,yDAAyD;YACzD,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,wCAAwC,CAAC,CAAC;YAChE,OAAO,IAAI,CAAC;QACd,CAAC,CACF,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelineRequestOptions, PipelineResponse } from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders, createPipelineRequest } from \"@azure/core-rest-pipeline\";\nimport { isError } from \"@azure/core-util\";\n\nimport type { GetTokenOptions } from \"@azure/core-auth\";\nimport { credentialLogger } from \"../../util/logging.js\";\nimport { mapScopesToResource } from \"./utils.js\";\nimport { tracingClient } from \"../../util/tracing.js\";\nimport type { IdentityClient } from \"../../client/identityClient.js\";\n\nconst msiName = \"ManagedIdentityCredential - IMDS\";\nconst logger = credentialLogger(msiName);\n\nconst imdsHost = \"http://169.254.169.254\";\nconst imdsEndpointPath = \"/metadata/identity/oauth2/token\";\n\n/**\n * Generates an invalid request options to get a response quickly from IMDS endpoint.\n * The response indicates the availability of IMSD service; otherwise the request would time out.\n */\nfunction prepareInvalidRequestOptions(scopes: string | string[]): PipelineRequestOptions {\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n throw new Error(`${msiName}: Multiple scopes are not supported.`);\n }\n\n // Pod Identity will try to process this request even if the Metadata header is missing.\n // We can exclude the request query to ensure no IMDS endpoint tries to process the ping request.\n const url = new URL(imdsEndpointPath, process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST ?? imdsHost);\n\n const rawHeaders: Record<string, string> = {\n Accept: \"application/json\",\n // intentionally leave out the Metadata header to invoke an error from IMDS endpoint.\n };\n\n return {\n // intentionally not including any query\n url: `${url}`,\n method: \"GET\",\n headers: createHttpHeaders(rawHeaders),\n };\n}\n\n/**\n * Defines how to determine whether the Azure IMDS MSI is available.\n *\n * Actually getting the token once we determine IMDS is available is handled by MSAL.\n */\nexport const imdsMsi = {\n name: \"imdsMsi\",\n async isAvailable(options: {\n scopes: string | string[];\n identityClient?: IdentityClient;\n clientId?: string;\n resourceId?: string;\n getTokenOptions?: GetTokenOptions;\n }): Promise<boolean> {\n const { scopes, identityClient, getTokenOptions } = options;\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);\n return false;\n }\n\n // if the PodIdentityEndpoint environment variable was set no need to probe the endpoint, it can be assumed to exist\n if (process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST) {\n return true;\n }\n\n if (!identityClient) {\n throw new Error(\"Missing IdentityClient\");\n }\n\n const requestOptions = prepareInvalidRequestOptions(resource);\n\n return tracingClient.withSpan(\n \"ManagedIdentityCredential-pingImdsEndpoint\",\n getTokenOptions ?? {},\n async (updatedOptions) => {\n requestOptions.tracingOptions = updatedOptions.tracingOptions;\n\n // Create a request with a timeout since we expect that\n // not having a \"Metadata\" header should cause an error to be\n // returned quickly from the endpoint, proving its availability.\n const request = createPipelineRequest(requestOptions);\n\n // Default to 1000 if the default of 0 is used.\n // Negative values can still be used to disable the timeout.\n request.timeout = updatedOptions.requestOptions?.timeout || 1000;\n\n // This MSI uses the imdsEndpoint to get the token, which only uses http://\n request.allowInsecureConnection = true;\n let response: PipelineResponse;\n try {\n logger.info(`${msiName}: Pinging the Azure IMDS endpoint`);\n response = await identityClient.sendRequest(request);\n } catch (err: unknown) {\n // If the request failed, or Node.js was unable to establish a connection,\n // or the host was down, we'll assume the IMDS endpoint isn't available.\n if (isError(err)) {\n logger.verbose(`${msiName}: Caught error ${err.name}: ${err.message}`);\n }\n // This is a special case for Docker Desktop which responds with a 403 with a message that contains \"A socket operation was attempted to an unreachable network\" or \"A socket operation was attempted to an unreachable host\"\n // rather than just timing out, as expected.\n logger.info(`${msiName}: The Azure IMDS endpoint is unavailable`);\n return false;\n }\n if (response.status === 403) {\n if (response.bodyAsText?.includes(\"unreachable\")) {\n logger.info(`${msiName}: The Azure IMDS endpoint is unavailable`);\n logger.info(`${msiName}: ${response.bodyAsText}`);\n return false;\n }\n }\n // If we received any response, the endpoint is available\n logger.info(`${msiName}: The Azure IMDS endpoint is available`);\n return true;\n },\n );\n },\n};\n"]}
1
+ {"version":3,"file":"imdsMsi.js","sourceRoot":"","sources":["../../../../src/credentials/managedIdentityCredential/imdsMsi.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,kEAAqF;AACrF,gDAA2C;AAG3C,sDAAyD;AACzD,yCAAiD;AACjD,sDAAsD;AAGtD,MAAM,OAAO,GAAG,kCAAkC,CAAC;AACnD,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,OAAO,CAAC,CAAC;AAEzC,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAC1C,MAAM,gBAAgB,GAAG,iCAAiC,CAAC;AAE3D;;;GAGG;AACH,SAAS,4BAA4B,CAAC,MAAyB;IAC7D,MAAM,QAAQ,GAAG,IAAA,8BAAmB,EAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,sCAAsC,CAAC,CAAC;IACpE,CAAC;IAED,wFAAwF;IACxF,iGAAiG;IACjG,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAI,QAAQ,CAAC,CAAC;IAEjG,MAAM,UAAU,GAA2B;QACzC,MAAM,EAAE,kBAAkB;QAC1B,qFAAqF;KACtF,CAAC;IAEF,OAAO;QACL,wCAAwC;QACxC,GAAG,EAAE,GAAG,GAAG,EAAE;QACb,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,IAAA,sCAAiB,EAAC,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,GAAG,MAAM,cAAc,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YACvD,CAAC;YAAC,OAAO,GAAY,EAAE,CAAC;gBACtB,0EAA0E;gBAC1E,wEAAwE;gBACxE,IAAI,IAAA,mBAAO,EAAC,GAAG,CAAC,EAAE,CAAC;oBACjB,MAAM,CAAC,OAAO,CAAC,GAAG,OAAO,kBAAkB,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;gBACzE,CAAC;gBACD,6NAA6N;gBAC7N,4CAA4C;gBAC5C,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,0CAA0C,CAAC,CAAC;gBAClE,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBAC5B,IAAI,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;oBACjD,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,0CAA0C,CAAC,CAAC;oBAClE,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;oBAClD,OAAO,KAAK,CAAC;gBACf,CAAC;YACH,CAAC;YACD,yDAAyD;YACzD,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,wCAAwC,CAAC,CAAC;YAChE,OAAO,IAAI,CAAC;QACd,CAAC,CACF,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelineRequestOptions, PipelineResponse } from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders, createPipelineRequest } from \"@azure/core-rest-pipeline\";\nimport { isError } from \"@azure/core-util\";\n\nimport type { GetTokenOptions } from \"@azure/core-auth\";\nimport { credentialLogger } from \"../../util/logging.js\";\nimport { mapScopesToResource } from \"./utils.js\";\nimport { tracingClient } from \"../../util/tracing.js\";\nimport type { IdentityClient } from \"../../client/identityClient.js\";\n\nconst msiName = \"ManagedIdentityCredential - IMDS\";\nconst logger = credentialLogger(msiName);\n\nconst imdsHost = \"http://169.254.169.254\";\nconst imdsEndpointPath = \"/metadata/identity/oauth2/token\";\n\n/**\n * Generates an invalid request options to get a response quickly from IMDS endpoint.\n * The response indicates the availability of IMSD service; otherwise the request would time out.\n */\nfunction prepareInvalidRequestOptions(scopes: string | string[]): PipelineRequestOptions {\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n throw new Error(`${msiName}: Multiple scopes are not supported.`);\n }\n\n // Pod Identity will try to process this request even if the Metadata header is missing.\n // We can exclude the request query to ensure no IMDS endpoint tries to process the ping request.\n const url = new URL(imdsEndpointPath, process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST ?? imdsHost);\n\n const rawHeaders: Record<string, string> = {\n Accept: \"application/json\",\n // intentionally leave out the Metadata header to invoke an error from IMDS endpoint.\n };\n\n return {\n // intentionally not including any query\n url: `${url}`,\n method: \"GET\",\n headers: createHttpHeaders(rawHeaders),\n };\n}\n\n/**\n * Defines how to determine whether the Azure IMDS MSI is available.\n *\n * Actually getting the token once we determine IMDS is available is handled by MSAL.\n */\nexport const imdsMsi = {\n name: \"imdsMsi\",\n async isAvailable(options: {\n scopes: string | string[];\n identityClient?: IdentityClient;\n clientId?: string;\n resourceId?: string;\n getTokenOptions?: GetTokenOptions;\n }): Promise<boolean> {\n const { scopes, identityClient, getTokenOptions } = options;\n const resource = mapScopesToResource(scopes);\n if (!resource) {\n logger.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);\n return false;\n }\n\n // if the PodIdentityEndpoint environment variable was set no need to probe the endpoint, it can be assumed to exist\n if (process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST) {\n return true;\n }\n\n if (!identityClient) {\n throw new Error(\"Missing IdentityClient\");\n }\n\n const requestOptions = prepareInvalidRequestOptions(resource);\n\n return tracingClient.withSpan(\n \"ManagedIdentityCredential-pingImdsEndpoint\",\n getTokenOptions ?? {},\n async (updatedOptions) => {\n requestOptions.tracingOptions = updatedOptions.tracingOptions;\n\n // Create a request with a timeout since we expect that\n // not having a \"Metadata\" header should cause an error to be\n // returned quickly from the endpoint, proving its availability.\n const request = createPipelineRequest(requestOptions);\n\n // Default to 1000 if the default of 0 is used.\n // Negative values can still be used to disable the timeout.\n request.timeout = updatedOptions.requestOptions?.timeout || 1000;\n\n // This MSI uses the imdsEndpoint to get the token, which only uses http://\n request.allowInsecureConnection = true;\n let response: PipelineResponse;\n try {\n logger.info(`${msiName}: Pinging the Azure IMDS endpoint`);\n response = await identityClient.sendRequest(request);\n } catch (err: unknown) {\n // If the request failed, or Node.js was unable to establish a connection,\n // or the host was down, we'll assume the IMDS endpoint isn't available.\n if (isError(err)) {\n logger.verbose(`${msiName}: Caught error ${err.name}: ${err.message}`);\n }\n // This is a special case for Docker Desktop which responds with a 403 with a message that contains \"A socket operation was attempted to an unreachable network\" or \"A socket operation was attempted to an unreachable host\"\n // rather than just timing out, as expected.\n logger.info(`${msiName}: The Azure IMDS endpoint is unavailable`);\n return false;\n }\n if (response.status === 403) {\n if (response.bodyAsText?.includes(\"unreachable\")) {\n logger.info(`${msiName}: The Azure IMDS endpoint is unavailable`);\n logger.info(`${msiName}: ${response.bodyAsText}`);\n return false;\n }\n }\n // If we received any response, the endpoint is available\n logger.info(`${msiName}: The Azure IMDS endpoint is available`);\n return true;\n },\n );\n },\n};\n"]}
@@ -26,11 +26,11 @@ function imdsRetryPolicy(msiRetryConfig) {
26
26
  {
27
27
  name: "imdsRetryPolicy",
28
28
  retry: ({ retryCount, response }) => {
29
- if ((response === null || response === void 0 ? void 0 : response.status) !== 404 && (response === null || response === void 0 ? void 0 : response.status) !== 410) {
29
+ if (response?.status !== 404 && response?.status !== 410) {
30
30
  return { skipStrategy: true };
31
31
  }
32
32
  // For 410 responses, use a minimum 3-second delay to ensure at least 70 seconds total retry duration
33
- const initialDelayMs = (response === null || response === void 0 ? void 0 : response.status) === 410
33
+ const initialDelayMs = response?.status === 410
34
34
  ? Math.max(MIN_DELAY_FOR_410_MS, msiRetryConfig.startDelayInMs)
35
35
  : msiRetryConfig.startDelayInMs;
36
36
  return (0, core_util_1.calculateRetryDelay)(retryCount, {
@@ -1 +1 @@
1
- {"version":3,"file":"imdsRetryPolicy.js","sourceRoot":"","sources":["../../../../src/credentials/managedIdentityCredential/imdsRetryPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AA0BlC,0CA2BC;AAlDD,kEAAwD;AAGxD,gDAAuD;AAEvD,0EAA0E;AAC1E,MAAM,iCAAiC,GAAG,IAAI,GAAG,EAAE,CAAC;AAEpD,sEAAsE;AACtE,oFAAoF;AACpF,kFAAkF;AAClF,sEAAsE;AACtE,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAAC,cAA+C;IAC7E,OAAO,IAAA,gCAAW,EAChB;QACE;YACE,IAAI,EAAE,iBAAiB;YACvB,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;gBAClC,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,MAAK,GAAG,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,MAAK,GAAG,EAAE,CAAC;oBACzD,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;gBAChC,CAAC;gBAED,qGAAqG;gBACrG,MAAM,cAAc,GAClB,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,MAAK,GAAG;oBACtB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,cAAc,CAAC,cAAc,CAAC;oBAC/D,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC;gBAEpC,OAAO,IAAA,+BAAmB,EAAC,UAAU,EAAE;oBACrC,cAAc,EAAE,cAAc;oBAC9B,iBAAiB,EAAE,iCAAiC;iBACrD,CAAC,CAAC;YACL,CAAC;SACF;KACF,EACD;QACE,UAAU,EAAE,cAAc,CAAC,UAAU;KACtC,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelinePolicy } from \"@azure/core-rest-pipeline\";\nimport { retryPolicy } from \"@azure/core-rest-pipeline\";\n\nimport type { MSIConfiguration } from \"./models.js\";\nimport { calculateRetryDelay } from \"@azure/core-util\";\n\n// Matches the default retry configuration in expontentialRetryStrategy.ts\nconst DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1000 * 64;\n\n// For 410 responses, we need at least 70 seconds total retry duration\n// With 5 retries using exponential backoff: delays of d, 2d, 4d, 8d, 16d sum to 31d\n// Accounting for jitter (which can reduce delays by 20%), we need 31d * 0.8 >= 70\n// So we need d >= 70/24.8 = 2.82 seconds. Using 3 seconds to be safe.\nconst MIN_DELAY_FOR_410_MS = 3000;\n\n/**\n * An additional policy that retries on 404 and 410 errors. The default retry policy does not retry on\n * 404s or 410s, but the IMDS endpoint can return these when the token is not yet available or when\n * the identity is still being set up. This policy will retry on 404s and 410s with an exponential backoff.\n * For 410 responses, it uses a minimum 3-second initial delay to ensure at least 70 seconds total duration.\n *\n * @param msiRetryConfig - The retry configuration for the MSI credential.\n * @returns - The policy that will retry on 404s and 410s.\n */\nexport function imdsRetryPolicy(msiRetryConfig: MSIConfiguration[\"retryConfig\"]): PipelinePolicy {\n return retryPolicy(\n [\n {\n name: \"imdsRetryPolicy\",\n retry: ({ retryCount, response }) => {\n if (response?.status !== 404 && response?.status !== 410) {\n return { skipStrategy: true };\n }\n\n // For 410 responses, use a minimum 3-second delay to ensure at least 70 seconds total retry duration\n const initialDelayMs =\n response?.status === 410\n ? Math.max(MIN_DELAY_FOR_410_MS, msiRetryConfig.startDelayInMs)\n : msiRetryConfig.startDelayInMs;\n\n return calculateRetryDelay(retryCount, {\n retryDelayInMs: initialDelayMs,\n maxRetryDelayInMs: DEFAULT_CLIENT_MAX_RETRY_INTERVAL,\n });\n },\n },\n ],\n {\n maxRetries: msiRetryConfig.maxRetries,\n },\n );\n}\n"]}
1
+ {"version":3,"file":"imdsRetryPolicy.js","sourceRoot":"","sources":["../../../../src/credentials/managedIdentityCredential/imdsRetryPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AA0BlC,0CA2BC;AAlDD,kEAAwD;AAGxD,gDAAuD;AAEvD,0EAA0E;AAC1E,MAAM,iCAAiC,GAAG,IAAI,GAAG,EAAE,CAAC;AAEpD,sEAAsE;AACtE,oFAAoF;AACpF,kFAAkF;AAClF,sEAAsE;AACtE,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAAC,cAA+C;IAC7E,OAAO,IAAA,gCAAW,EAChB;QACE;YACE,IAAI,EAAE,iBAAiB;YACvB,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE;gBAClC,IAAI,QAAQ,EAAE,MAAM,KAAK,GAAG,IAAI,QAAQ,EAAE,MAAM,KAAK,GAAG,EAAE,CAAC;oBACzD,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;gBAChC,CAAC;gBAED,qGAAqG;gBACrG,MAAM,cAAc,GAClB,QAAQ,EAAE,MAAM,KAAK,GAAG;oBACtB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,cAAc,CAAC,cAAc,CAAC;oBAC/D,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC;gBAEpC,OAAO,IAAA,+BAAmB,EAAC,UAAU,EAAE;oBACrC,cAAc,EAAE,cAAc;oBAC9B,iBAAiB,EAAE,iCAAiC;iBACrD,CAAC,CAAC;YACL,CAAC;SACF;KACF,EACD;QACE,UAAU,EAAE,cAAc,CAAC,UAAU;KACtC,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelinePolicy } from \"@azure/core-rest-pipeline\";\nimport { retryPolicy } from \"@azure/core-rest-pipeline\";\n\nimport type { MSIConfiguration } from \"./models.js\";\nimport { calculateRetryDelay } from \"@azure/core-util\";\n\n// Matches the default retry configuration in expontentialRetryStrategy.ts\nconst DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1000 * 64;\n\n// For 410 responses, we need at least 70 seconds total retry duration\n// With 5 retries using exponential backoff: delays of d, 2d, 4d, 8d, 16d sum to 31d\n// Accounting for jitter (which can reduce delays by 20%), we need 31d * 0.8 >= 70\n// So we need d >= 70/24.8 = 2.82 seconds. Using 3 seconds to be safe.\nconst MIN_DELAY_FOR_410_MS = 3000;\n\n/**\n * An additional policy that retries on 404 and 410 errors. The default retry policy does not retry on\n * 404s or 410s, but the IMDS endpoint can return these when the token is not yet available or when\n * the identity is still being set up. This policy will retry on 404s and 410s with an exponential backoff.\n * For 410 responses, it uses a minimum 3-second initial delay to ensure at least 70 seconds total duration.\n *\n * @param msiRetryConfig - The retry configuration for the MSI credential.\n * @returns - The policy that will retry on 404s and 410s.\n */\nexport function imdsRetryPolicy(msiRetryConfig: MSIConfiguration[\"retryConfig\"]): PipelinePolicy {\n return retryPolicy(\n [\n {\n name: \"imdsRetryPolicy\",\n retry: ({ retryCount, response }) => {\n if (response?.status !== 404 && response?.status !== 410) {\n return { skipStrategy: true };\n }\n\n // For 410 responses, use a minimum 3-second delay to ensure at least 70 seconds total retry duration\n const initialDelayMs =\n response?.status === 410\n ? Math.max(MIN_DELAY_FOR_410_MS, msiRetryConfig.startDelayInMs)\n : msiRetryConfig.startDelayInMs;\n\n return calculateRetryDelay(retryCount, {\n retryDelayInMs: initialDelayMs,\n maxRetryDelayInMs: DEFAULT_CLIENT_MAX_RETRY_INTERVAL,\n });\n },\n },\n ],\n {\n maxRetries: msiRetryConfig.maxRetries,\n },\n );\n}\n"]}
@@ -24,28 +24,33 @@ const logger = (0, logging_js_1.credentialLogger)("ManagedIdentityCredential");
24
24
  * https://learn.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview
25
25
  */
26
26
  class ManagedIdentityCredential {
27
+ managedIdentityApp;
28
+ identityClient;
29
+ clientId;
30
+ resourceId;
31
+ objectId;
32
+ msiRetryConfig = {
33
+ maxRetries: 5,
34
+ startDelayInMs: 800,
35
+ intervalIncrement: 2,
36
+ };
37
+ isAvailableIdentityClient;
27
38
  /**
28
39
  * @internal
29
40
  * @hidden
30
41
  */
31
42
  constructor(clientIdOrOptions, options) {
32
- var _a, _b;
33
- this.msiRetryConfig = {
34
- maxRetries: 5,
35
- startDelayInMs: 800,
36
- intervalIncrement: 2,
37
- };
38
43
  let _options;
39
44
  if (typeof clientIdOrOptions === "string") {
40
45
  this.clientId = clientIdOrOptions;
41
- _options = options !== null && options !== void 0 ? options : {};
46
+ _options = options ?? {};
42
47
  }
43
48
  else {
44
- this.clientId = clientIdOrOptions === null || clientIdOrOptions === void 0 ? void 0 : clientIdOrOptions.clientId;
45
- _options = clientIdOrOptions !== null && clientIdOrOptions !== void 0 ? clientIdOrOptions : {};
49
+ this.clientId = clientIdOrOptions?.clientId;
50
+ _options = clientIdOrOptions ?? {};
46
51
  }
47
- this.resourceId = _options === null || _options === void 0 ? void 0 : _options.resourceId;
48
- this.objectId = _options === null || _options === void 0 ? void 0 : _options.objectId;
52
+ this.resourceId = _options?.resourceId;
53
+ this.objectId = _options?.objectId;
49
54
  // For JavaScript users.
50
55
  const providedIds = [
51
56
  { key: "clientId", value: this.clientId },
@@ -57,10 +62,13 @@ class ManagedIdentityCredential {
57
62
  }
58
63
  // ManagedIdentity uses http for local requests
59
64
  _options.allowInsecureConnection = true;
60
- if (((_a = _options.retryOptions) === null || _a === void 0 ? void 0 : _a.maxRetries) !== undefined) {
65
+ if (_options.retryOptions?.maxRetries !== undefined) {
61
66
  this.msiRetryConfig.maxRetries = _options.retryOptions.maxRetries;
62
67
  }
63
- this.identityClient = new identityClient_js_1.IdentityClient(Object.assign(Object.assign({}, _options), { additionalPolicies: [{ policy: (0, imdsRetryPolicy_js_1.imdsRetryPolicy)(this.msiRetryConfig), position: "perCall" }] }));
68
+ this.identityClient = new identityClient_js_1.IdentityClient({
69
+ ..._options,
70
+ additionalPolicies: [{ policy: (0, imdsRetryPolicy_js_1.imdsRetryPolicy)(this.msiRetryConfig), position: "perCall" }],
71
+ });
64
72
  this.managedIdentityApp = new msal_node_1.ManagedIdentityApplication({
65
73
  managedIdentityIdParams: {
66
74
  userAssignedClientId: this.clientId,
@@ -72,14 +80,17 @@ class ManagedIdentityCredential {
72
80
  networkClient: this.identityClient,
73
81
  loggerOptions: {
74
82
  logLevel: (0, utils_js_1.getMSALLogLevel)((0, logger_1.getLogLevel)()),
75
- piiLoggingEnabled: (_b = _options.loggingOptions) === null || _b === void 0 ? void 0 : _b.enableUnsafeSupportLogging,
83
+ piiLoggingEnabled: _options.loggingOptions?.enableUnsafeSupportLogging,
76
84
  loggerCallback: (0, utils_js_1.defaultLoggerCallback)(logger),
77
85
  },
78
86
  },
79
87
  });
80
- this.isAvailableIdentityClient = new identityClient_js_1.IdentityClient(Object.assign(Object.assign({}, _options), { retryOptions: {
88
+ this.isAvailableIdentityClient = new identityClient_js_1.IdentityClient({
89
+ ..._options,
90
+ retryOptions: {
81
91
  maxRetries: 0,
82
- } }));
92
+ },
93
+ });
83
94
  const managedIdentitySource = this.managedIdentityApp.getManagedIdentitySource();
84
95
  // CloudShell MSI will ignore any user-assigned identity passed as parameters. To avoid confusion, we prevent this from happening as early as possible.
85
96
  if (managedIdentitySource === "CloudShell") {
@@ -126,7 +137,6 @@ class ManagedIdentityCredential {
126
137
  throw new errors_js_1.CredentialUnavailableError(`ManagedIdentityCredential: Multiple scopes are not supported. Scopes: ${JSON.stringify(scopes)}`);
127
138
  }
128
139
  return tracing_js_1.tracingClient.withSpan("ManagedIdentityCredential.getToken", options, async () => {
129
- var _a;
130
140
  try {
131
141
  const isTokenExchangeMsi = await tokenExchangeMsi_js_1.tokenExchangeMsi.isAvailable(this.clientId);
132
142
  // Most scenarios are handled by MSAL except for two:
@@ -180,7 +190,7 @@ class ManagedIdentityCredential {
180
190
  return {
181
191
  expiresOnTimestamp: token.expiresOn.getTime(),
182
192
  token: token.accessToken,
183
- refreshAfterTimestamp: (_a = token.refreshOn) === null || _a === void 0 ? void 0 : _a.getTime(),
193
+ refreshAfterTimestamp: token.refreshOn?.getTime(),
184
194
  tokenType: "Bearer",
185
195
  };
186
196
  }