@azure/identity 4.10.3-alpha.20250714.3 → 4.11.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (359) 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/defaultAzureCredentialFunctions.d.ts +62 -0
  17. package/dist/browser/credentials/defaultAzureCredentialFunctions.d.ts.map +1 -0
  18. package/dist/browser/credentials/defaultAzureCredentialFunctions.js +143 -0
  19. package/dist/browser/credentials/defaultAzureCredentialFunctions.js.map +1 -0
  20. package/dist/browser/credentials/interactiveBrowserCredential-browser.mjs.map +1 -1
  21. package/dist/browser/credentials/interactiveBrowserCredential.js +19 -6
  22. package/dist/browser/credentials/managedIdentityCredential/imdsMsi.js +4 -6
  23. package/dist/browser/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  24. package/dist/browser/credentials/managedIdentityCredential/imdsRetryPolicy.js +2 -2
  25. package/dist/browser/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
  26. package/dist/browser/credentials/managedIdentityCredential/tokenExchangeMsi.js +7 -1
  27. package/dist/browser/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
  28. package/dist/browser/credentials/usernamePasswordCredential-browser.mjs.map +1 -1
  29. package/dist/browser/credentials/usernamePasswordCredential.js +7 -1
  30. package/dist/browser/credentials/visualStudioCodeCredentialOptions.d.ts +0 -4
  31. package/dist/browser/credentials/visualStudioCodeCredentialOptions.d.ts.map +1 -1
  32. package/dist/browser/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
  33. package/dist/browser/credentials/visualStudioCodeCredentialPlugin.d.ts +0 -4
  34. package/dist/browser/credentials/visualStudioCodeCredentialPlugin.d.ts.map +1 -1
  35. package/dist/browser/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
  36. package/dist/browser/errors.js +21 -0
  37. package/dist/browser/errors.js.map +1 -1
  38. package/dist/browser/msal/browserFlows/msalBrowserCommon.js +15 -15
  39. package/dist/browser/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  40. package/dist/browser/msal/nodeFlows/msalClient.d.ts +13 -0
  41. package/dist/browser/msal/nodeFlows/msalClient.d.ts.map +1 -1
  42. package/dist/browser/msal/nodeFlows/msalClient.js +127 -94
  43. package/dist/browser/msal/nodeFlows/msalClient.js.map +1 -1
  44. package/dist/browser/msal/nodeFlows/msalPlugins.d.ts +19 -1
  45. package/dist/browser/msal/nodeFlows/msalPlugins.d.ts.map +1 -1
  46. package/dist/browser/msal/nodeFlows/msalPlugins.js +61 -16
  47. package/dist/browser/msal/nodeFlows/msalPlugins.js.map +1 -1
  48. package/dist/browser/msal/utils.js +3 -4
  49. package/dist/browser/msal/utils.js.map +1 -1
  50. package/dist/browser/plugins/provider.d.ts +2 -2
  51. package/dist/browser/plugins/provider.d.ts.map +1 -1
  52. package/dist/browser/plugins/provider.js.map +1 -1
  53. package/dist/browser/regionalAuthority.js +1 -2
  54. package/dist/browser/regionalAuthority.js.map +1 -1
  55. package/dist/browser/tokenProvider.js +1 -2
  56. package/dist/browser/tokenProvider.js.map +1 -1
  57. package/dist/browser/util/logging.js +6 -2
  58. package/dist/browser/util/logging.js.map +1 -1
  59. package/dist/browser/util/processMultiTenantRequest-browser.mjs.map +1 -1
  60. package/dist/browser/util/processMultiTenantRequest.js +1 -2
  61. package/dist/browser/util/processUtils.d.ts +1 -1
  62. package/dist/browser/util/processUtils.d.ts.map +1 -1
  63. package/dist/browser/util/processUtils.js +1 -1
  64. package/dist/browser/util/processUtils.js.map +1 -1
  65. package/dist/commonjs/client/identityClient.js +30 -18
  66. package/dist/commonjs/client/identityClient.js.map +1 -1
  67. package/dist/commonjs/constants.d.ts +1 -1
  68. package/dist/commonjs/constants.d.ts.map +1 -1
  69. package/dist/commonjs/constants.js +1 -1
  70. package/dist/commonjs/constants.js.map +1 -1
  71. package/dist/commonjs/credentials/authorizationCodeCredential.js +17 -3
  72. package/dist/commonjs/credentials/authorizationCodeCredential.js.map +1 -1
  73. package/dist/commonjs/credentials/azureCliCredential.js +15 -12
  74. package/dist/commonjs/credentials/azureCliCredential.js.map +1 -1
  75. package/dist/commonjs/credentials/azureDeveloperCliCredential.js +12 -10
  76. package/dist/commonjs/credentials/azureDeveloperCliCredential.js.map +1 -1
  77. package/dist/commonjs/credentials/azurePipelinesCredential.js +9 -5
  78. package/dist/commonjs/credentials/azurePipelinesCredential.js.map +1 -1
  79. package/dist/commonjs/credentials/azurePowerShellCredential.js +10 -7
  80. package/dist/commonjs/credentials/azurePowerShellCredential.js.map +1 -1
  81. package/dist/commonjs/credentials/brokerCredential.d.ts +35 -0
  82. package/dist/commonjs/credentials/brokerCredential.d.ts.map +1 -0
  83. package/dist/commonjs/credentials/brokerCredential.js +73 -0
  84. package/dist/commonjs/credentials/brokerCredential.js.map +1 -0
  85. package/dist/commonjs/credentials/chainedTokenCredential.js +1 -1
  86. package/dist/commonjs/credentials/chainedTokenCredential.js.map +1 -1
  87. package/dist/commonjs/credentials/clientAssertionCredential.js +11 -2
  88. package/dist/commonjs/credentials/clientAssertionCredential.js.map +1 -1
  89. package/dist/commonjs/credentials/clientCertificateCredential.js +19 -9
  90. package/dist/commonjs/credentials/clientCertificateCredential.js.map +1 -1
  91. package/dist/commonjs/credentials/clientSecretCredential.js +10 -2
  92. package/dist/commonjs/credentials/clientSecretCredential.js.map +1 -1
  93. package/dist/commonjs/credentials/defaultAzureCredential.d.ts +12 -14
  94. package/dist/commonjs/credentials/defaultAzureCredential.d.ts.map +1 -1
  95. package/dist/commonjs/credentials/defaultAzureCredential.js +48 -113
  96. package/dist/commonjs/credentials/defaultAzureCredential.js.map +1 -1
  97. package/dist/commonjs/credentials/defaultAzureCredentialFunctions.d.ts +62 -0
  98. package/dist/commonjs/credentials/defaultAzureCredentialFunctions.d.ts.map +1 -0
  99. package/dist/commonjs/credentials/defaultAzureCredentialFunctions.js +153 -0
  100. package/dist/commonjs/credentials/defaultAzureCredentialFunctions.js.map +1 -0
  101. package/dist/commonjs/credentials/deviceCodeCredential.js +24 -10
  102. package/dist/commonjs/credentials/deviceCodeCredential.js.map +1 -1
  103. package/dist/commonjs/credentials/environmentCredential.js +4 -6
  104. package/dist/commonjs/credentials/environmentCredential.js.map +1 -1
  105. package/dist/commonjs/credentials/interactiveBrowserCredential.js +30 -11
  106. package/dist/commonjs/credentials/interactiveBrowserCredential.js.map +1 -1
  107. package/dist/commonjs/credentials/managedIdentityCredential/imdsMsi.js +4 -6
  108. package/dist/commonjs/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  109. package/dist/commonjs/credentials/managedIdentityCredential/imdsRetryPolicy.js +2 -2
  110. package/dist/commonjs/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
  111. package/dist/commonjs/credentials/managedIdentityCredential/index.js +28 -18
  112. package/dist/commonjs/credentials/managedIdentityCredential/index.js.map +1 -1
  113. package/dist/commonjs/credentials/managedIdentityCredential/tokenExchangeMsi.js +7 -1
  114. package/dist/commonjs/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
  115. package/dist/commonjs/credentials/onBehalfOfCredential.js +13 -1
  116. package/dist/commonjs/credentials/onBehalfOfCredential.js.map +1 -1
  117. package/dist/commonjs/credentials/usernamePasswordCredential.js +10 -2
  118. package/dist/commonjs/credentials/usernamePasswordCredential.js.map +1 -1
  119. package/dist/commonjs/credentials/visualStudioCodeCredential.d.ts +15 -26
  120. package/dist/commonjs/credentials/visualStudioCodeCredential.d.ts.map +1 -1
  121. package/dist/commonjs/credentials/visualStudioCodeCredential.js +69 -130
  122. package/dist/commonjs/credentials/visualStudioCodeCredential.js.map +1 -1
  123. package/dist/commonjs/credentials/visualStudioCodeCredentialOptions.d.ts +0 -4
  124. package/dist/commonjs/credentials/visualStudioCodeCredentialOptions.d.ts.map +1 -1
  125. package/dist/commonjs/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
  126. package/dist/commonjs/credentials/visualStudioCodeCredentialPlugin.d.ts +0 -4
  127. package/dist/commonjs/credentials/visualStudioCodeCredentialPlugin.d.ts.map +1 -1
  128. package/dist/commonjs/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
  129. package/dist/commonjs/credentials/workloadIdentityCredential.js +5 -3
  130. package/dist/commonjs/credentials/workloadIdentityCredential.js.map +1 -1
  131. package/dist/commonjs/errors.js +21 -0
  132. package/dist/commonjs/errors.js.map +1 -1
  133. package/dist/commonjs/msal/browserFlows/msalBrowserCommon.js +15 -15
  134. package/dist/commonjs/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  135. package/dist/commonjs/msal/nodeFlows/msalClient.d.ts +13 -0
  136. package/dist/commonjs/msal/nodeFlows/msalClient.d.ts.map +1 -1
  137. package/dist/commonjs/msal/nodeFlows/msalClient.js +127 -94
  138. package/dist/commonjs/msal/nodeFlows/msalClient.js.map +1 -1
  139. package/dist/commonjs/msal/nodeFlows/msalPlugins.d.ts +19 -1
  140. package/dist/commonjs/msal/nodeFlows/msalPlugins.d.ts.map +1 -1
  141. package/dist/commonjs/msal/nodeFlows/msalPlugins.js +63 -17
  142. package/dist/commonjs/msal/nodeFlows/msalPlugins.js.map +1 -1
  143. package/dist/commonjs/msal/utils.js +3 -4
  144. package/dist/commonjs/msal/utils.js.map +1 -1
  145. package/dist/commonjs/plugins/consumer.d.ts.map +1 -1
  146. package/dist/commonjs/plugins/consumer.js +1 -2
  147. package/dist/commonjs/plugins/consumer.js.map +1 -1
  148. package/dist/commonjs/plugins/provider.d.ts +2 -2
  149. package/dist/commonjs/plugins/provider.d.ts.map +1 -1
  150. package/dist/commonjs/plugins/provider.js.map +1 -1
  151. package/dist/commonjs/regionalAuthority.js +1 -2
  152. package/dist/commonjs/regionalAuthority.js.map +1 -1
  153. package/dist/commonjs/tokenProvider.js +1 -2
  154. package/dist/commonjs/tokenProvider.js.map +1 -1
  155. package/dist/commonjs/util/logging.js +6 -2
  156. package/dist/commonjs/util/logging.js.map +1 -1
  157. package/dist/commonjs/util/processMultiTenantRequest.js +2 -3
  158. package/dist/commonjs/util/processMultiTenantRequest.js.map +1 -1
  159. package/dist/commonjs/util/processUtils.d.ts +1 -1
  160. package/dist/commonjs/util/processUtils.d.ts.map +1 -1
  161. package/dist/commonjs/util/processUtils.js +2 -2
  162. package/dist/commonjs/util/processUtils.js.map +1 -1
  163. package/dist/esm/client/identityClient.js +30 -18
  164. package/dist/esm/client/identityClient.js.map +1 -1
  165. package/dist/esm/constants.d.ts +1 -1
  166. package/dist/esm/constants.d.ts.map +1 -1
  167. package/dist/esm/constants.js +1 -1
  168. package/dist/esm/constants.js.map +1 -1
  169. package/dist/esm/credentials/authorizationCodeCredential.js +17 -3
  170. package/dist/esm/credentials/authorizationCodeCredential.js.map +1 -1
  171. package/dist/esm/credentials/azureCliCredential.js +15 -12
  172. package/dist/esm/credentials/azureCliCredential.js.map +1 -1
  173. package/dist/esm/credentials/azureDeveloperCliCredential.js +12 -10
  174. package/dist/esm/credentials/azureDeveloperCliCredential.js.map +1 -1
  175. package/dist/esm/credentials/azurePipelinesCredential.js +9 -5
  176. package/dist/esm/credentials/azurePipelinesCredential.js.map +1 -1
  177. package/dist/esm/credentials/azurePowerShellCredential.js +10 -7
  178. package/dist/esm/credentials/azurePowerShellCredential.js.map +1 -1
  179. package/dist/esm/credentials/brokerCredential.d.ts +35 -0
  180. package/dist/esm/credentials/brokerCredential.d.ts.map +1 -0
  181. package/dist/esm/credentials/brokerCredential.js +69 -0
  182. package/dist/esm/credentials/brokerCredential.js.map +1 -0
  183. package/dist/esm/credentials/chainedTokenCredential.js +1 -1
  184. package/dist/esm/credentials/chainedTokenCredential.js.map +1 -1
  185. package/dist/esm/credentials/clientAssertionCredential.js +11 -2
  186. package/dist/esm/credentials/clientAssertionCredential.js.map +1 -1
  187. package/dist/esm/credentials/clientCertificateCredential.js +19 -9
  188. package/dist/esm/credentials/clientCertificateCredential.js.map +1 -1
  189. package/dist/esm/credentials/clientSecretCredential.js +10 -2
  190. package/dist/esm/credentials/clientSecretCredential.js.map +1 -1
  191. package/dist/esm/credentials/defaultAzureCredential.d.ts +12 -14
  192. package/dist/esm/credentials/defaultAzureCredential.d.ts.map +1 -1
  193. package/dist/esm/credentials/defaultAzureCredential.js +43 -106
  194. package/dist/esm/credentials/defaultAzureCredential.js.map +1 -1
  195. package/dist/esm/credentials/defaultAzureCredentialFunctions.d.ts +62 -0
  196. package/dist/esm/credentials/defaultAzureCredentialFunctions.d.ts.map +1 -0
  197. package/dist/esm/credentials/defaultAzureCredentialFunctions.js +143 -0
  198. package/dist/esm/credentials/defaultAzureCredentialFunctions.js.map +1 -0
  199. package/dist/esm/credentials/deviceCodeCredential.js +24 -10
  200. package/dist/esm/credentials/deviceCodeCredential.js.map +1 -1
  201. package/dist/esm/credentials/environmentCredential.js +4 -6
  202. package/dist/esm/credentials/environmentCredential.js.map +1 -1
  203. package/dist/esm/credentials/interactiveBrowserCredential.js +30 -11
  204. package/dist/esm/credentials/interactiveBrowserCredential.js.map +1 -1
  205. package/dist/esm/credentials/managedIdentityCredential/imdsMsi.js +4 -6
  206. package/dist/esm/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  207. package/dist/esm/credentials/managedIdentityCredential/imdsRetryPolicy.js +2 -2
  208. package/dist/esm/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
  209. package/dist/esm/credentials/managedIdentityCredential/index.js +28 -18
  210. package/dist/esm/credentials/managedIdentityCredential/index.js.map +1 -1
  211. package/dist/esm/credentials/managedIdentityCredential/tokenExchangeMsi.js +7 -1
  212. package/dist/esm/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
  213. package/dist/esm/credentials/onBehalfOfCredential.js +13 -1
  214. package/dist/esm/credentials/onBehalfOfCredential.js.map +1 -1
  215. package/dist/esm/credentials/usernamePasswordCredential.js +10 -2
  216. package/dist/esm/credentials/usernamePasswordCredential.js.map +1 -1
  217. package/dist/esm/credentials/visualStudioCodeCredential.d.ts +15 -26
  218. package/dist/esm/credentials/visualStudioCodeCredential.d.ts.map +1 -1
  219. package/dist/esm/credentials/visualStudioCodeCredential.js +69 -128
  220. package/dist/esm/credentials/visualStudioCodeCredential.js.map +1 -1
  221. package/dist/esm/credentials/visualStudioCodeCredentialOptions.d.ts +0 -4
  222. package/dist/esm/credentials/visualStudioCodeCredentialOptions.d.ts.map +1 -1
  223. package/dist/esm/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
  224. package/dist/esm/credentials/visualStudioCodeCredentialPlugin.d.ts +0 -4
  225. package/dist/esm/credentials/visualStudioCodeCredentialPlugin.d.ts.map +1 -1
  226. package/dist/esm/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
  227. package/dist/esm/credentials/workloadIdentityCredential.js +5 -3
  228. package/dist/esm/credentials/workloadIdentityCredential.js.map +1 -1
  229. package/dist/esm/errors.js +21 -0
  230. package/dist/esm/errors.js.map +1 -1
  231. package/dist/esm/msal/browserFlows/msalBrowserCommon.js +15 -15
  232. package/dist/esm/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  233. package/dist/esm/msal/nodeFlows/msalClient.d.ts +13 -0
  234. package/dist/esm/msal/nodeFlows/msalClient.d.ts.map +1 -1
  235. package/dist/esm/msal/nodeFlows/msalClient.js +127 -94
  236. package/dist/esm/msal/nodeFlows/msalClient.js.map +1 -1
  237. package/dist/esm/msal/nodeFlows/msalPlugins.d.ts +19 -1
  238. package/dist/esm/msal/nodeFlows/msalPlugins.d.ts.map +1 -1
  239. package/dist/esm/msal/nodeFlows/msalPlugins.js +61 -16
  240. package/dist/esm/msal/nodeFlows/msalPlugins.js.map +1 -1
  241. package/dist/esm/msal/utils.js +3 -4
  242. package/dist/esm/msal/utils.js.map +1 -1
  243. package/dist/esm/plugins/consumer.d.ts.map +1 -1
  244. package/dist/esm/plugins/consumer.js +2 -3
  245. package/dist/esm/plugins/consumer.js.map +1 -1
  246. package/dist/esm/plugins/provider.d.ts +2 -2
  247. package/dist/esm/plugins/provider.d.ts.map +1 -1
  248. package/dist/esm/plugins/provider.js.map +1 -1
  249. package/dist/esm/regionalAuthority.js +1 -2
  250. package/dist/esm/regionalAuthority.js.map +1 -1
  251. package/dist/esm/tokenProvider.js +1 -2
  252. package/dist/esm/tokenProvider.js.map +1 -1
  253. package/dist/esm/util/logging.js +6 -2
  254. package/dist/esm/util/logging.js.map +1 -1
  255. package/dist/esm/util/processMultiTenantRequest.js +2 -3
  256. package/dist/esm/util/processMultiTenantRequest.js.map +1 -1
  257. package/dist/esm/util/processUtils.d.ts +1 -1
  258. package/dist/esm/util/processUtils.d.ts.map +1 -1
  259. package/dist/esm/util/processUtils.js +1 -1
  260. package/dist/esm/util/processUtils.js.map +1 -1
  261. package/dist/workerd/client/identityClient.js +30 -18
  262. package/dist/workerd/client/identityClient.js.map +1 -1
  263. package/dist/workerd/constants.d.ts +1 -1
  264. package/dist/workerd/constants.d.ts.map +1 -1
  265. package/dist/workerd/constants.js +1 -1
  266. package/dist/workerd/constants.js.map +1 -1
  267. package/dist/workerd/credentials/authorizationCodeCredential.js +17 -3
  268. package/dist/workerd/credentials/authorizationCodeCredential.js.map +1 -1
  269. package/dist/workerd/credentials/azureCliCredential.js +15 -12
  270. package/dist/workerd/credentials/azureCliCredential.js.map +1 -1
  271. package/dist/workerd/credentials/azureDeveloperCliCredential.js +12 -10
  272. package/dist/workerd/credentials/azureDeveloperCliCredential.js.map +1 -1
  273. package/dist/workerd/credentials/azurePipelinesCredential.js +9 -5
  274. package/dist/workerd/credentials/azurePipelinesCredential.js.map +1 -1
  275. package/dist/workerd/credentials/azurePowerShellCredential.js +10 -7
  276. package/dist/workerd/credentials/azurePowerShellCredential.js.map +1 -1
  277. package/dist/workerd/credentials/brokerCredential.d.ts +35 -0
  278. package/dist/workerd/credentials/brokerCredential.d.ts.map +1 -0
  279. package/dist/workerd/credentials/brokerCredential.js +69 -0
  280. package/dist/workerd/credentials/brokerCredential.js.map +1 -0
  281. package/dist/workerd/credentials/chainedTokenCredential.js +1 -1
  282. package/dist/workerd/credentials/chainedTokenCredential.js.map +1 -1
  283. package/dist/workerd/credentials/clientAssertionCredential.js +11 -2
  284. package/dist/workerd/credentials/clientAssertionCredential.js.map +1 -1
  285. package/dist/workerd/credentials/clientCertificateCredential.js +19 -9
  286. package/dist/workerd/credentials/clientCertificateCredential.js.map +1 -1
  287. package/dist/workerd/credentials/clientSecretCredential.js +10 -2
  288. package/dist/workerd/credentials/clientSecretCredential.js.map +1 -1
  289. package/dist/workerd/credentials/defaultAzureCredential.d.ts +12 -14
  290. package/dist/workerd/credentials/defaultAzureCredential.d.ts.map +1 -1
  291. package/dist/workerd/credentials/defaultAzureCredential.js +43 -106
  292. package/dist/workerd/credentials/defaultAzureCredential.js.map +1 -1
  293. package/dist/workerd/credentials/defaultAzureCredentialFunctions.d.ts +62 -0
  294. package/dist/workerd/credentials/defaultAzureCredentialFunctions.d.ts.map +1 -0
  295. package/dist/workerd/credentials/defaultAzureCredentialFunctions.js +143 -0
  296. package/dist/workerd/credentials/defaultAzureCredentialFunctions.js.map +1 -0
  297. package/dist/workerd/credentials/deviceCodeCredential.js +24 -10
  298. package/dist/workerd/credentials/deviceCodeCredential.js.map +1 -1
  299. package/dist/workerd/credentials/environmentCredential.js +4 -6
  300. package/dist/workerd/credentials/environmentCredential.js.map +1 -1
  301. package/dist/workerd/credentials/interactiveBrowserCredential.js +30 -11
  302. package/dist/workerd/credentials/interactiveBrowserCredential.js.map +1 -1
  303. package/dist/workerd/credentials/managedIdentityCredential/imdsMsi.js +4 -6
  304. package/dist/workerd/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  305. package/dist/workerd/credentials/managedIdentityCredential/imdsRetryPolicy.js +2 -2
  306. package/dist/workerd/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
  307. package/dist/workerd/credentials/managedIdentityCredential/index.js +28 -18
  308. package/dist/workerd/credentials/managedIdentityCredential/index.js.map +1 -1
  309. package/dist/workerd/credentials/managedIdentityCredential/tokenExchangeMsi.js +7 -1
  310. package/dist/workerd/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
  311. package/dist/workerd/credentials/onBehalfOfCredential.js +13 -1
  312. package/dist/workerd/credentials/onBehalfOfCredential.js.map +1 -1
  313. package/dist/workerd/credentials/usernamePasswordCredential.js +10 -2
  314. package/dist/workerd/credentials/usernamePasswordCredential.js.map +1 -1
  315. package/dist/workerd/credentials/visualStudioCodeCredential.d.ts +15 -26
  316. package/dist/workerd/credentials/visualStudioCodeCredential.d.ts.map +1 -1
  317. package/dist/workerd/credentials/visualStudioCodeCredential.js +69 -128
  318. package/dist/workerd/credentials/visualStudioCodeCredential.js.map +1 -1
  319. package/dist/workerd/credentials/visualStudioCodeCredentialOptions.d.ts +0 -4
  320. package/dist/workerd/credentials/visualStudioCodeCredentialOptions.d.ts.map +1 -1
  321. package/dist/workerd/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
  322. package/dist/workerd/credentials/visualStudioCodeCredentialPlugin.d.ts +0 -4
  323. package/dist/workerd/credentials/visualStudioCodeCredentialPlugin.d.ts.map +1 -1
  324. package/dist/workerd/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
  325. package/dist/workerd/credentials/workloadIdentityCredential.js +5 -3
  326. package/dist/workerd/credentials/workloadIdentityCredential.js.map +1 -1
  327. package/dist/workerd/errors.js +21 -0
  328. package/dist/workerd/errors.js.map +1 -1
  329. package/dist/workerd/msal/browserFlows/msalBrowserCommon.js +15 -15
  330. package/dist/workerd/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  331. package/dist/workerd/msal/nodeFlows/msalClient.d.ts +13 -0
  332. package/dist/workerd/msal/nodeFlows/msalClient.d.ts.map +1 -1
  333. package/dist/workerd/msal/nodeFlows/msalClient.js +127 -94
  334. package/dist/workerd/msal/nodeFlows/msalClient.js.map +1 -1
  335. package/dist/workerd/msal/nodeFlows/msalPlugins.d.ts +19 -1
  336. package/dist/workerd/msal/nodeFlows/msalPlugins.d.ts.map +1 -1
  337. package/dist/workerd/msal/nodeFlows/msalPlugins.js +61 -16
  338. package/dist/workerd/msal/nodeFlows/msalPlugins.js.map +1 -1
  339. package/dist/workerd/msal/utils.js +3 -4
  340. package/dist/workerd/msal/utils.js.map +1 -1
  341. package/dist/workerd/plugins/consumer.d.ts.map +1 -1
  342. package/dist/workerd/plugins/consumer.js +2 -3
  343. package/dist/workerd/plugins/consumer.js.map +1 -1
  344. package/dist/workerd/plugins/provider.d.ts +2 -2
  345. package/dist/workerd/plugins/provider.d.ts.map +1 -1
  346. package/dist/workerd/plugins/provider.js.map +1 -1
  347. package/dist/workerd/regionalAuthority.js +1 -2
  348. package/dist/workerd/regionalAuthority.js.map +1 -1
  349. package/dist/workerd/tokenProvider.js +1 -2
  350. package/dist/workerd/tokenProvider.js.map +1 -1
  351. package/dist/workerd/util/logging.js +6 -2
  352. package/dist/workerd/util/logging.js.map +1 -1
  353. package/dist/workerd/util/processMultiTenantRequest.js +2 -3
  354. package/dist/workerd/util/processMultiTenantRequest.js.map +1 -1
  355. package/dist/workerd/util/processUtils.d.ts +1 -1
  356. package/dist/workerd/util/processUtils.d.ts.map +1 -1
  357. package/dist/workerd/util/processUtils.js +1 -1
  358. package/dist/workerd/util/processUtils.js.map +1 -1
  359. package/package.json +6 -6
@@ -16,6 +16,7 @@ exports.logger = (0, logging_js_1.credentialLogger)("ChainedTokenCredential");
16
16
  * [ChainedTokenCredential overview](https://aka.ms/azsdk/js/identity/credential-chains#use-chainedtokencredential-for-granularity).
17
17
  */
18
18
  class ChainedTokenCredential {
19
+ _sources = [];
19
20
  /**
20
21
  * Creates an instance of ChainedTokenCredential using the given credentials.
21
22
  *
@@ -38,7 +39,6 @@ class ChainedTokenCredential {
38
39
  * ```
39
40
  */
40
41
  constructor(...sources) {
41
- this._sources = [];
42
42
  this._sources = sources;
43
43
  }
44
44
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"chainedTokenCredential.js","sourceRoot":"","sources":["../../../src/credentials/chainedTokenCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,4CAAwF;AACxF,mDAAkF;AAClF,mDAAmD;AAEnD;;GAEG;AACU,QAAA,MAAM,GAAG,IAAA,6BAAgB,EAAC,wBAAwB,CAAC,CAAC;AAEjE;;;;GAIG;AACH,MAAa,sBAAsB;IAGjC;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,YAAY,GAAG,OAA0B;QAvBjC,aAAQ,GAAsB,EAAE,CAAC;QAwBvC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,QAAQ,CAAC,MAAyB,EAAE,UAA2B,EAAE;QACrE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/D,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,KAAK,CAAC,gBAAgB,CAC5B,MAAyB,EACzB,UAA2B,EAAE;QAE7B,IAAI,KAAK,GAAuB,IAAI,CAAC;QACrC,IAAI,oBAAqC,CAAC;QAC1C,MAAM,MAAM,GAAY,EAAE,CAAC;QAE3B,OAAO,0BAAa,CAAC,QAAQ,CAC3B,iCAAiC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B,MAAM,IAAI,sCAA0B,CAAC,kCAAkC,CAAC,CAAC;YAC3E,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAC;QACzC,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AA/FD,wDA+FC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport { AggregateAuthenticationError, CredentialUnavailableError } from \"../errors.js\";\nimport { credentialLogger, formatError, formatSuccess } from \"../util/logging.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\n/**\n * @internal\n */\nexport const logger = credentialLogger(\"ChainedTokenCredential\");\n\n/**\n * Enables multiple `TokenCredential` implementations to be tried in order until\n * one of the getToken methods returns an access token. For more information, see\n * [ChainedTokenCredential overview](https://aka.ms/azsdk/js/identity/credential-chains#use-chainedtokencredential-for-granularity).\n */\nexport class ChainedTokenCredential implements TokenCredential {\n private _sources: TokenCredential[] = [];\n\n /**\n * Creates an instance of ChainedTokenCredential using the given credentials.\n *\n * @param sources - `TokenCredential` implementations to be tried in order.\n *\n * Example usage:\n * ```ts snippet:chained_token_credential_example\n * import { ClientSecretCredential, ChainedTokenCredential } from \"@azure/identity\";\n *\n * const tenantId = \"<tenant-id>\";\n * const clientId = \"<client-id>\";\n * const clientSecret = \"<client-secret>\";\n * const anotherClientId = \"<another-client-id>\";\n * const anotherSecret = \"<another-client-secret>\";\n *\n * const firstCredential = new ClientSecretCredential(tenantId, clientId, clientSecret);\n * const secondCredential = new ClientSecretCredential(tenantId, anotherClientId, anotherSecret);\n *\n * const credentialChain = new ChainedTokenCredential(firstCredential, secondCredential);\n * ```\n */\n constructor(...sources: TokenCredential[]) {\n this._sources = sources;\n }\n\n /**\n * Returns the first access token returned by one of the chained\n * `TokenCredential` implementations. Throws an {@link AggregateAuthenticationError}\n * when one or more credentials throws an {@link AuthenticationError} and\n * no credentials have returned an access token.\n *\n * This method is called automatically by Azure SDK client libraries. You may call this method\n * directly, but you must also handle token caching and token refreshing.\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 const { token } = await this.getTokenInternal(scopes, options);\n return token;\n }\n\n private async getTokenInternal(\n scopes: string | string[],\n options: GetTokenOptions = {},\n ): Promise<{ token: AccessToken; successfulCredential: TokenCredential }> {\n let token: AccessToken | null = null;\n let successfulCredential: TokenCredential;\n const errors: Error[] = [];\n\n return tracingClient.withSpan(\n \"ChainedTokenCredential.getToken\",\n options,\n async (updatedOptions) => {\n for (let i = 0; i < this._sources.length && token === null; i++) {\n try {\n token = await this._sources[i].getToken(scopes, updatedOptions);\n successfulCredential = this._sources[i];\n } catch (err: any) {\n if (\n err.name === \"CredentialUnavailableError\" ||\n err.name === \"AuthenticationRequiredError\"\n ) {\n errors.push(err);\n } else {\n logger.getToken.info(formatError(scopes, err));\n throw err;\n }\n }\n }\n\n if (!token && errors.length > 0) {\n const err = new AggregateAuthenticationError(\n errors,\n \"ChainedTokenCredential authentication failed.\",\n );\n logger.getToken.info(formatError(scopes, err));\n throw err;\n }\n\n logger.getToken.info(\n `Result for ${successfulCredential.constructor.name}: ${formatSuccess(scopes)}`,\n );\n\n if (token === null) {\n throw new CredentialUnavailableError(\"Failed to retrieve a valid token\");\n }\n return { token, successfulCredential };\n },\n );\n }\n}\n"]}
1
+ {"version":3,"file":"chainedTokenCredential.js","sourceRoot":"","sources":["../../../src/credentials/chainedTokenCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,4CAAwF;AACxF,mDAAkF;AAClF,mDAAmD;AAEnD;;GAEG;AACU,QAAA,MAAM,GAAG,IAAA,6BAAgB,EAAC,wBAAwB,CAAC,CAAC;AAEjE;;;;GAIG;AACH,MAAa,sBAAsB;IACzB,QAAQ,GAAsB,EAAE,CAAC;IAEzC;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AAC;wBAC/C,MAAM,GAAG,CAAC;oBACZ,CAAC;gBACH,CAAC;YACH,CAAC;YAED,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAChC,MAAM,GAAG,GAAG,IAAI,wCAA4B,CAC1C,MAAM,EACN,+CAA+C,CAChD,CAAC;gBACF,cAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAA,wBAAW,EAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;gBAC/C,MAAM,GAAG,CAAC;YACZ,CAAC;YAED,cAAM,CAAC,QAAQ,CAAC,IAAI,CAClB,cAAc,oBAAoB,CAAC,WAAW,CAAC,IAAI,KAAK,IAAA,0BAAa,EAAC,MAAM,CAAC,EAAE,CAChF,CAAC;YAEF,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACnB,MAAM,IAAI,sCAA0B,CAAC,kCAAkC,CAAC,CAAC;YAC3E,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAC;QACzC,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AA/FD,wDA+FC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport { AggregateAuthenticationError, CredentialUnavailableError } from \"../errors.js\";\nimport { credentialLogger, formatError, formatSuccess } from \"../util/logging.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\n/**\n * @internal\n */\nexport const logger = credentialLogger(\"ChainedTokenCredential\");\n\n/**\n * Enables multiple `TokenCredential` implementations to be tried in order until\n * one of the getToken methods returns an access token. For more information, see\n * [ChainedTokenCredential overview](https://aka.ms/azsdk/js/identity/credential-chains#use-chainedtokencredential-for-granularity).\n */\nexport class ChainedTokenCredential implements TokenCredential {\n private _sources: TokenCredential[] = [];\n\n /**\n * Creates an instance of ChainedTokenCredential using the given credentials.\n *\n * @param sources - `TokenCredential` implementations to be tried in order.\n *\n * Example usage:\n * ```ts snippet:chained_token_credential_example\n * import { ClientSecretCredential, ChainedTokenCredential } from \"@azure/identity\";\n *\n * const tenantId = \"<tenant-id>\";\n * const clientId = \"<client-id>\";\n * const clientSecret = \"<client-secret>\";\n * const anotherClientId = \"<another-client-id>\";\n * const anotherSecret = \"<another-client-secret>\";\n *\n * const firstCredential = new ClientSecretCredential(tenantId, clientId, clientSecret);\n * const secondCredential = new ClientSecretCredential(tenantId, anotherClientId, anotherSecret);\n *\n * const credentialChain = new ChainedTokenCredential(firstCredential, secondCredential);\n * ```\n */\n constructor(...sources: TokenCredential[]) {\n this._sources = sources;\n }\n\n /**\n * Returns the first access token returned by one of the chained\n * `TokenCredential` implementations. Throws an {@link AggregateAuthenticationError}\n * when one or more credentials throws an {@link AuthenticationError} and\n * no credentials have returned an access token.\n *\n * This method is called automatically by Azure SDK client libraries. You may call this method\n * directly, but you must also handle token caching and token refreshing.\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 const { token } = await this.getTokenInternal(scopes, options);\n return token;\n }\n\n private async getTokenInternal(\n scopes: string | string[],\n options: GetTokenOptions = {},\n ): Promise<{ token: AccessToken; successfulCredential: TokenCredential }> {\n let token: AccessToken | null = null;\n let successfulCredential: TokenCredential;\n const errors: Error[] = [];\n\n return tracingClient.withSpan(\n \"ChainedTokenCredential.getToken\",\n options,\n async (updatedOptions) => {\n for (let i = 0; i < this._sources.length && token === null; i++) {\n try {\n token = await this._sources[i].getToken(scopes, updatedOptions);\n successfulCredential = this._sources[i];\n } catch (err: any) {\n if (\n err.name === \"CredentialUnavailableError\" ||\n err.name === \"AuthenticationRequiredError\"\n ) {\n errors.push(err);\n } else {\n logger.getToken.info(formatError(scopes, err));\n throw err;\n }\n }\n }\n\n if (!token && errors.length > 0) {\n const err = new AggregateAuthenticationError(\n errors,\n \"ChainedTokenCredential authentication failed.\",\n );\n logger.getToken.info(formatError(scopes, err));\n throw err;\n }\n\n logger.getToken.info(\n `Result for ${successfulCredential.constructor.name}: ${formatSuccess(scopes)}`,\n );\n\n if (token === null) {\n throw new CredentialUnavailableError(\"Failed to retrieve a valid token\");\n }\n return { token, successfulCredential };\n },\n );\n }\n}\n"]}
@@ -13,6 +13,11 @@ const logger = (0, logging_js_1.credentialLogger)("ClientAssertionCredential");
13
13
  * Authenticates a service principal with a JWT assertion.
14
14
  */
15
15
  class ClientAssertionCredential {
16
+ msalClient;
17
+ tenantId;
18
+ additionallyAllowedTenantIds;
19
+ getAssertion;
20
+ options;
16
21
  /**
17
22
  * Creates an instance of the ClientAssertionCredential with the details
18
23
  * needed to authenticate against Microsoft Entra ID with a client
@@ -34,10 +39,14 @@ class ClientAssertionCredential {
34
39
  throw new errors_js_1.CredentialUnavailableError("ClientAssertionCredential: clientAssertion is a required parameter.");
35
40
  }
36
41
  this.tenantId = tenantId;
37
- this.additionallyAllowedTenantIds = (0, tenantIdUtils_js_1.resolveAdditionallyAllowedTenantIds)(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
42
+ this.additionallyAllowedTenantIds = (0, tenantIdUtils_js_1.resolveAdditionallyAllowedTenantIds)(options?.additionallyAllowedTenants);
38
43
  this.options = options;
39
44
  this.getAssertion = getAssertion;
40
- this.msalClient = (0, msalClient_js_1.createMsalClient)(clientId, tenantId, Object.assign(Object.assign({}, options), { logger, tokenCredentialOptions: this.options }));
45
+ this.msalClient = (0, msalClient_js_1.createMsalClient)(clientId, tenantId, {
46
+ ...options,
47
+ logger,
48
+ tokenCredentialOptions: this.options,
49
+ });
41
50
  }
42
51
  /**
43
52
  * Authenticates with Microsoft Entra ID and returns an access token if successful.
@@ -1 +1 @@
1
- {"version":3,"file":"clientAssertionCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientAssertionCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAIlC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UAAU,EACV,IAAI,CAAC,4BAA4B,EACjC,MAAM,CACP,CAAC;YAEF,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC,UAAU,CAAC,yBAAyB,CAC9C,WAAW,EACX,IAAI,CAAC,YAAY,EACjB,UAAU,CACX,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAnFD,8DAmFC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type { MsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\n\nimport type { ClientAssertionCredentialOptions } from \"./clientAssertionCredentialOptions.js\";\nimport { CredentialUnavailableError } from \"../errors.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\nconst logger = credentialLogger(\"ClientAssertionCredential\");\n\n/**\n * Authenticates a service principal with a JWT assertion.\n */\nexport class ClientAssertionCredential implements TokenCredential {\n private msalClient: MsalClient;\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private getAssertion: () => Promise<string>;\n private options: ClientAssertionCredentialOptions;\n\n /**\n * Creates an instance of the ClientAssertionCredential with the details\n * needed to authenticate against Microsoft Entra ID with a client\n * assertion provided by the developer through the `getAssertion` function parameter.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param getAssertion - A function that retrieves the assertion for the credential to use.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n getAssertion: () => Promise<string>,\n options: ClientAssertionCredentialOptions = {},\n ) {\n if (!tenantId) {\n throw new CredentialUnavailableError(\n \"ClientAssertionCredential: tenantId is a required parameter.\",\n );\n }\n\n if (!clientId) {\n throw new CredentialUnavailableError(\n \"ClientAssertionCredential: clientId is a required parameter.\",\n );\n }\n\n if (!getAssertion) {\n throw new CredentialUnavailableError(\n \"ClientAssertionCredential: clientAssertion is a required parameter.\",\n );\n }\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.options = options;\n this.getAssertion = getAssertion;\n this.msalClient = createMsalClient(clientId, tenantId, {\n ...options,\n logger,\n tokenCredentialOptions: this.options,\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 * @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 = Array.isArray(scopes) ? scopes : [scopes];\n return this.msalClient.getTokenByClientAssertion(\n arrayScopes,\n this.getAssertion,\n newOptions,\n );\n },\n );\n }\n}\n"]}
1
+ {"version":3,"file":"clientAssertionCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientAssertionCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAIlC,mEAAmE;AACnE,+DAGkC;AAGlC,4CAA0D;AAC1D,mDAAsD;AACtD,mDAAmD;AAEnD,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,2BAA2B,CAAC,CAAC;AAE7D;;GAEG;AACH,MAAa,yBAAyB;IAC5B,UAAU,CAAa;IACvB,QAAQ,C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AAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC,UAAU,CAAC,yBAAyB,CAC9C,WAAW,EACX,IAAI,CAAC,YAAY,EACjB,UAAU,CACX,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAnFD,8DAmFC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type { MsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\n\nimport type { ClientAssertionCredentialOptions } from \"./clientAssertionCredentialOptions.js\";\nimport { CredentialUnavailableError } from \"../errors.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\nconst logger = credentialLogger(\"ClientAssertionCredential\");\n\n/**\n * Authenticates a service principal with a JWT assertion.\n */\nexport class ClientAssertionCredential implements TokenCredential {\n private msalClient: MsalClient;\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private getAssertion: () => Promise<string>;\n private options: ClientAssertionCredentialOptions;\n\n /**\n * Creates an instance of the ClientAssertionCredential with the details\n * needed to authenticate against Microsoft Entra ID with a client\n * assertion provided by the developer through the `getAssertion` function parameter.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param getAssertion - A function that retrieves the assertion for the credential to use.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n getAssertion: () => Promise<string>,\n options: ClientAssertionCredentialOptions = {},\n ) {\n if (!tenantId) {\n throw new CredentialUnavailableError(\n \"ClientAssertionCredential: tenantId is a required parameter.\",\n );\n }\n\n if (!clientId) {\n throw new CredentialUnavailableError(\n \"ClientAssertionCredential: clientId is a required parameter.\",\n );\n }\n\n if (!getAssertion) {\n throw new CredentialUnavailableError(\n \"ClientAssertionCredential: clientAssertion is a required parameter.\",\n );\n }\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.options = options;\n this.getAssertion = getAssertion;\n this.msalClient = createMsalClient(clientId, tenantId, {\n ...options,\n logger,\n tokenCredentialOptions: this.options,\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 * @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 = Array.isArray(scopes) ? scopes : [scopes];\n return this.msalClient.getTokenByClientAssertion(\n arrayScopes,\n this.getAssertion,\n newOptions,\n );\n },\n );\n }\n}\n"]}
@@ -21,18 +21,25 @@ const logger = (0, logging_js_1.credentialLogger)(credentialName);
21
21
  *
22
22
  */
23
23
  class ClientCertificateCredential {
24
+ tenantId;
25
+ additionallyAllowedTenantIds;
26
+ certificateConfiguration;
27
+ sendCertificateChain;
28
+ msalClient;
24
29
  constructor(tenantId, clientId, certificatePathOrConfiguration, options = {}) {
25
30
  if (!tenantId || !clientId) {
26
31
  throw new Error(`${credentialName}: tenantId and clientId are required parameters.`);
27
32
  }
28
33
  this.tenantId = tenantId;
29
- this.additionallyAllowedTenantIds = (0, tenantIdUtils_js_1.resolveAdditionallyAllowedTenantIds)(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
34
+ this.additionallyAllowedTenantIds = (0, tenantIdUtils_js_1.resolveAdditionallyAllowedTenantIds)(options?.additionallyAllowedTenants);
30
35
  this.sendCertificateChain = options.sendCertificateChain;
31
- this.certificateConfiguration = Object.assign({}, (typeof certificatePathOrConfiguration === "string"
32
- ? {
33
- certificatePath: certificatePathOrConfiguration,
34
- }
35
- : certificatePathOrConfiguration));
36
+ this.certificateConfiguration = {
37
+ ...(typeof certificatePathOrConfiguration === "string"
38
+ ? {
39
+ certificatePath: certificatePathOrConfiguration,
40
+ }
41
+ : certificatePathOrConfiguration),
42
+ };
36
43
  const certificate = this.certificateConfiguration
37
44
  .certificate;
38
45
  const certificatePath = this.certificateConfiguration
@@ -43,7 +50,11 @@ class ClientCertificateCredential {
43
50
  if (certificate && certificatePath) {
44
51
  throw new Error(`${credentialName}: To avoid unexpected behaviors, providing both the contents of a PEM certificate and the path to a PEM certificate is forbidden. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`);
45
52
  }
46
- this.msalClient = (0, msalClient_js_1.createMsalClient)(clientId, tenantId, Object.assign(Object.assign({}, options), { logger, tokenCredentialOptions: options }));
53
+ this.msalClient = (0, msalClient_js_1.createMsalClient)(clientId, tenantId, {
54
+ ...options,
55
+ logger,
56
+ tokenCredentialOptions: options,
57
+ });
47
58
  }
48
59
  /**
49
60
  * Authenticates with Microsoft Entra ID and returns an access token if successful.
@@ -62,8 +73,7 @@ class ClientCertificateCredential {
62
73
  });
63
74
  }
64
75
  async buildClientCertificate() {
65
- var _a;
66
- const parts = await parseCertificate(this.certificateConfiguration, (_a = this.sendCertificateChain) !== null && _a !== void 0 ? _a : false);
76
+ const parts = await parseCertificate(this.certificateConfiguration, this.sendCertificateChain ?? false);
67
77
  let privateKey;
68
78
  if (this.certificateConfiguration.certificatePassword !== undefined) {
69
79
  privateKey = (0, node_crypto_1.createPrivateKey)({
@@ -1 +1 @@
1
- {"version":3,"file":"clientCertificateCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientCertificateC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BAAU,EAAC,MAAM,CAAC,CAAC,4DAA4D;SAC/F,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;SAC5C,MAAM,CAAC,KAAK,CAAC;SACb,WAAW,EAAE,CAAC;IAEjB,MAAM,gBAAgB,GAAG,IAAA,wBAAU,EAAC,QAAQ,CAAC;SAC1C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;SAC5C,MAAM,CAAC,KAAK,CAAC;SACb,WAAW,EAAE,CAAC;IAEjB,OAAO;QACL,mBAAmB;QACnB,gBAAgB;QAChB,UAAU;QACV,GAAG;KACJ,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type { MsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createHash, createPrivateKey } from \"node:crypto\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\n\nimport type { CertificateParts } from \"../msal/types.js\";\nimport type { ClientCertificateCredentialOptions } from \"./clientCertificateCredentialOptions.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { readFile } from \"node:fs/promises\";\nimport { tracingClient } from \"../util/tracing.js\";\nimport type {\n ClientCertificateCredentialPEMConfiguration,\n ClientCertificatePEMCertificate,\n ClientCertificatePEMCertificatePath,\n} from \"./clientCertificateCredentialModels.js\";\n\nconst credentialName = \"ClientCertificateCredential\";\nconst logger = credentialLogger(credentialName);\n\n/**\n * Enables authentication to Microsoft Entra ID using a PEM-encoded\n * certificate that is assigned to an App Registration. More information\n * on how to configure certificate authentication can be found here:\n *\n * https://learn.microsoft.com/azure/active-directory/develop/active-directory-certificate-credentials#register-your-certificate-with-azure-ad\n *\n */\nexport class ClientCertificateCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private certificateConfiguration: ClientCertificateCredentialPEMConfiguration;\n private sendCertificateChain?: boolean;\n private msalClient: MsalClient;\n\n /**\n * Creates an instance of the ClientCertificateCredential with the details\n * needed to authenticate against Microsoft Entra ID with a certificate.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param certificatePath - The path to a PEM-encoded public/private key certificate on the filesystem.\n * Ensure that certificate is in PEM format and contains both the public and private keys.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n certificatePath: string,\n options?: ClientCertificateCredentialOptions,\n );\n /**\n * Creates an instance of the ClientCertificateCredential with the details\n * needed to authenticate against Microsoft Entra ID with a certificate.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param configuration - Other parameters required, including the path of the certificate on the filesystem.\n * If the type is ignored, we will throw the value of the path to a PEM certificate.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n configuration: ClientCertificatePEMCertificatePath,\n options?: ClientCertificateCredentialOptions,\n );\n /**\n * Creates an instance of the ClientCertificateCredential with the details\n * needed to authenticate against Microsoft Entra ID with a certificate.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param configuration - Other parameters required, including the PEM-encoded certificate as a string.\n * If the type is ignored, we will throw the value of the PEM-encoded certificate.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n configuration: ClientCertificatePEMCertificate,\n options?: ClientCertificateCredentialOptions,\n );\n constructor(\n tenantId: string,\n clientId: string,\n certificatePathOrConfiguration: string | ClientCertificateCredentialPEMConfiguration,\n options: ClientCertificateCredentialOptions = {},\n ) {\n if (!tenantId || !clientId) {\n throw new Error(`${credentialName}: tenantId and clientId are required parameters.`);\n }\n\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.sendCertificateChain = options.sendCertificateChain;\n\n this.certificateConfiguration = {\n ...(typeof certificatePathOrConfiguration === \"string\"\n ? {\n certificatePath: certificatePathOrConfiguration,\n }\n : certificatePathOrConfiguration),\n };\n const certificate = (this.certificateConfiguration as ClientCertificatePEMCertificate)\n .certificate;\n const certificatePath = (this.certificateConfiguration as ClientCertificatePEMCertificatePath)\n .certificatePath;\n if (!this.certificateConfiguration || !(certificate || certificatePath)) {\n throw new Error(\n `${credentialName}: Provide either a PEM certificate in string form, or the path to that certificate in the filesystem. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n if (certificate && certificatePath) {\n throw new Error(\n `${credentialName}: To avoid unexpected behaviors, providing both the contents of a PEM certificate and the path to a PEM certificate is forbidden. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n this.msalClient = createMsalClient(clientId, tenantId, {\n ...options,\n logger,\n tokenCredentialOptions: options,\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 * @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(`${credentialName}.getToken`, options, async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];\n const certificate = await this.buildClientCertificate();\n return this.msalClient.getTokenByClientCertificate(arrayScopes, certificate, newOptions);\n });\n }\n\n private async buildClientCertificate(): Promise<CertificateParts> {\n const parts = await parseCertificate(\n this.certificateConfiguration,\n this.sendCertificateChain ?? false,\n );\n\n let privateKey: string;\n if (this.certificateConfiguration.certificatePassword !== undefined) {\n privateKey = createPrivateKey({\n key: parts.certificateContents,\n passphrase: this.certificateConfiguration.certificatePassword,\n format: \"pem\",\n })\n .export({\n format: \"pem\",\n type: \"pkcs8\",\n })\n .toString();\n } else {\n privateKey = parts.certificateContents;\n }\n\n return {\n thumbprint: parts.thumbprint,\n thumbprintSha256: parts.thumbprintSha256,\n privateKey,\n x5c: parts.x5c,\n };\n }\n}\n\n/**\n * Parses a certificate into its relevant parts\n *\n * @param certificateConfiguration - The certificate contents or path to the certificate\n * @param sendCertificateChain - true if the entire certificate chain should be sent for SNI, false otherwise\n * @returns The parsed certificate parts and the certificate contents\n */\nexport async function parseCertificate(\n certificateConfiguration: ClientCertificateCredentialPEMConfiguration,\n sendCertificateChain: boolean,\n): Promise<Omit<CertificateParts, \"privateKey\"> & { certificateContents: string }> {\n const certificate = (certificateConfiguration as ClientCertificatePEMCertificate).certificate;\n const certificatePath = (certificateConfiguration as ClientCertificatePEMCertificatePath)\n .certificatePath;\n const certificateContents = certificate || (await readFile(certificatePath!, \"utf8\"));\n const x5c = sendCertificateChain ? certificateContents : undefined;\n\n const certificatePattern =\n /(-+BEGIN CERTIFICATE-+)(\\n\\r?|\\r\\n?)([A-Za-z0-9+/\\n\\r]+=*)(\\n\\r?|\\r\\n?)(-+END CERTIFICATE-+)/g;\n const publicKeys: string[] = [];\n\n // Match all possible certificates, in the order they are in the file. These will form the chain that is used for x5c\n let match;\n do {\n match = certificatePattern.exec(certificateContents);\n if (match) {\n publicKeys.push(match[3]);\n }\n } while (match);\n\n if (publicKeys.length === 0) {\n throw new Error(\"The file at the specified path does not contain a PEM-encoded certificate.\");\n }\n\n const thumbprint = createHash(\"sha1\") // CodeQL [SM04514] Needed for backward compatibility reason\n .update(Buffer.from(publicKeys[0], \"base64\"))\n .digest(\"hex\")\n .toUpperCase();\n\n const thumbprintSha256 = createHash(\"sha256\")\n .update(Buffer.from(publicKeys[0], \"base64\"))\n .digest(\"hex\")\n .toUpperCase();\n\n return {\n certificateContents,\n thumbprintSha256,\n thumbprint,\n x5c,\n };\n}\n"]}
1
+ {"version":3,"file":"clientCertificateCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientCertificateCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAkMlC,4CA2CC;AAzOD,mEAAmE;AACnE,6CAA2D;AAC3D,+DAGkC;AAIlC,mDAAsD;AACtD,+CAA4C;AAC5C,mDAAmD;AAOnD,MAAM,cAAc,GAAG,6BAA6B,CAAC;AACrD,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,cAAc,CAAC,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAa,2BAA2B;IAC9B,QAAQ,CAAS;IACjB,4BAA4B,CAAW;IACvC,wBAAwB,CAA8C;IACtE,oBAAoB,CAAW;IAC/B,UAAU,CAAa;IAkD/B,YACE,QAAgB,EAChB,QAAgB,EAChB,8BAAoF,EACpF,UAA8C,EAAE;QAEhD,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,GAAG,cAAc,kDAAkD,CAAC,CAAC;QACvF,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,4BAA4B,GAAG,IAAA,sDAAmC,EACrE,OAAO,EAAE,0BAA0B,CACpC,CAAC;QAEF,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC;QAEzD,IAAI,CAAC,wBAAwB,GAAG;YAC9B,GAAG,CAAC,OAAO,8BAA8B,KAAK,QAAQ;gBACpD,CAAC,CAAC;oBACE,eAAe,EAAE,8BAA8B;iBAChD;gBACH,CAAC,CAAC,8BAA8B,CAAC;SACpC,CAAC;QACF,MAAM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ACF,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACrD,IAAI,KAAK,EAAE,CAAC;YACV,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC,QAAQ,KAAK,EAAE;IAEhB,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;IAChG,CAAC;IAED,MAAM,UAAU,GAAG,IAAA,wBAAU,EAAC,MAAM,CAAC,CAAC,4DAA4D;SAC/F,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;SAC5C,MAAM,CAAC,KAAK,CAAC;SACb,WAAW,EAAE,CAAC;IAEjB,MAAM,gBAAgB,GAAG,IAAA,wBAAU,EAAC,QAAQ,CAAC;SAC1C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;SAC5C,MAAM,CAAC,KAAK,CAAC;SACb,WAAW,EAAE,CAAC;IAEjB,OAAO;QACL,mBAAmB;QACnB,gBAAgB;QAChB,UAAU;QACV,GAAG;KACJ,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type { MsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createHash, createPrivateKey } from \"node:crypto\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\n\nimport type { CertificateParts } from \"../msal/types.js\";\nimport type { ClientCertificateCredentialOptions } from \"./clientCertificateCredentialOptions.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { readFile } from \"node:fs/promises\";\nimport { tracingClient } from \"../util/tracing.js\";\nimport type {\n ClientCertificateCredentialPEMConfiguration,\n ClientCertificatePEMCertificate,\n ClientCertificatePEMCertificatePath,\n} from \"./clientCertificateCredentialModels.js\";\n\nconst credentialName = \"ClientCertificateCredential\";\nconst logger = credentialLogger(credentialName);\n\n/**\n * Enables authentication to Microsoft Entra ID using a PEM-encoded\n * certificate that is assigned to an App Registration. More information\n * on how to configure certificate authentication can be found here:\n *\n * https://learn.microsoft.com/azure/active-directory/develop/active-directory-certificate-credentials#register-your-certificate-with-azure-ad\n *\n */\nexport class ClientCertificateCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private certificateConfiguration: ClientCertificateCredentialPEMConfiguration;\n private sendCertificateChain?: boolean;\n private msalClient: MsalClient;\n\n /**\n * Creates an instance of the ClientCertificateCredential with the details\n * needed to authenticate against Microsoft Entra ID with a certificate.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param certificatePath - The path to a PEM-encoded public/private key certificate on the filesystem.\n * Ensure that certificate is in PEM format and contains both the public and private keys.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n certificatePath: string,\n options?: ClientCertificateCredentialOptions,\n );\n /**\n * Creates an instance of the ClientCertificateCredential with the details\n * needed to authenticate against Microsoft Entra ID with a certificate.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param configuration - Other parameters required, including the path of the certificate on the filesystem.\n * If the type is ignored, we will throw the value of the path to a PEM certificate.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n configuration: ClientCertificatePEMCertificatePath,\n options?: ClientCertificateCredentialOptions,\n );\n /**\n * Creates an instance of the ClientCertificateCredential with the details\n * needed to authenticate against Microsoft Entra ID with a certificate.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param configuration - Other parameters required, including the PEM-encoded certificate as a string.\n * If the type is ignored, we will throw the value of the PEM-encoded certificate.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n configuration: ClientCertificatePEMCertificate,\n options?: ClientCertificateCredentialOptions,\n );\n constructor(\n tenantId: string,\n clientId: string,\n certificatePathOrConfiguration: string | ClientCertificateCredentialPEMConfiguration,\n options: ClientCertificateCredentialOptions = {},\n ) {\n if (!tenantId || !clientId) {\n throw new Error(`${credentialName}: tenantId and clientId are required parameters.`);\n }\n\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.sendCertificateChain = options.sendCertificateChain;\n\n this.certificateConfiguration = {\n ...(typeof certificatePathOrConfiguration === \"string\"\n ? {\n certificatePath: certificatePathOrConfiguration,\n }\n : certificatePathOrConfiguration),\n };\n const certificate = (this.certificateConfiguration as ClientCertificatePEMCertificate)\n .certificate;\n const certificatePath = (this.certificateConfiguration as ClientCertificatePEMCertificatePath)\n .certificatePath;\n if (!this.certificateConfiguration || !(certificate || certificatePath)) {\n throw new Error(\n `${credentialName}: Provide either a PEM certificate in string form, or the path to that certificate in the filesystem. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n if (certificate && certificatePath) {\n throw new Error(\n `${credentialName}: To avoid unexpected behaviors, providing both the contents of a PEM certificate and the path to a PEM certificate is forbidden. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n this.msalClient = createMsalClient(clientId, tenantId, {\n ...options,\n logger,\n tokenCredentialOptions: options,\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 * @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(`${credentialName}.getToken`, options, async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];\n const certificate = await this.buildClientCertificate();\n return this.msalClient.getTokenByClientCertificate(arrayScopes, certificate, newOptions);\n });\n }\n\n private async buildClientCertificate(): Promise<CertificateParts> {\n const parts = await parseCertificate(\n this.certificateConfiguration,\n this.sendCertificateChain ?? false,\n );\n\n let privateKey: string;\n if (this.certificateConfiguration.certificatePassword !== undefined) {\n privateKey = createPrivateKey({\n key: parts.certificateContents,\n passphrase: this.certificateConfiguration.certificatePassword,\n format: \"pem\",\n })\n .export({\n format: \"pem\",\n type: \"pkcs8\",\n })\n .toString();\n } else {\n privateKey = parts.certificateContents;\n }\n\n return {\n thumbprint: parts.thumbprint,\n thumbprintSha256: parts.thumbprintSha256,\n privateKey,\n x5c: parts.x5c,\n };\n }\n}\n\n/**\n * Parses a certificate into its relevant parts\n *\n * @param certificateConfiguration - The certificate contents or path to the certificate\n * @param sendCertificateChain - true if the entire certificate chain should be sent for SNI, false otherwise\n * @returns The parsed certificate parts and the certificate contents\n */\nexport async function parseCertificate(\n certificateConfiguration: ClientCertificateCredentialPEMConfiguration,\n sendCertificateChain: boolean,\n): Promise<Omit<CertificateParts, \"privateKey\"> & { certificateContents: string }> {\n const certificate = (certificateConfiguration as ClientCertificatePEMCertificate).certificate;\n const certificatePath = (certificateConfiguration as ClientCertificatePEMCertificatePath)\n .certificatePath;\n const certificateContents = certificate || (await readFile(certificatePath!, \"utf8\"));\n const x5c = sendCertificateChain ? certificateContents : undefined;\n\n const certificatePattern =\n /(-+BEGIN CERTIFICATE-+)(\\n\\r?|\\r\\n?)([A-Za-z0-9+/\\n\\r]+=*)(\\n\\r?|\\r\\n?)(-+END CERTIFICATE-+)/g;\n const publicKeys: string[] = [];\n\n // Match all possible certificates, in the order they are in the file. These will form the chain that is used for x5c\n let match;\n do {\n match = certificatePattern.exec(certificateContents);\n if (match) {\n publicKeys.push(match[3]);\n }\n } while (match);\n\n if (publicKeys.length === 0) {\n throw new Error(\"The file at the specified path does not contain a PEM-encoded certificate.\");\n }\n\n const thumbprint = createHash(\"sha1\") // CodeQL [SM04514] Needed for backward compatibility reason\n .update(Buffer.from(publicKeys[0], \"base64\"))\n .digest(\"hex\")\n .toUpperCase();\n\n const thumbprintSha256 = createHash(\"sha256\")\n .update(Buffer.from(publicKeys[0], \"base64\"))\n .digest(\"hex\")\n .toUpperCase();\n\n return {\n certificateContents,\n thumbprintSha256,\n thumbprint,\n x5c,\n };\n}\n"]}
@@ -19,6 +19,10 @@ const logger = (0, logging_js_1.credentialLogger)("ClientSecretCredential");
19
19
  *
20
20
  */
21
21
  class ClientSecretCredential {
22
+ tenantId;
23
+ additionallyAllowedTenantIds;
24
+ msalClient;
25
+ clientSecret;
22
26
  /**
23
27
  * Creates an instance of the ClientSecretCredential with the details
24
28
  * needed to authenticate against Microsoft Entra ID with a client
@@ -41,8 +45,12 @@ class ClientSecretCredential {
41
45
  }
42
46
  this.clientSecret = clientSecret;
43
47
  this.tenantId = tenantId;
44
- this.additionallyAllowedTenantIds = (0, tenantIdUtils_js_1.resolveAdditionallyAllowedTenantIds)(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
45
- this.msalClient = (0, msalClient_js_1.createMsalClient)(clientId, tenantId, Object.assign(Object.assign({}, options), { logger, tokenCredentialOptions: options }));
48
+ this.additionallyAllowedTenantIds = (0, tenantIdUtils_js_1.resolveAdditionallyAllowedTenantIds)(options?.additionallyAllowedTenants);
49
+ this.msalClient = (0, msalClient_js_1.createMsalClient)(clientId, tenantId, {
50
+ ...options,
51
+ logger,
52
+ tokenCredentialOptions: options,
53
+ });
46
54
  }
47
55
  /**
48
56
  * Authenticates with Microsoft Entra ID and returns an access token if successful.
@@ -1 +1 @@
1
- {"version":3,"file":"clientSecretCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientSecretCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAIlC,mEAAmE;AACnE,+DAGkC;AAGlC,4CAA0D;AAC1D,mDAAsD;AACtD,yDAAqD;AACrD,mDAAmD;AAEnD,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,wBAAwB,CAAC,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAa,sBAAsB;IAMjC;;;;;;;;;OASG;IACH,YACE,QAAgB,EAChB,QAAgB,EAChB,YAAoB,EACpB,UAAyC,EAAE;QAE3C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,sCAA0B,CAClC,gKAAgK,CACjK,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,sCAA0B,CAClC,gKAAgK,CACjK,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,sCAA0B,CAClC,oKAAoK,CACrK,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,4BAA4B,GAAG,IAAA,sDAAmC,EACrE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,0BAA0B,CACpC,CAAC;QAEF,IAAI,CAAC,UAAU,GAAG,IAAA,gCAAgB,EAAC,QAAQ,EAAE,QAAQ,kCAChD,OAAO,KACV,MAAM,EACN,sBAAsB,EAAE,OAAO,IAC/B,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,QAAQ,CAAC,MAAyB,EAAE,UAA2B,EAAE;QACrE,OAAO,0BAAa,CAAC,QAAQ,CAC3B,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,WAAW,EACnC,OAAO,EACP,KAAK,EAAE,UAAU,EAAE,EAAE;YACnB,UAAU,CAAC,QAAQ,GAAG,IAAA,4CAAyB,EAC7C,IAAI,CAAC,QAAQ,EACb,UAAU,EACV,IAAI,CAAC,4BAA4B,EACjC,MAAM,CACP,CAAC;YAEF,MAAM,WAAW,GAAG,IAAA,4BAAY,EAAC,MAAM,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;QAC5F,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AA9ED,wDA8EC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type { MsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\n\nimport type { ClientSecretCredentialOptions } from \"./clientSecretCredentialOptions.js\";\nimport { CredentialUnavailableError } from \"../errors.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\nconst logger = credentialLogger(\"ClientSecretCredential\");\n\n/**\n * Enables authentication to Microsoft Entra ID using a client secret\n * that was generated for an App Registration. More information on how\n * to configure a client secret can be found here:\n *\n * https://learn.microsoft.com/entra/identity-platform/quickstart-configure-app-access-web-apis#add-credentials-to-your-web-application\n *\n */\nexport class ClientSecretCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private msalClient: MsalClient;\n private clientSecret: string;\n\n /**\n * Creates an instance of the ClientSecretCredential with the details\n * needed to authenticate against Microsoft Entra ID with a client\n * secret.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param clientSecret - A client secret that was generated for the App Registration.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n clientSecret: string,\n options: ClientSecretCredentialOptions = {},\n ) {\n if (!tenantId) {\n throw new CredentialUnavailableError(\n \"ClientSecretCredential: tenantId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.\",\n );\n }\n\n if (!clientId) {\n throw new CredentialUnavailableError(\n \"ClientSecretCredential: clientId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.\",\n );\n }\n\n if (!clientSecret) {\n throw new CredentialUnavailableError(\n \"ClientSecretCredential: clientSecret is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.\",\n );\n }\n\n this.clientSecret = clientSecret;\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.msalClient = createMsalClient(clientId, tenantId, {\n ...options,\n logger,\n tokenCredentialOptions: options,\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 * @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.getTokenByClientSecret(arrayScopes, this.clientSecret, newOptions);\n },\n );\n }\n}\n"]}
1
+ {"version":3,"file":"clientSecretCredential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AW,EACnC,OAAO,EACP,KAAK,EAAE,UAAU,EAAE,EAAE;YACnB,UAAU,CAAC,QAAQ,GAAG,IAAA,4CAAyB,EAC7C,IAAI,CAAC,QAAQ,EACb,UAAU,EACV,IAAI,CAAC,4BAA4B,EACjC,MAAM,CACP,CAAC;YAEF,MAAM,WAAW,GAAG,IAAA,4BAAY,EAAC,MAAM,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;QAC5F,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AA9ED,wDA8EC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type { MsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\n\nimport type { ClientSecretCredentialOptions } from \"./clientSecretCredentialOptions.js\";\nimport { CredentialUnavailableError } from \"../errors.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\nconst logger = credentialLogger(\"ClientSecretCredential\");\n\n/**\n * Enables authentication to Microsoft Entra ID using a client secret\n * that was generated for an App Registration. More information on how\n * to configure a client secret can be found here:\n *\n * https://learn.microsoft.com/entra/identity-platform/quickstart-configure-app-access-web-apis#add-credentials-to-your-web-application\n *\n */\nexport class ClientSecretCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private msalClient: MsalClient;\n private clientSecret: string;\n\n /**\n * Creates an instance of the ClientSecretCredential with the details\n * needed to authenticate against Microsoft Entra ID with a client\n * secret.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param clientSecret - A client secret that was generated for the App Registration.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n clientSecret: string,\n options: ClientSecretCredentialOptions = {},\n ) {\n if (!tenantId) {\n throw new CredentialUnavailableError(\n \"ClientSecretCredential: tenantId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.\",\n );\n }\n\n if (!clientId) {\n throw new CredentialUnavailableError(\n \"ClientSecretCredential: clientId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.\",\n );\n }\n\n if (!clientSecret) {\n throw new CredentialUnavailableError(\n \"ClientSecretCredential: clientSecret is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.\",\n );\n }\n\n this.clientSecret = clientSecret;\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.msalClient = createMsalClient(clientId, tenantId, {\n ...options,\n logger,\n tokenCredentialOptions: options,\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 * @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.getTokenByClientSecret(arrayScopes, this.clientSecret, newOptions);\n },\n );\n }\n}\n"]}
@@ -1,20 +1,6 @@
1
1
  import type { DefaultAzureCredentialClientIdOptions, DefaultAzureCredentialOptions, DefaultAzureCredentialResourceIdOptions } from "./defaultAzureCredentialOptions.js";
2
2
  import { ChainedTokenCredential } from "./chainedTokenCredential.js";
3
3
  import type { TokenCredential } from "@azure/core-auth";
4
- /**
5
- * Creates a {@link ManagedIdentityCredential} from the provided options.
6
- * @param options - Options to configure the credential.
7
- *
8
- * @internal
9
- */
10
- export declare function createDefaultManagedIdentityCredential(options?: DefaultAzureCredentialOptions | DefaultAzureCredentialResourceIdOptions | DefaultAzureCredentialClientIdOptions): TokenCredential;
11
- /**
12
- * Creates an {@link EnvironmentCredential} from the provided options.
13
- * @param options - Options to configure the credential.
14
- *
15
- * @internal
16
- */
17
- export declare function createEnvironmentCredential(options?: DefaultAzureCredentialOptions): TokenCredential;
18
4
  /**
19
5
  * A no-op credential that logs the reason it was skipped if getToken is called.
20
6
  * @internal
@@ -35,12 +21,24 @@ export declare class UnavailableDefaultCredential implements TokenCredential {
35
21
  * - {@link EnvironmentCredential}
36
22
  * - {@link WorkloadIdentityCredential}
37
23
  * - {@link ManagedIdentityCredential}
24
+ * - {@link VisualStudioCodeCredential}
38
25
  * - {@link AzureCliCredential}
39
26
  * - {@link AzurePowerShellCredential}
40
27
  * - {@link AzureDeveloperCliCredential}
41
28
  *
42
29
  * Consult the documentation of these credential types for more information
43
30
  * on how they attempt authentication.
31
+ *
32
+ * Selecting credentials
33
+ *
34
+ * Set environment variable AZURE_TOKEN_CREDENTIALS to select a subset of the credential chain.
35
+ * DefaultAzureCredential will try only the specified credential(s), but its other behavior remains the same.
36
+ * Valid values for AZURE_TOKEN_CREDENTIALS are the name of any single type in the above chain, for example
37
+ * "EnvironmentCredential" or "AzureCliCredential", and these special values:
38
+ *
39
+ * - "dev": try [VisualStudioCodeCredential], [AzureCliCredential], [AzurePowerShellCredential] and [AzureDeveloperCliCredential], in that order
40
+ * - "prod": try [EnvironmentCredential], [WorkloadIdentityCredential], and [ManagedIdentityCredential], in that order
41
+ *
44
42
  */
45
43
  export declare class DefaultAzureCredential extends ChainedTokenCredential {
46
44
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"defaultAzureCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/defaultAzureCredential.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qCAAqC,EACrC,6BAA6B,EAC7B,uCAAuC,EACxC,MAAM,oCAAoC,CAAC;AAU5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAOxD;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,OAAO,GACH,6BAA6B,GAC7B,uCAAuC,GACvC,qCAA0C,GAC7C,eAAe,CA8CjB;AA+ED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,GAAE,6BAAkC,GAC1C,eAAe,CAEjB;AAED;;;GAGG;AACH,qBAAa,4BAA6B,YAAW,eAAe;IAClE,iCAAiC,EAAE,MAAM,CAAC;IAC1C,cAAc,EAAE,MAAM,CAAC;gBAEX,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAKnD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAM1B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;IAChE;;;;OAIG;gBACS,OAAO,CAAC,EAAE,qCAAqC;IAE3D;;;;OAIG;gBACS,OAAO,CAAC,EAAE,uCAAuC;IAE7D;;;;OAIG;gBACS,OAAO,CAAC,EAAE,6BAA6B;CA6DpD"}
1
+ {"version":3,"file":"defaultAzureCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/defaultAzureCredential.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qCAAqC,EACrC,6BAA6B,EAC7B,uCAAuC,EACxC,MAAM,oCAAoC,CAAC;AAO5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAgBxD;;;GAGG;AACH,qBAAa,4BAA6B,YAAW,eAAe;IAClE,iCAAiC,EAAE,MAAM,CAAC;IAC1C,cAAc,EAAE,MAAM,CAAC;gBAEX,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAKnD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAM1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;IAChE;;;;OAIG;gBACS,OAAO,CAAC,EAAE,qCAAqC;IAE3D;;;;OAIG;gBACS,OAAO,CAAC,EAAE,uCAAuC;IAE7D;;;;OAIG;gBACS,OAAO,CAAC,EAAE,6BAA6B;CAoFpD"}
@@ -3,116 +3,17 @@
3
3
  // Licensed under the MIT License.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.DefaultAzureCredential = exports.UnavailableDefaultCredential = void 0;
6
- exports.createDefaultManagedIdentityCredential = createDefaultManagedIdentityCredential;
7
- exports.createEnvironmentCredential = createEnvironmentCredential;
8
- const index_js_1 = require("./managedIdentityCredential/index.js");
9
- const azureCliCredential_js_1 = require("./azureCliCredential.js");
10
- const azureDeveloperCliCredential_js_1 = require("./azureDeveloperCliCredential.js");
11
- const azurePowerShellCredential_js_1 = require("./azurePowerShellCredential.js");
12
6
  const chainedTokenCredential_js_1 = require("./chainedTokenCredential.js");
13
- const environmentCredential_js_1 = require("./environmentCredential.js");
14
- const workloadIdentityCredential_js_1 = require("./workloadIdentityCredential.js");
15
7
  const logging_js_1 = require("../util/logging.js");
8
+ const defaultAzureCredentialFunctions_js_1 = require("./defaultAzureCredentialFunctions.js");
16
9
  const logger = (0, logging_js_1.credentialLogger)("DefaultAzureCredential");
17
- /**
18
- * Creates a {@link ManagedIdentityCredential} from the provided options.
19
- * @param options - Options to configure the credential.
20
- *
21
- * @internal
22
- */
23
- function createDefaultManagedIdentityCredential(options = {}) {
24
- var _a, _b, _c, _d;
25
- (_a = options.retryOptions) !== null && _a !== void 0 ? _a : (options.retryOptions = {
26
- maxRetries: 5,
27
- retryDelayInMs: 800,
28
- });
29
- const managedIdentityClientId = (_b = options === null || options === void 0 ? void 0 : options.managedIdentityClientId) !== null && _b !== void 0 ? _b : process.env.AZURE_CLIENT_ID;
30
- const workloadIdentityClientId = (_c = options === null || options === void 0 ? void 0 : options.workloadIdentityClientId) !== null && _c !== void 0 ? _c : managedIdentityClientId;
31
- const managedResourceId = options === null || options === void 0 ? void 0 : options.managedIdentityResourceId;
32
- const workloadFile = process.env.AZURE_FEDERATED_TOKEN_FILE;
33
- const tenantId = (_d = options === null || options === void 0 ? void 0 : options.tenantId) !== null && _d !== void 0 ? _d : process.env.AZURE_TENANT_ID;
34
- if (managedResourceId) {
35
- const managedIdentityResourceIdOptions = Object.assign(Object.assign({}, options), { resourceId: managedResourceId });
36
- return new index_js_1.ManagedIdentityCredential(managedIdentityResourceIdOptions);
37
- }
38
- if (workloadFile && workloadIdentityClientId) {
39
- const workloadIdentityCredentialOptions = Object.assign(Object.assign({}, options), { tenantId: tenantId });
40
- return new index_js_1.ManagedIdentityCredential(workloadIdentityClientId, workloadIdentityCredentialOptions);
41
- }
42
- if (managedIdentityClientId) {
43
- const managedIdentityClientOptions = Object.assign(Object.assign({}, options), { clientId: managedIdentityClientId });
44
- return new index_js_1.ManagedIdentityCredential(managedIdentityClientOptions);
45
- }
46
- // We may be able to return a UnavailableCredential here, but that may be a breaking change
47
- return new index_js_1.ManagedIdentityCredential(options);
48
- }
49
- /**
50
- * Creates a {@link WorkloadIdentityCredential} from the provided options.
51
- * @param options - Options to configure the credential.
52
- *
53
- * @internal
54
- */
55
- function createDefaultWorkloadIdentityCredential(options) {
56
- var _a, _b, _c;
57
- const managedIdentityClientId = (_a = options === null || options === void 0 ? void 0 : options.managedIdentityClientId) !== null && _a !== void 0 ? _a : process.env.AZURE_CLIENT_ID;
58
- const workloadIdentityClientId = (_b = options === null || options === void 0 ? void 0 : options.workloadIdentityClientId) !== null && _b !== void 0 ? _b : managedIdentityClientId;
59
- const workloadFile = process.env.AZURE_FEDERATED_TOKEN_FILE;
60
- const tenantId = (_c = options === null || options === void 0 ? void 0 : options.tenantId) !== null && _c !== void 0 ? _c : process.env.AZURE_TENANT_ID;
61
- if (workloadFile && workloadIdentityClientId) {
62
- const workloadIdentityCredentialOptions = Object.assign(Object.assign({}, options), { tenantId, clientId: workloadIdentityClientId, tokenFilePath: workloadFile });
63
- return new workloadIdentityCredential_js_1.WorkloadIdentityCredential(workloadIdentityCredentialOptions);
64
- }
65
- if (tenantId) {
66
- const workloadIdentityClientTenantOptions = Object.assign(Object.assign({}, options), { tenantId });
67
- return new workloadIdentityCredential_js_1.WorkloadIdentityCredential(workloadIdentityClientTenantOptions);
68
- }
69
- // We may be able to return a UnavailableCredential here, but that may be a breaking change
70
- return new workloadIdentityCredential_js_1.WorkloadIdentityCredential(options);
71
- }
72
- /**
73
- * Creates a {@link AzureDeveloperCliCredential} from the provided options.
74
- * @param options - Options to configure the credential.
75
- *
76
- * @internal
77
- */
78
- function createDefaultAzureDeveloperCliCredential(options = {}) {
79
- const processTimeoutInMs = options.processTimeoutInMs;
80
- return new azureDeveloperCliCredential_js_1.AzureDeveloperCliCredential(Object.assign({ processTimeoutInMs }, options));
81
- }
82
- /**
83
- * Creates a {@link AzureCliCredential} from the provided options.
84
- * @param options - Options to configure the credential.
85
- *
86
- * @internal
87
- */
88
- function createDefaultAzureCliCredential(options = {}) {
89
- const processTimeoutInMs = options.processTimeoutInMs;
90
- return new azureCliCredential_js_1.AzureCliCredential(Object.assign({ processTimeoutInMs }, options));
91
- }
92
- /**
93
- * Creates a {@link AzurePowerShellCredential} from the provided options.
94
- * @param options - Options to configure the credential.
95
- *
96
- * @internal
97
- */
98
- function createDefaultAzurePowershellCredential(options = {}) {
99
- const processTimeoutInMs = options.processTimeoutInMs;
100
- return new azurePowerShellCredential_js_1.AzurePowerShellCredential(Object.assign({ processTimeoutInMs }, options));
101
- }
102
- /**
103
- * Creates an {@link EnvironmentCredential} from the provided options.
104
- * @param options - Options to configure the credential.
105
- *
106
- * @internal
107
- */
108
- function createEnvironmentCredential(options = {}) {
109
- return new environmentCredential_js_1.EnvironmentCredential(options);
110
- }
111
10
  /**
112
11
  * A no-op credential that logs the reason it was skipped if getToken is called.
113
12
  * @internal
114
13
  */
115
14
  class UnavailableDefaultCredential {
15
+ credentialUnavailableErrorMessage;
16
+ credentialName;
116
17
  constructor(credentialName, message) {
117
18
  this.credentialName = credentialName;
118
19
  this.credentialUnavailableErrorMessage = message;
@@ -133,12 +34,24 @@ exports.UnavailableDefaultCredential = UnavailableDefaultCredential;
133
34
  * - {@link EnvironmentCredential}
134
35
  * - {@link WorkloadIdentityCredential}
135
36
  * - {@link ManagedIdentityCredential}
37
+ * - {@link VisualStudioCodeCredential}
136
38
  * - {@link AzureCliCredential}
137
39
  * - {@link AzurePowerShellCredential}
138
40
  * - {@link AzureDeveloperCliCredential}
139
41
  *
140
42
  * Consult the documentation of these credential types for more information
141
43
  * on how they attempt authentication.
44
+ *
45
+ * Selecting credentials
46
+ *
47
+ * Set environment variable AZURE_TOKEN_CREDENTIALS to select a subset of the credential chain.
48
+ * DefaultAzureCredential will try only the specified credential(s), but its other behavior remains the same.
49
+ * Valid values for AZURE_TOKEN_CREDENTIALS are the name of any single type in the above chain, for example
50
+ * "EnvironmentCredential" or "AzureCliCredential", and these special values:
51
+ *
52
+ * - "dev": try [VisualStudioCodeCredential], [AzureCliCredential], [AzurePowerShellCredential] and [AzureDeveloperCliCredential], in that order
53
+ * - "prod": try [EnvironmentCredential], [WorkloadIdentityCredential], and [ManagedIdentityCredential], in that order
54
+ *
142
55
  */
143
56
  class DefaultAzureCredential extends chainedTokenCredential_js_1.ChainedTokenCredential {
144
57
  constructor(options) {
@@ -147,32 +60,54 @@ class DefaultAzureCredential extends chainedTokenCredential_js_1.ChainedTokenCre
147
60
  ? process.env.AZURE_TOKEN_CREDENTIALS.trim().toLowerCase()
148
61
  : undefined;
149
62
  const devCredentialFunctions = [
150
- createDefaultAzureCliCredential,
151
- createDefaultAzurePowershellCredential,
152
- createDefaultAzureDeveloperCliCredential,
63
+ defaultAzureCredentialFunctions_js_1.createDefaultVisualStudioCodeCredential,
64
+ defaultAzureCredentialFunctions_js_1.createDefaultAzureCliCredential,
65
+ defaultAzureCredentialFunctions_js_1.createDefaultAzurePowershellCredential,
66
+ defaultAzureCredentialFunctions_js_1.createDefaultAzureDeveloperCliCredential,
67
+ defaultAzureCredentialFunctions_js_1.createDefaultBrokerCredential,
153
68
  ];
154
69
  const prodCredentialFunctions = [
155
- createEnvironmentCredential,
156
- createDefaultWorkloadIdentityCredential,
157
- createDefaultManagedIdentityCredential,
70
+ defaultAzureCredentialFunctions_js_1.createDefaultEnvironmentCredential,
71
+ defaultAzureCredentialFunctions_js_1.createDefaultWorkloadIdentityCredential,
72
+ defaultAzureCredentialFunctions_js_1.createDefaultManagedIdentityCredential,
158
73
  ];
159
74
  let credentialFunctions = [];
75
+ const validCredentialNames = "EnvironmentCredential, WorkloadIdentityCredential, ManagedIdentityCredential, VisualStudioCodeCredential, AzureCliCredential, AzurePowerShellCredential, AzureDeveloperCliCredential";
160
76
  // If AZURE_TOKEN_CREDENTIALS is set, use it to determine which credentials to use.
161
- // The value of AZURE_TOKEN_CREDENTIALS should be either "dev" or "prod".
77
+ // The value of AZURE_TOKEN_CREDENTIALS should be either "dev" or "prod" or any one of these credentials - {validCredentialNames}.
162
78
  if (azureTokenCredentials) {
163
79
  switch (azureTokenCredentials) {
164
80
  case "dev":
165
- // If AZURE_TOKEN_CREDENTIALS is set to "dev", use the developer tool-based credential chain.
166
81
  credentialFunctions = devCredentialFunctions;
167
82
  break;
168
83
  case "prod":
169
- // If AZURE_TOKEN_CREDENTIALS is set to "prod", use the production credential chain.
170
84
  credentialFunctions = prodCredentialFunctions;
171
85
  break;
86
+ case "environmentcredential":
87
+ credentialFunctions = [defaultAzureCredentialFunctions_js_1.createDefaultEnvironmentCredential];
88
+ break;
89
+ case "workloadidentitycredential":
90
+ credentialFunctions = [defaultAzureCredentialFunctions_js_1.createDefaultWorkloadIdentityCredential];
91
+ break;
92
+ case "managedidentitycredential":
93
+ credentialFunctions = [defaultAzureCredentialFunctions_js_1.createDefaultManagedIdentityCredential];
94
+ break;
95
+ case "visualstudiocodecredential":
96
+ credentialFunctions = [defaultAzureCredentialFunctions_js_1.createDefaultVisualStudioCodeCredential];
97
+ break;
98
+ case "azureclicredential":
99
+ credentialFunctions = [defaultAzureCredentialFunctions_js_1.createDefaultAzureCliCredential];
100
+ break;
101
+ case "azurepowershellcredential":
102
+ credentialFunctions = [defaultAzureCredentialFunctions_js_1.createDefaultAzurePowershellCredential];
103
+ break;
104
+ case "azuredeveloperclicredential":
105
+ credentialFunctions = [defaultAzureCredentialFunctions_js_1.createDefaultAzureDeveloperCliCredential];
106
+ break;
172
107
  default: {
173
108
  // If AZURE_TOKEN_CREDENTIALS is set to an unsupported value, throw an error.
174
- // We will throw an error here to prevent the creation of the DefaultAzureCredential.
175
- const errorMessage = `Invalid value for AZURE_TOKEN_CREDENTIALS = ${process.env.AZURE_TOKEN_CREDENTIALS}. Valid values are 'prod' or 'dev'.`;
109
+ // This will prevent the creation of the DefaultAzureCredential.
110
+ const errorMessage = `Invalid value for AZURE_TOKEN_CREDENTIALS = ${process.env.AZURE_TOKEN_CREDENTIALS}. Valid values are 'prod' or 'dev' or any of these credentials - ${validCredentialNames}.`;
176
111
  logger.warning(errorMessage);
177
112
  throw new Error(errorMessage);
178
113
  }