@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
@@ -14,6 +14,14 @@ const logger = credentialLogger(credentialName);
14
14
  * Enables authentication to Microsoft Entra ID using the [On Behalf Of flow](https://learn.microsoft.com/entra/identity-platform/v2-oauth2-on-behalf-of-flow).
15
15
  */
16
16
  export class OnBehalfOfCredential {
17
+ tenantId;
18
+ additionallyAllowedTenantIds;
19
+ msalClient;
20
+ sendCertificateChain;
21
+ certificatePath;
22
+ clientSecret;
23
+ userAssertionToken;
24
+ clientAssertion;
17
25
  constructor(options) {
18
26
  const { clientSecret } = options;
19
27
  const { certificatePath, sendCertificateChain } = options;
@@ -38,7 +46,11 @@ export class OnBehalfOfCredential {
38
46
  this.clientAssertion = getAssertion;
39
47
  this.tenantId = tenantId;
40
48
  this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(additionallyAllowedTenantIds);
41
- this.msalClient = createMsalClient(clientId, this.tenantId, Object.assign(Object.assign({}, options), { logger, tokenCredentialOptions: options }));
49
+ this.msalClient = createMsalClient(clientId, this.tenantId, {
50
+ ...options,
51
+ logger,
52
+ tokenCredentialOptions: options,
53
+ });
42
54
  }
43
55
  /**
44
56
  * Authenticates with Microsoft Entra ID and returns an access token if successful.
@@ -1 +1 @@
1
- {"version":3,"file":"onBehalfOfCredential.js","sourceRoot":"","sources":["../../../src/credentials/onBehalfOfCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAOnE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EACL,yBAAyB,EACzB,mCAAmC,GACpC,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAA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AQ,KAAK,EAAE;QAEhB,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;QAChG,CAAC;QACD,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,4DAA4D;aAC/F,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;aAC5C,MAAM,CAAC,KAAK,CAAC;aACb,WAAW,EAAE,CAAC;QAEjB,MAAM,gBAAgB,GAAG,UAAU,CAAC,QAAQ,CAAC;aAC1C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;aAC5C,MAAM,CAAC,KAAK,CAAC;aACb,WAAW,EAAE,CAAC;QAEjB,OAAO;YACL,mBAAmB;YACnB,gBAAgB;YAChB,UAAU;YACV,GAAG;SACJ,CAAC;IACJ,CAAC;CACF","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 type {\n OnBehalfOfCredentialAssertionOptions,\n OnBehalfOfCredentialCertificateOptions,\n OnBehalfOfCredentialOptions,\n OnBehalfOfCredentialSecretOptions,\n} from \"./onBehalfOfCredentialOptions.js\";\nimport { credentialLogger, formatError } from \"../util/logging.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\n\nimport type { CertificateParts } from \"../msal/types.js\";\nimport type { ClientCertificatePEMCertificatePath } from \"./clientCertificateCredentialModels.js\";\nimport type { CredentialPersistenceOptions } from \"./credentialPersistenceOptions.js\";\nimport { CredentialUnavailableError } from \"../errors.js\";\nimport type { MultiTenantTokenCredentialOptions } from \"./multiTenantTokenCredentialOptions.js\";\nimport { createHash } from \"node:crypto\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { readFile } from \"node:fs/promises\";\nimport { tracingClient } from \"../util/tracing.js\";\n\nconst credentialName = \"OnBehalfOfCredential\";\nconst logger = credentialLogger(credentialName);\n\n/**\n * Enables authentication to Microsoft Entra ID using the [On Behalf Of flow](https://learn.microsoft.com/entra/identity-platform/v2-oauth2-on-behalf-of-flow).\n */\nexport class OnBehalfOfCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private msalClient: MsalClient;\n private sendCertificateChain?: boolean;\n private certificatePath?: string;\n private clientSecret?: string;\n private userAssertionToken: string;\n private clientAssertion?: () => Promise<string>;\n\n /**\n * Creates an instance of the {@link OnBehalfOfCredential} with the details\n * needed to authenticate against Microsoft Entra ID with path to a PEM certificate,\n * and an user assertion.\n *\n * Example using the `KeyClient` from [\\@azure/keyvault-keys](https://www.npmjs.com/package/\\@azure/keyvault-keys):\n *\n * ```ts snippet:on_behalf_of_credential_pem_example\n * import { OnBehalfOfCredential } from \"@azure/identity\";\n * import { KeyClient } from \"@azure/keyvault-keys\";\n *\n * const tokenCredential = new OnBehalfOfCredential({\n * tenantId: \"tenant-id\",\n * clientId: \"client-id\",\n * certificatePath: \"/path/to/certificate.pem\",\n * userAssertionToken: \"access-token\",\n * });\n * const client = new KeyClient(\"vault-url\", tokenCredential);\n *\n * await client.getKey(\"key-name\");\n * ```\n *\n * @param options - Optional parameters, generally common across credentials.\n */\n constructor(\n options: OnBehalfOfCredentialCertificateOptions &\n MultiTenantTokenCredentialOptions &\n CredentialPersistenceOptions,\n );\n /**\n * Creates an instance of the {@link OnBehalfOfCredential} with the details\n * needed to authenticate against Microsoft Entra ID with a client\n * secret and an user assertion.\n *\n * Example using the `KeyClient` from [\\@azure/keyvault-keys](https://www.npmjs.com/package/\\@azure/keyvault-keys):\n *\n * ```ts snippet:on_behalf_of_credential_secret_example\n * import { OnBehalfOfCredential } from \"@azure/identity\";\n * import { KeyClient } from \"@azure/keyvault-keys\";\n *\n * const tokenCredential = new OnBehalfOfCredential({\n * tenantId: \"tenant-id\",\n * clientId: \"client-id\",\n * clientSecret: \"client-secret\",\n * userAssertionToken: \"access-token\",\n * });\n * const client = new KeyClient(\"vault-url\", tokenCredential);\n *\n * await client.getKey(\"key-name\");\n * ```\n *\n * @param options - Optional parameters, generally common across credentials.\n */\n constructor(\n options: OnBehalfOfCredentialSecretOptions &\n MultiTenantTokenCredentialOptions &\n CredentialPersistenceOptions,\n );\n\n /**\n * Creates an instance of the {@link OnBehalfOfCredential} with the details\n * needed to authenticate against Microsoft Entra ID with a client `getAssertion`\n * and an user assertion.\n *\n * Example using the `KeyClient` from [\\@azure/keyvault-keys](https://www.npmjs.com/package/\\@azure/keyvault-keys):\n *\n * ```ts snippet:on_behalf_of_credential_assertion_example\n * import { OnBehalfOfCredential } from \"@azure/identity\";\n * import { KeyClient } from \"@azure/keyvault-keys\";\n *\n * const tokenCredential = new OnBehalfOfCredential({\n * tenantId: \"tenant-id\",\n * clientId: \"client-id\",\n * getAssertion: () => {\n * return Promise.resolve(\"my-jwt\");\n * },\n * userAssertionToken: \"access-token\",\n * });\n * const client = new KeyClient(\"vault-url\", tokenCredential);\n *\n * await client.getKey(\"key-name\");\n * ```\n *\n * @param options - Optional parameters, generally common across credentials.\n */\n constructor(\n options: OnBehalfOfCredentialAssertionOptions &\n MultiTenantTokenCredentialOptions &\n CredentialPersistenceOptions,\n );\n\n constructor(options: OnBehalfOfCredentialOptions) {\n const { clientSecret } = options as OnBehalfOfCredentialSecretOptions;\n const { certificatePath, sendCertificateChain } =\n options as OnBehalfOfCredentialCertificateOptions;\n const { getAssertion } = options as OnBehalfOfCredentialAssertionOptions;\n const {\n tenantId,\n clientId,\n userAssertionToken,\n additionallyAllowedTenants: additionallyAllowedTenantIds,\n } = options;\n if (!tenantId) {\n throw new CredentialUnavailableError(\n `${credentialName}: 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 `${credentialName}: clientId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n\n if (!clientSecret && !certificatePath && !getAssertion) {\n throw new CredentialUnavailableError(\n `${credentialName}: You must provide one of clientSecret, certificatePath, or a getAssertion callback but none were provided. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n\n if (!userAssertionToken) {\n throw new CredentialUnavailableError(\n `${credentialName}: userAssertionToken is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n this.certificatePath = certificatePath;\n this.clientSecret = clientSecret;\n this.userAssertionToken = userAssertionToken;\n this.sendCertificateChain = sendCertificateChain;\n this.clientAssertion = getAssertion;\n\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n additionallyAllowedTenantIds,\n );\n\n this.msalClient = createMsalClient(clientId, this.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 the underlying network requests.\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 = ensureScopes(scopes);\n if (this.certificatePath) {\n const clientCertificate = await this.buildClientCertificate(this.certificatePath);\n\n return this.msalClient.getTokenOnBehalfOf(\n arrayScopes,\n this.userAssertionToken,\n clientCertificate,\n newOptions,\n );\n } else if (this.clientSecret) {\n return this.msalClient.getTokenOnBehalfOf(\n arrayScopes,\n this.userAssertionToken,\n this.clientSecret,\n options,\n );\n } else if (this.clientAssertion) {\n return this.msalClient.getTokenOnBehalfOf(\n arrayScopes,\n this.userAssertionToken,\n this.clientAssertion,\n options,\n );\n } else {\n // this is an invalid scenario and is a bug, as the constructor should have thrown an error if neither clientSecret nor certificatePath nor clientAssertion were provided\n throw new Error(\n \"Expected either clientSecret or certificatePath or clientAssertion to be defined.\",\n );\n }\n });\n }\n\n private async buildClientCertificate(certificatePath: string): Promise<CertificateParts> {\n try {\n const parts = await this.parseCertificate({ certificatePath }, this.sendCertificateChain);\n return {\n thumbprint: parts.thumbprint,\n thumbprintSha256: parts.thumbprintSha256,\n privateKey: parts.certificateContents,\n x5c: parts.x5c,\n };\n } catch (error: any) {\n logger.info(formatError(\"\", error));\n throw error;\n }\n }\n\n private async parseCertificate(\n configuration: ClientCertificatePEMCertificatePath,\n sendCertificateChain?: boolean,\n ): Promise<Omit<CertificateParts, \"privateKey\"> & { certificateContents: string }> {\n const certificatePath = configuration.certificatePath;\n const certificateContents = 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 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}\n"]}
1
+ {"version":3,"file":"onBehalfOfCredential.js","sourceRoot":"","sources":["../../../src/credentials/onBehalfOfCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAOnE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EACL,yBAAyB,EACzB,mCAAmC,GACpC,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAC9C,MAAM,MAAM,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;AAEhD;;GAEG;AACH,MAAM,OAAO,oBAAoB;IACvB,QAAQ,CAAS;IACjB,4BAA4B,CAAW;IACvC,UAAU,CAAa;IACvB,oBAAoB,CAAW;IAC/B,eAAe,CAAU;IACzB,YAAY,CAAU;IACtB,kBAAkB,CAAS;IAC3B,eAAe,CAAyB;IA6FhD,YAAY,OAAoC;QAC9C,MAAM,EAAE,YAAY,EAAE,GAAG,OAA4C,CAAC;QACtE,MAAM,EAAE,eAAe,EAAE,oBAAoB,EAAE,GAC7C,OAAiD,CAAC;QACpD,MAAM,EAAE,YAAY,EAAE,GAAG,OAA+C,CAAC;QACzE,MAAM,EACJ,QAAQ,EACR,QAAQ,EACR,kBA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,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;aAC5C,MAAM,CAAC,KAAK,CAAC;aACb,WAAW,EAAE,CAAC;QAEjB,OAAO;YACL,mBAAmB;YACnB,gBAAgB;YAChB,UAAU;YACV,GAAG;SACJ,CAAC;IACJ,CAAC;CACF","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 type {\n OnBehalfOfCredentialAssertionOptions,\n OnBehalfOfCredentialCertificateOptions,\n OnBehalfOfCredentialOptions,\n OnBehalfOfCredentialSecretOptions,\n} from \"./onBehalfOfCredentialOptions.js\";\nimport { credentialLogger, formatError } from \"../util/logging.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\n\nimport type { CertificateParts } from \"../msal/types.js\";\nimport type { ClientCertificatePEMCertificatePath } from \"./clientCertificateCredentialModels.js\";\nimport type { CredentialPersistenceOptions } from \"./credentialPersistenceOptions.js\";\nimport { CredentialUnavailableError } from \"../errors.js\";\nimport type { MultiTenantTokenCredentialOptions } from \"./multiTenantTokenCredentialOptions.js\";\nimport { createHash } from \"node:crypto\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { readFile } from \"node:fs/promises\";\nimport { tracingClient } from \"../util/tracing.js\";\n\nconst credentialName = \"OnBehalfOfCredential\";\nconst logger = credentialLogger(credentialName);\n\n/**\n * Enables authentication to Microsoft Entra ID using the [On Behalf Of flow](https://learn.microsoft.com/entra/identity-platform/v2-oauth2-on-behalf-of-flow).\n */\nexport class OnBehalfOfCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private msalClient: MsalClient;\n private sendCertificateChain?: boolean;\n private certificatePath?: string;\n private clientSecret?: string;\n private userAssertionToken: string;\n private clientAssertion?: () => Promise<string>;\n\n /**\n * Creates an instance of the {@link OnBehalfOfCredential} with the details\n * needed to authenticate against Microsoft Entra ID with path to a PEM certificate,\n * and an user assertion.\n *\n * Example using the `KeyClient` from [\\@azure/keyvault-keys](https://www.npmjs.com/package/\\@azure/keyvault-keys):\n *\n * ```ts snippet:on_behalf_of_credential_pem_example\n * import { OnBehalfOfCredential } from \"@azure/identity\";\n * import { KeyClient } from \"@azure/keyvault-keys\";\n *\n * const tokenCredential = new OnBehalfOfCredential({\n * tenantId: \"tenant-id\",\n * clientId: \"client-id\",\n * certificatePath: \"/path/to/certificate.pem\",\n * userAssertionToken: \"access-token\",\n * });\n * const client = new KeyClient(\"vault-url\", tokenCredential);\n *\n * await client.getKey(\"key-name\");\n * ```\n *\n * @param options - Optional parameters, generally common across credentials.\n */\n constructor(\n options: OnBehalfOfCredentialCertificateOptions &\n MultiTenantTokenCredentialOptions &\n CredentialPersistenceOptions,\n );\n /**\n * Creates an instance of the {@link OnBehalfOfCredential} with the details\n * needed to authenticate against Microsoft Entra ID with a client\n * secret and an user assertion.\n *\n * Example using the `KeyClient` from [\\@azure/keyvault-keys](https://www.npmjs.com/package/\\@azure/keyvault-keys):\n *\n * ```ts snippet:on_behalf_of_credential_secret_example\n * import { OnBehalfOfCredential } from \"@azure/identity\";\n * import { KeyClient } from \"@azure/keyvault-keys\";\n *\n * const tokenCredential = new OnBehalfOfCredential({\n * tenantId: \"tenant-id\",\n * clientId: \"client-id\",\n * clientSecret: \"client-secret\",\n * userAssertionToken: \"access-token\",\n * });\n * const client = new KeyClient(\"vault-url\", tokenCredential);\n *\n * await client.getKey(\"key-name\");\n * ```\n *\n * @param options - Optional parameters, generally common across credentials.\n */\n constructor(\n options: OnBehalfOfCredentialSecretOptions &\n MultiTenantTokenCredentialOptions &\n CredentialPersistenceOptions,\n );\n\n /**\n * Creates an instance of the {@link OnBehalfOfCredential} with the details\n * needed to authenticate against Microsoft Entra ID with a client `getAssertion`\n * and an user assertion.\n *\n * Example using the `KeyClient` from [\\@azure/keyvault-keys](https://www.npmjs.com/package/\\@azure/keyvault-keys):\n *\n * ```ts snippet:on_behalf_of_credential_assertion_example\n * import { OnBehalfOfCredential } from \"@azure/identity\";\n * import { KeyClient } from \"@azure/keyvault-keys\";\n *\n * const tokenCredential = new OnBehalfOfCredential({\n * tenantId: \"tenant-id\",\n * clientId: \"client-id\",\n * getAssertion: () => {\n * return Promise.resolve(\"my-jwt\");\n * },\n * userAssertionToken: \"access-token\",\n * });\n * const client = new KeyClient(\"vault-url\", tokenCredential);\n *\n * await client.getKey(\"key-name\");\n * ```\n *\n * @param options - Optional parameters, generally common across credentials.\n */\n constructor(\n options: OnBehalfOfCredentialAssertionOptions &\n MultiTenantTokenCredentialOptions &\n CredentialPersistenceOptions,\n );\n\n constructor(options: OnBehalfOfCredentialOptions) {\n const { clientSecret } = options as OnBehalfOfCredentialSecretOptions;\n const { certificatePath, sendCertificateChain } =\n options as OnBehalfOfCredentialCertificateOptions;\n const { getAssertion } = options as OnBehalfOfCredentialAssertionOptions;\n const {\n tenantId,\n clientId,\n userAssertionToken,\n additionallyAllowedTenants: additionallyAllowedTenantIds,\n } = options;\n if (!tenantId) {\n throw new CredentialUnavailableError(\n `${credentialName}: 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 `${credentialName}: clientId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n\n if (!clientSecret && !certificatePath && !getAssertion) {\n throw new CredentialUnavailableError(\n `${credentialName}: You must provide one of clientSecret, certificatePath, or a getAssertion callback but none were provided. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n\n if (!userAssertionToken) {\n throw new CredentialUnavailableError(\n `${credentialName}: userAssertionToken is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n this.certificatePath = certificatePath;\n this.clientSecret = clientSecret;\n this.userAssertionToken = userAssertionToken;\n this.sendCertificateChain = sendCertificateChain;\n this.clientAssertion = getAssertion;\n\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n additionallyAllowedTenantIds,\n );\n\n this.msalClient = createMsalClient(clientId, this.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 the underlying network requests.\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 = ensureScopes(scopes);\n if (this.certificatePath) {\n const clientCertificate = await this.buildClientCertificate(this.certificatePath);\n\n return this.msalClient.getTokenOnBehalfOf(\n arrayScopes,\n this.userAssertionToken,\n clientCertificate,\n newOptions,\n );\n } else if (this.clientSecret) {\n return this.msalClient.getTokenOnBehalfOf(\n arrayScopes,\n this.userAssertionToken,\n this.clientSecret,\n options,\n );\n } else if (this.clientAssertion) {\n return this.msalClient.getTokenOnBehalfOf(\n arrayScopes,\n this.userAssertionToken,\n this.clientAssertion,\n options,\n );\n } else {\n // this is an invalid scenario and is a bug, as the constructor should have thrown an error if neither clientSecret nor certificatePath nor clientAssertion were provided\n throw new Error(\n \"Expected either clientSecret or certificatePath or clientAssertion to be defined.\",\n );\n }\n });\n }\n\n private async buildClientCertificate(certificatePath: string): Promise<CertificateParts> {\n try {\n const parts = await this.parseCertificate({ certificatePath }, this.sendCertificateChain);\n return {\n thumbprint: parts.thumbprint,\n thumbprintSha256: parts.thumbprintSha256,\n privateKey: parts.certificateContents,\n x5c: parts.x5c,\n };\n } catch (error: any) {\n logger.info(formatError(\"\", error));\n throw error;\n }\n }\n\n private async parseCertificate(\n configuration: ClientCertificatePEMCertificatePath,\n sendCertificateChain?: boolean,\n ): Promise<Omit<CertificateParts, \"privateKey\"> & { certificateContents: string }> {\n const certificatePath = configuration.certificatePath;\n const certificateContents = 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 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}\n"]}
@@ -15,6 +15,11 @@ const logger = credentialLogger("UsernamePasswordCredential");
15
15
  * @deprecated UsernamePasswordCredential is deprecated. Use a more secure credential. See https://aka.ms/azsdk/identity/mfa for details.
16
16
  */
17
17
  export class UsernamePasswordCredential {
18
+ tenantId;
19
+ additionallyAllowedTenantIds;
20
+ msalClient;
21
+ username;
22
+ password;
18
23
  /**
19
24
  * Creates an instance of the UsernamePasswordCredential with the details
20
25
  * needed to authenticate against Microsoft Entra ID with a username
@@ -40,10 +45,13 @@ export class UsernamePasswordCredential {
40
45
  throw new CredentialUnavailableError("UsernamePasswordCredential: password is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.");
41
46
  }
42
47
  this.tenantId = tenantId;
43
- this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
48
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options?.additionallyAllowedTenants);
44
49
  this.username = username;
45
50
  this.password = password;
46
- this.msalClient = createMsalClient(clientId, this.tenantId, Object.assign(Object.assign({}, options), { tokenCredentialOptions: options !== null && options !== void 0 ? options : {} }));
51
+ this.msalClient = createMsalClient(clientId, this.tenantId, {
52
+ ...options,
53
+ tokenCredentialOptions: options ?? {},
54
+ });
47
55
  }
48
56
  /**
49
57
  * Authenticates with Microsoft Entra ID and returns an access token if successful.
@@ -1 +1 @@
1
- {"version":3,"file":"usernamePasswordCredential.js","sourceRoot":"","sources":["../../../src/credentials/usernamePasswordCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EACL,yBAAyB,EACzB,mCAAmC,GACpC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,MAAM,GAAG,gBAAgB,CAAC,4BAA4B,CAAC,CAAC;AAE9D;;;;;;GAMG;AACH,MAAM,OAAO,0BAA0B;IAOrC;;;;;;;;;;OAUG;IACH,YACE,QAAgB,EAChB,QAAgB,EAChB,QAAg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AC;YACzC,OAAO,IAAI,CAAC,UAAU,CAAC,0BAA0B,CAC/C,WAAW,EACX,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,QAAQ,EACb,UAAU,CACX,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF","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 { CredentialUnavailableError } from \"../errors.js\";\nimport type { UsernamePasswordCredentialOptions } from \"./usernamePasswordCredentialOptions.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\nconst logger = credentialLogger(\"UsernamePasswordCredential\");\n\n/**\n * Enables authentication to Microsoft Entra ID with a user's\n * username and password. This credential requires a high degree of\n * trust so you should only use it when other, more secure credential\n * types can't be used.\n * @deprecated UsernamePasswordCredential is deprecated. Use a more secure credential. See https://aka.ms/azsdk/identity/mfa for details.\n */\nexport class UsernamePasswordCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private msalClient: MsalClient;\n private username: string;\n private password: string;\n\n /**\n * Creates an instance of the UsernamePasswordCredential with the details\n * needed to authenticate against Microsoft Entra ID with a username\n * and password.\n *\n * @param tenantId - The Microsoft Entra tenant (directory).\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param username - The user account's e-mail address (user name).\n * @param password - The user account's account password\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n username: string,\n password: string,\n options: UsernamePasswordCredentialOptions = {},\n ) {\n if (!tenantId) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: tenantId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n if (!clientId) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: clientId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n if (!username) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: username is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n if (!password) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: password is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.username = username;\n this.password = password;\n\n this.msalClient = createMsalClient(clientId, this.tenantId, {\n ...options,\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 * If the user provided the option `disableAutomaticAuthentication`,\n * once the token can't be retrieved silently,\n * this method won't attempt to request user interaction to retrieve the token.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(\n `${this.constructor.name}.getToken`,\n options,\n async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = ensureScopes(scopes);\n return this.msalClient.getTokenByUsernamePassword(\n arrayScopes,\n this.username,\n this.password,\n newOptions,\n );\n },\n );\n }\n}\n"]}
1
+ {"version":3,"file":"usernamePasswordCredential.js","sourceRo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;QAEF,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,CAAC,UAAU,GAAG,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE;YAC1D,GAAG,OAAO;YACV,sBAAsB,EAAE,OAAO,IAAI,EAAE;SACtC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,QAAQ,CAAC,MAAyB,EAAE,UAA2B,EAAE;QACrE,OAAO,aAAa,CAAC,QAAQ,CAC3B,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,WAAW,EACnC,OAAO,EACP,KAAK,EAAE,UAAU,EAAE,EAAE;YACnB,UAAU,CAAC,QAAQ,GAAG,yBAAyB,CAC7C,IAAI,CAAC,QAAQ,EACb,UAAU,EACV,IAAI,CAAC,4BAA4B,EACjC,MAAM,CACP,CAAC;YAEF,MAAM,WAAW,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;YACzC,OAAO,IAAI,CAAC,UAAU,CAAC,0BAA0B,CAC/C,WAAW,EACX,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,QAAQ,EACb,UAAU,CACX,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF","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 { CredentialUnavailableError } from \"../errors.js\";\nimport type { UsernamePasswordCredentialOptions } from \"./usernamePasswordCredentialOptions.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\nconst logger = credentialLogger(\"UsernamePasswordCredential\");\n\n/**\n * Enables authentication to Microsoft Entra ID with a user's\n * username and password. This credential requires a high degree of\n * trust so you should only use it when other, more secure credential\n * types can't be used.\n * @deprecated UsernamePasswordCredential is deprecated. Use a more secure credential. See https://aka.ms/azsdk/identity/mfa for details.\n */\nexport class UsernamePasswordCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private msalClient: MsalClient;\n private username: string;\n private password: string;\n\n /**\n * Creates an instance of the UsernamePasswordCredential with the details\n * needed to authenticate against Microsoft Entra ID with a username\n * and password.\n *\n * @param tenantId - The Microsoft Entra tenant (directory).\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param username - The user account's e-mail address (user name).\n * @param password - The user account's account password\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n username: string,\n password: string,\n options: UsernamePasswordCredentialOptions = {},\n ) {\n if (!tenantId) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: tenantId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n if (!clientId) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: clientId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n if (!username) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: username is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n if (!password) {\n throw new CredentialUnavailableError(\n \"UsernamePasswordCredential: password is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.\",\n );\n }\n\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.username = username;\n this.password = password;\n\n this.msalClient = createMsalClient(clientId, this.tenantId, {\n ...options,\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 * If the user provided the option `disableAutomaticAuthentication`,\n * once the token can't be retrieved silently,\n * this method won't attempt to request user interaction to retrieve the token.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(\n `${this.constructor.name}.getToken`,\n options,\n async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = ensureScopes(scopes);\n return this.msalClient.getTokenByUsernamePassword(\n arrayScopes,\n this.username,\n this.password,\n newOptions,\n );\n },\n );\n }\n}\n"]}
@@ -1,48 +1,30 @@
1
1
  import type { AccessToken, GetTokenOptions, TokenCredential } from "@azure/core-auth";
2
2
  import type { VisualStudioCodeCredentialOptions } from "./visualStudioCodeCredentialOptions.js";
3
- import type { VSCodeCredentialFinder } from "./visualStudioCodeCredentialPlugin.js";
4
- export declare const vsCodeCredentialControl: {
5
- setVsCodeCredentialFinder(finder: VSCodeCredentialFinder): void;
6
- };
7
3
  /**
8
- * Attempts to load a specific property from the VSCode configurations of the current OS.
9
- * If it fails at any point, returns undefined.
10
- */
11
- export declare function getPropertyFromVSCode(property: string): string | undefined;
12
- /**
13
- * Connects to Azure using the credential provided by the VSCode extension 'Azure Account'.
4
+ * Connects to Azure using the user account signed in through the Azure Resources extension in Visual Studio Code.
14
5
  * Once the user has logged in via the extension, this credential can share the same refresh token
15
6
  * that is cached by the extension.
16
- *
17
- * It's a [known issue](https://github.com/Azure/azure-sdk-for-js/issues/20500) that this credential doesn't
18
- * work with [Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account)
19
- * versions newer than **0.9.11**. A long-term fix to this problem is in progress. In the meantime, consider
20
- * authenticating with {@link AzureCliCredential}.
21
- *
22
- * @deprecated This credential is deprecated because the VS Code Azure Account extension on which this credential
23
- * relies has been deprecated. Users should use other dev-time credentials, such as {@link AzureCliCredential},
24
- * {@link AzureDeveloperCliCredential}, or {@link AzurePowerShellCredential} for their
25
- * local development needs. See Azure Account extension deprecation notice [here](https://github.com/microsoft/vscode-azure-account/issues/964).
26
- *
27
7
  */
28
8
  export declare class VisualStudioCodeCredential implements TokenCredential {
29
- private identityClient;
30
9
  private tenantId;
31
10
  private additionallyAllowedTenantIds;
32
- private cloudName;
11
+ private msalClient;
12
+ private options;
33
13
  /**
34
14
  * Creates an instance of VisualStudioCodeCredential to use for automatically authenticating via VSCode.
35
15
  *
36
16
  * **Note**: `VisualStudioCodeCredential` is provided by a plugin package:
37
- * `@azure/identity-vscode`. If this package is not installed and registered
38
- * using the plugin API (`useIdentityPlugin`), then authentication using
17
+ * `@azure/identity-vscode`. If this package is not installed, then authentication using
39
18
  * `VisualStudioCodeCredential` will not be available.
40
19
  *
41
20
  * @param options - Options for configuring the client which makes the authentication request.
42
21
  */
43
22
  constructor(options?: VisualStudioCodeCredentialOptions);
44
23
  /**
45
- * Runs preparations for any further getToken request.
24
+ * Runs preparations for any further getToken request:
25
+ * - Validates that the plugin is available.
26
+ * - Loads the authentication record from VSCode if available.
27
+ * - Creates the MSAL client with the loaded plugin and authentication record.
46
28
  */
47
29
  private prepare;
48
30
  /**
@@ -62,5 +44,12 @@ export declare class VisualStudioCodeCredential implements TokenCredential {
62
44
  * `TokenCredential` implementation might make.
63
45
  */
64
46
  getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>;
47
+ /**
48
+ * Loads the authentication record from the specified path.
49
+ * @param authRecordPath - The path to the authentication record file.
50
+ * @param scopes - The list of scopes for which the token will have access.
51
+ * @returns The authentication record or undefined if loading fails.
52
+ */
53
+ private loadAuthRecord;
65
54
  }
66
55
  //# sourceMappingURL=visualStudioCodeCredential.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"visualStudioCodeCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/visualStudioCodeCredential.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAStF,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAChG,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAYpF,eAAO,MAAM,uBAAuB;sCACA,sBAAsB,GAAG,IAAI;CAGhE,CAAC;AAwBF;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA6B1E;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,0BAA2B,YAAW,eAAe;IAChE,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,4BAA4B,CAAW;IAC/C,OAAO,CAAC,SAAS,CAAmB;IAEpC;;;;;;;;;OASG;gBACS,OAAO,CAAC,EAAE,iCAAiC;IA2BvD;;OAEG;YACW,OAAO;IASrB;;OAEG;IACH,OAAO,CAAC,cAAc,CAA4B;IAElD;;OAEG;IACH,OAAO,CAAC,WAAW;IAOnB;;;;;;;OAOG;IACU,QAAQ,CACnB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EACzB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,WAAW,CAAC;CA6ExB"}
1
+ {"version":3,"file":"visualStudioCodeCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/visualStudioCodeCredential.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAOtF,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AA0BhG;;;;GAIG;AACH,qBAAa,0BAA2B,YAAW,eAAe;IAChE,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,4BAA4B,CAAW;IAC/C,OAAO,CAAC,UAAU,CAAyB;IAC3C,OAAO,CAAC,OAAO,CAAoC;IAEnD;;;;;;;;OAQG;gBACS,OAAO,CAAC,EAAE,iCAAiC;IAiBvD;;;;;OAKG;YACW,OAAO;IAgCrB;;OAEG;IACH,OAAO,CAAC,cAAc,CAA4B;IAElD;;OAEG;IACH,OAAO,CAAC,WAAW;IAOnB;;;;;;;OAOG;IACU,QAAQ,CACnB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EACzB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,WAAW,CAAC;IAiBvB;;;;;OAKG;YACW,cAAc;CAiB7B"}
@@ -1,23 +1,17 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
- import { credentialLogger, formatError, formatSuccess } from "../util/logging.js";
3
+ import { credentialLogger, formatError } from "../util/logging.js";
4
4
  import { processMultiTenantRequest, resolveAdditionallyAllowedTenantIds, } from "../util/tenantIdUtils.js";
5
- import { AzureAuthorityHosts } from "../constants.js";
6
5
  import { CredentialUnavailableError } from "../errors.js";
7
- import { IdentityClient } from "../client/identityClient.js";
8
6
  import { checkTenantId } from "../util/tenantIdUtils.js";
9
- import fs from "node:fs";
10
- import os from "node:os";
11
- import path from "node:path";
7
+ import { createMsalClient } from "../msal/nodeFlows/msalClient.js";
8
+ import { ensureScopes } from "../util/scopeUtils.js";
9
+ import { hasVSCodePlugin, vsCodeAuthRecordPath } from "../msal/nodeFlows/msalPlugins.js";
10
+ import { deserializeAuthenticationRecord } from "../msal/utils.js";
11
+ import { readFile } from "node:fs/promises";
12
12
  const CommonTenantId = "common";
13
- const AzureAccountClientId = "aebc6443-996d-45c2-90f0-388ff96faa56"; // VSC: 'aebc6443-996d-45c2-90f0-388ff96faa56'
13
+ const VSCodeClientId = "aebc6443-996d-45c2-90f0-388ff96faa56";
14
14
  const logger = credentialLogger("VisualStudioCodeCredential");
15
- let findCredentials = undefined;
16
- export const vsCodeCredentialControl = {
17
- setVsCodeCredentialFinder(finder) {
18
- findCredentials = finder;
19
- },
20
- };
21
15
  // Map of unsupported Tenant IDs and the errors we will be throwing.
22
16
  const unsupportedTenantIds = {
23
17
  adfs: "The VisualStudioCodeCredential does not support authentication with ADFS tenants.",
@@ -29,79 +23,27 @@ function checkUnsupportedTenant(tenantId) {
29
23
  throw new CredentialUnavailableError(unsupportedTenantError);
30
24
  }
31
25
  }
32
- const mapVSCodeAuthorityHosts = {
33
- AzureCloud: AzureAuthorityHosts.AzurePublicCloud,
34
- AzureChina: AzureAuthorityHosts.AzureChina,
35
- AzureGermanCloud: AzureAuthorityHosts.AzureGermany,
36
- AzureUSGovernment: AzureAuthorityHosts.AzureGovernment,
37
- };
38
- /**
39
- * Attempts to load a specific property from the VSCode configurations of the current OS.
40
- * If it fails at any point, returns undefined.
41
- */
42
- export function getPropertyFromVSCode(property) {
43
- const settingsPath = ["User", "settings.json"];
44
- // Eventually we can add more folders for more versions of VSCode.
45
- const vsCodeFolder = "Code";
46
- const homedir = os.homedir();
47
- function loadProperty(...pathSegments) {
48
- const fullPath = path.join(...pathSegments, vsCodeFolder, ...settingsPath);
49
- const settings = JSON.parse(fs.readFileSync(fullPath, { encoding: "utf8" }));
50
- return settings[property];
51
- }
52
- try {
53
- let appData;
54
- switch (process.platform) {
55
- case "win32":
56
- appData = process.env.APPDATA;
57
- return appData ? loadProperty(appData) : undefined;
58
- case "darwin":
59
- return loadProperty(homedir, "Library", "Application Support");
60
- case "linux":
61
- return loadProperty(homedir, ".config");
62
- default:
63
- return;
64
- }
65
- }
66
- catch (e) {
67
- logger.info(`Failed to load the Visual Studio Code configuration file. Error: ${e.message}`);
68
- return;
69
- }
70
- }
71
26
  /**
72
- * Connects to Azure using the credential provided by the VSCode extension 'Azure Account'.
27
+ * Connects to Azure using the user account signed in through the Azure Resources extension in Visual Studio Code.
73
28
  * Once the user has logged in via the extension, this credential can share the same refresh token
74
29
  * that is cached by the extension.
75
- *
76
- * It's a [known issue](https://github.com/Azure/azure-sdk-for-js/issues/20500) that this credential doesn't
77
- * work with [Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account)
78
- * versions newer than **0.9.11**. A long-term fix to this problem is in progress. In the meantime, consider
79
- * authenticating with {@link AzureCliCredential}.
80
- *
81
- * @deprecated This credential is deprecated because the VS Code Azure Account extension on which this credential
82
- * relies has been deprecated. Users should use other dev-time credentials, such as {@link AzureCliCredential},
83
- * {@link AzureDeveloperCliCredential}, or {@link AzurePowerShellCredential} for their
84
- * local development needs. See Azure Account extension deprecation notice [here](https://github.com/microsoft/vscode-azure-account/issues/964).
85
- *
86
30
  */
87
31
  export class VisualStudioCodeCredential {
32
+ tenantId;
33
+ additionallyAllowedTenantIds;
34
+ msalClient;
35
+ options;
88
36
  /**
89
37
  * Creates an instance of VisualStudioCodeCredential to use for automatically authenticating via VSCode.
90
38
  *
91
39
  * **Note**: `VisualStudioCodeCredential` is provided by a plugin package:
92
- * `@azure/identity-vscode`. If this package is not installed and registered
93
- * using the plugin API (`useIdentityPlugin`), then authentication using
40
+ * `@azure/identity-vscode`. If this package is not installed, then authentication using
94
41
  * `VisualStudioCodeCredential` will not be available.
95
42
  *
96
43
  * @param options - Options for configuring the client which makes the authentication request.
97
44
  */
98
45
  constructor(options) {
99
- // We want to make sure we use the one assigned by the user on the VSCode settings.
100
- // Or just `AzureCloud` by default.
101
- this.cloudName = (getPropertyFromVSCode("azure.cloud") || "AzureCloud");
102
- // Picking an authority host based on the cloud name.
103
- const authorityHost = mapVSCodeAuthorityHosts[this.cloudName];
104
- this.identityClient = new IdentityClient(Object.assign({ authorityHost }, options));
46
+ this.options = options || {};
105
47
  if (options && options.tenantId) {
106
48
  checkTenantId(logger, options.tenantId);
107
49
  this.tenantId = options.tenantId;
@@ -109,26 +51,46 @@ export class VisualStudioCodeCredential {
109
51
  else {
110
52
  this.tenantId = CommonTenantId;
111
53
  }
112
- this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
54
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options?.additionallyAllowedTenants);
113
55
  checkUnsupportedTenant(this.tenantId);
114
56
  }
115
57
  /**
116
- * Runs preparations for any further getToken request.
58
+ * Runs preparations for any further getToken request:
59
+ * - Validates that the plugin is available.
60
+ * - Loads the authentication record from VSCode if available.
61
+ * - Creates the MSAL client with the loaded plugin and authentication record.
117
62
  */
118
- async prepare() {
119
- // Attempts to load the tenant from the VSCode configuration file.
120
- const settingsTenant = getPropertyFromVSCode("azure.tenant");
121
- if (settingsTenant) {
122
- this.tenantId = settingsTenant;
63
+ async prepare(scopes) {
64
+ const tenantId = processMultiTenantRequest(this.tenantId, this.options, this.additionallyAllowedTenantIds, logger) || this.tenantId;
65
+ if (!hasVSCodePlugin() || !vsCodeAuthRecordPath) {
66
+ throw new CredentialUnavailableError("Visual Studio Code Authentication is not available." +
67
+ " Ensure you have have Azure Resources Extension installed in VS Code," +
68
+ " signed into Azure via VS Code, installed the @azure/identity-vscode package," +
69
+ " and properly configured the extension.");
123
70
  }
124
- checkUnsupportedTenant(this.tenantId);
71
+ // Load the authentication record directly from the path
72
+ const authenticationRecord = await this.loadAuthRecord(vsCodeAuthRecordPath, scopes);
73
+ this.msalClient = createMsalClient(VSCodeClientId, tenantId, {
74
+ ...this.options,
75
+ isVSCodeCredential: true,
76
+ brokerOptions: {
77
+ enabled: true,
78
+ parentWindowHandle: new Uint8Array(0),
79
+ useDefaultBrokerAccount: true,
80
+ },
81
+ authenticationRecord,
82
+ });
125
83
  }
84
+ /**
85
+ * The promise of the single preparation that will be executed at the first getToken request for an instance of this class.
86
+ */
87
+ preparePromise;
126
88
  /**
127
89
  * Runs preparations for any further getToken, but only once.
128
90
  */
129
- prepareOnce() {
91
+ prepareOnce(scopes) {
130
92
  if (!this.preparePromise) {
131
- this.preparePromise = this.prepare();
93
+ this.preparePromise = this.prepare(scopes);
132
94
  }
133
95
  return this.preparePromise;
134
96
  }
@@ -141,55 +103,34 @@ export class VisualStudioCodeCredential {
141
103
  * `TokenCredential` implementation might make.
142
104
  */
143
105
  async getToken(scopes, options) {
144
- var _a, _b;
145
- await this.prepareOnce();
146
- const tenantId = processMultiTenantRequest(this.tenantId, options, this.additionallyAllowedTenantIds, logger) || this.tenantId;
147
- if (findCredentials === undefined) {
148
- throw new CredentialUnavailableError([
149
- "No implementation of `VisualStudioCodeCredential` is available.",
150
- "You must install the identity-vscode plugin package (`npm install --save-dev @azure/identity-vscode`)",
151
- "and enable it by importing `useIdentityPlugin` from `@azure/identity` and calling",
152
- "`useIdentityPlugin(vsCodePlugin)` before creating a `VisualStudioCodeCredential`.",
153
- "To troubleshoot, visit https://aka.ms/azsdk/js/identity/vscodecredential/troubleshoot.",
154
- ].join(" "));
155
- }
156
- let scopeString = typeof scopes === "string" ? scopes : scopes.join(" ");
157
- // Check to make sure the scope we get back is a valid scope
158
- if (!scopeString.match(/^[0-9a-zA-Z-.:/]+$/)) {
159
- const error = new Error("Invalid scope was specified by the user or calling client");
160
- logger.getToken.info(formatError(scopes, error));
161
- throw error;
162
- }
163
- if (scopeString.indexOf("offline_access") < 0) {
164
- scopeString += " offline_access";
106
+ // Load the plugin and authentication record only once
107
+ const scopeArray = ensureScopes(scopes);
108
+ await this.prepareOnce(scopeArray);
109
+ if (!this.msalClient) {
110
+ throw new CredentialUnavailableError("Visual Studio Code Authentication failed to initialize." +
111
+ " Ensure you have have Azure Resources Extension installed in VS Code," +
112
+ " signed into Azure via VS Code, installed the @azure/identity-vscode package," +
113
+ " and properly configured the extension.");
165
114
  }
166
- // findCredentials returns an array similar to:
167
- // [
168
- // {
169
- // account: "",
170
- // password: "",
171
- // },
172
- // /* ... */
173
- // ]
174
- const credentials = await findCredentials();
175
- // If we can't find the credential based on the name, we'll pick the first one available.
176
- const { password: refreshToken } = (_b = (_a = credentials.find(({ account }) => account === this.cloudName)) !== null && _a !== void 0 ? _a : credentials[0]) !== null && _b !== void 0 ? _b : {};
177
- if (refreshToken) {
178
- const tokenResponse = await this.identityClient.refreshAccessToken(tenantId, AzureAccountClientId, scopeString, refreshToken, undefined);
179
- if (tokenResponse) {
180
- logger.getToken.info(formatSuccess(scopes));
181
- return tokenResponse.accessToken;
182
- }
183
- else {
184
- const error = new CredentialUnavailableError("Could not retrieve the token associated with Visual Studio Code. Have you connected using the 'Azure Account' extension recently? To troubleshoot, visit https://aka.ms/azsdk/js/identity/vscodecredential/troubleshoot.");
185
- logger.getToken.info(formatError(scopes, error));
186
- throw error;
187
- }
115
+ return this.msalClient.getTokenByInteractiveRequest(scopeArray, options || {});
116
+ }
117
+ /**
118
+ * Loads the authentication record from the specified path.
119
+ * @param authRecordPath - The path to the authentication record file.
120
+ * @param scopes - The list of scopes for which the token will have access.
121
+ * @returns The authentication record or undefined if loading fails.
122
+ */
123
+ async loadAuthRecord(authRecordPath, scopes) {
124
+ try {
125
+ const authRecordContent = await readFile(authRecordPath, { encoding: "utf8" });
126
+ return deserializeAuthenticationRecord(authRecordContent);
188
127
  }
189
- else {
190
- const error = new CredentialUnavailableError("Could not retrieve the token associated with Visual Studio Code. Did you connect using the 'Azure Account' extension? To troubleshoot, visit https://aka.ms/azsdk/js/identity/vscodecredential/troubleshoot.");
128
+ catch (error) {
191
129
  logger.getToken.info(formatError(scopes, error));
192
- throw error;
130
+ throw new CredentialUnavailableError("Cannot load authentication record in Visual Studio Code." +
131
+ " Ensure you have have Azure Resources Extension installed in VS Code," +
132
+ " signed into Azure via VS Code, installed the @azure/identity-vscode package," +
133
+ " and properly configured the extension.");
193
134
  }
194
135
  }
195
136
  }
@@ -1 +1 @@
1
- {"version":3,"file":"visualStudioCodeCredential.js","sourceRoot":"","sources":["../../../src/credentials/visualStudioCodeCredential.ts"],"names":[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AW,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,KAAK,IAAI,CAAC,SAAS,CAAC,mCAAI,WAAW,CAAC,CAAC,CAAC,mCAAI,EAAE,CAAC;QAExF,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAChE,QAAQ,EACR,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,SAAS,CACV,CAAC;YAEF,IAAI,aAAa,EAAE,CAAC;gBAClB,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC5C,OAAO,aAAa,CAAC,WAAW,CAAC;YACnC,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,GAAG,IAAI,0BAA0B,CAC1C,0NAA0N,CAC3N,CAAC;gBACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;gBACjD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,GAAG,IAAI,0BAA0B,CAC1C,8MAA8M,CAC/M,CAAC;YACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;YACjD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport { credentialLogger, formatError, formatSuccess } from \"../util/logging.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\nimport { AzureAuthorityHosts } from \"../constants.js\";\nimport { CredentialUnavailableError } from \"../errors.js\";\nimport { IdentityClient } from \"../client/identityClient.js\";\nimport type { VisualStudioCodeCredentialOptions } from \"./visualStudioCodeCredentialOptions.js\";\nimport type { VSCodeCredentialFinder } from \"./visualStudioCodeCredentialPlugin.js\";\nimport { checkTenantId } from \"../util/tenantIdUtils.js\";\nimport fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nconst CommonTenantId = \"common\";\nconst AzureAccountClientId = \"aebc6443-996d-45c2-90f0-388ff96faa56\"; // VSC: 'aebc6443-996d-45c2-90f0-388ff96faa56'\nconst logger = credentialLogger(\"VisualStudioCodeCredential\");\n\nlet findCredentials: VSCodeCredentialFinder | undefined = undefined;\n\nexport const vsCodeCredentialControl = {\n setVsCodeCredentialFinder(finder: VSCodeCredentialFinder): void {\n findCredentials = finder;\n },\n};\n\n// Map of unsupported Tenant IDs and the errors we will be throwing.\nconst unsupportedTenantIds: Record<string, string> = {\n adfs: \"The VisualStudioCodeCredential does not support authentication with ADFS tenants.\",\n};\n\nfunction checkUnsupportedTenant(tenantId: string): void {\n // If the Tenant ID isn't supported, we throw.\n const unsupportedTenantError = unsupportedTenantIds[tenantId];\n if (unsupportedTenantError) {\n throw new CredentialUnavailableError(unsupportedTenantError);\n }\n}\n\ntype VSCodeCloudNames = \"AzureCloud\" | \"AzureChina\" | \"AzureGermanCloud\" | \"AzureUSGovernment\";\n\nconst mapVSCodeAuthorityHosts: Record<VSCodeCloudNames, string> = {\n AzureCloud: AzureAuthorityHosts.AzurePublicCloud,\n AzureChina: AzureAuthorityHosts.AzureChina,\n AzureGermanCloud: AzureAuthorityHosts.AzureGermany,\n AzureUSGovernment: AzureAuthorityHosts.AzureGovernment,\n};\n\n/**\n * Attempts to load a specific property from the VSCode configurations of the current OS.\n * If it fails at any point, returns undefined.\n */\nexport function getPropertyFromVSCode(property: string): string | undefined {\n const settingsPath = [\"User\", \"settings.json\"];\n // Eventually we can add more folders for more versions of VSCode.\n const vsCodeFolder = \"Code\";\n const homedir = os.homedir();\n\n function loadProperty(...pathSegments: string[]): string | undefined {\n const fullPath = path.join(...pathSegments, vsCodeFolder, ...settingsPath);\n const settings = JSON.parse(fs.readFileSync(fullPath, { encoding: \"utf8\" }));\n return settings[property];\n }\n\n try {\n let appData: string;\n switch (process.platform) {\n case \"win32\":\n appData = process.env.APPDATA!;\n return appData ? loadProperty(appData) : undefined;\n case \"darwin\":\n return loadProperty(homedir, \"Library\", \"Application Support\");\n case \"linux\":\n return loadProperty(homedir, \".config\");\n default:\n return;\n }\n } catch (e: any) {\n logger.info(`Failed to load the Visual Studio Code configuration file. Error: ${e.message}`);\n return;\n }\n}\n\n/**\n * Connects to Azure using the credential provided by the VSCode extension 'Azure Account'.\n * Once the user has logged in via the extension, this credential can share the same refresh token\n * that is cached by the extension.\n *\n * It's a [known issue](https://github.com/Azure/azure-sdk-for-js/issues/20500) that this credential doesn't\n * work with [Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account)\n * versions newer than **0.9.11**. A long-term fix to this problem is in progress. In the meantime, consider\n * authenticating with {@link AzureCliCredential}.\n *\n * @deprecated This credential is deprecated because the VS Code Azure Account extension on which this credential\n * relies has been deprecated. Users should use other dev-time credentials, such as {@link AzureCliCredential},\n * {@link AzureDeveloperCliCredential}, or {@link AzurePowerShellCredential} for their\n * local development needs. See Azure Account extension deprecation notice [here](https://github.com/microsoft/vscode-azure-account/issues/964).\n *\n */\nexport class VisualStudioCodeCredential implements TokenCredential {\n private identityClient: IdentityClient;\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private cloudName: VSCodeCloudNames;\n\n /**\n * Creates an instance of VisualStudioCodeCredential to use for automatically authenticating via VSCode.\n *\n * **Note**: `VisualStudioCodeCredential` is provided by a plugin package:\n * `@azure/identity-vscode`. If this package is not installed and registered\n * using the plugin API (`useIdentityPlugin`), then authentication using\n * `VisualStudioCodeCredential` will not be available.\n *\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(options?: VisualStudioCodeCredentialOptions) {\n // We want to make sure we use the one assigned by the user on the VSCode settings.\n // Or just `AzureCloud` by default.\n this.cloudName = (getPropertyFromVSCode(\"azure.cloud\") || \"AzureCloud\") as VSCodeCloudNames;\n\n // Picking an authority host based on the cloud name.\n const authorityHost = mapVSCodeAuthorityHosts[this.cloudName];\n\n this.identityClient = new IdentityClient({\n authorityHost,\n ...options,\n });\n\n if (options && options.tenantId) {\n checkTenantId(logger, options.tenantId);\n this.tenantId = options.tenantId;\n } else {\n this.tenantId = CommonTenantId;\n }\n\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n checkUnsupportedTenant(this.tenantId);\n }\n\n /**\n * Runs preparations for any further getToken request.\n */\n private async prepare(): Promise<void> {\n // Attempts to load the tenant from the VSCode configuration file.\n const settingsTenant = getPropertyFromVSCode(\"azure.tenant\");\n if (settingsTenant) {\n this.tenantId = settingsTenant;\n }\n checkUnsupportedTenant(this.tenantId);\n }\n\n /**\n * The promise of the single preparation that will be executed at the first getToken request for an instance of this class.\n */\n private preparePromise: Promise<void> | undefined;\n\n /**\n * Runs preparations for any further getToken, but only once.\n */\n private prepareOnce(): Promise<void> | undefined {\n if (!this.preparePromise) {\n this.preparePromise = this.prepare();\n }\n return this.preparePromise;\n }\n\n /**\n * Returns the token found by searching VSCode's authentication cache or\n * returns null if no token could be found.\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 public async getToken(\n scopes: string | string[],\n options?: GetTokenOptions,\n ): Promise<AccessToken> {\n await this.prepareOnce();\n\n const tenantId =\n processMultiTenantRequest(\n this.tenantId,\n options,\n this.additionallyAllowedTenantIds,\n logger,\n ) || this.tenantId;\n\n if (findCredentials === undefined) {\n throw new CredentialUnavailableError(\n [\n \"No implementation of `VisualStudioCodeCredential` is available.\",\n \"You must install the identity-vscode plugin package (`npm install --save-dev @azure/identity-vscode`)\",\n \"and enable it by importing `useIdentityPlugin` from `@azure/identity` and calling\",\n \"`useIdentityPlugin(vsCodePlugin)` before creating a `VisualStudioCodeCredential`.\",\n \"To troubleshoot, visit https://aka.ms/azsdk/js/identity/vscodecredential/troubleshoot.\",\n ].join(\" \"),\n );\n }\n\n let scopeString = typeof scopes === \"string\" ? scopes : scopes.join(\" \");\n\n // Check to make sure the scope we get back is a valid scope\n if (!scopeString.match(/^[0-9a-zA-Z-.:/]+$/)) {\n const error = new Error(\"Invalid scope was specified by the user or calling client\");\n logger.getToken.info(formatError(scopes, error));\n throw error;\n }\n\n if (scopeString.indexOf(\"offline_access\") < 0) {\n scopeString += \" offline_access\";\n }\n\n // findCredentials returns an array similar to:\n // [\n // {\n // account: \"\",\n // password: \"\",\n // },\n // /* ... */\n // ]\n const credentials = await findCredentials();\n\n // If we can't find the credential based on the name, we'll pick the first one available.\n const { password: refreshToken } =\n credentials.find(({ account }) => account === this.cloudName) ?? credentials[0] ?? {};\n\n if (refreshToken) {\n const tokenResponse = await this.identityClient.refreshAccessToken(\n tenantId,\n AzureAccountClientId,\n scopeString,\n refreshToken,\n undefined,\n );\n\n if (tokenResponse) {\n logger.getToken.info(formatSuccess(scopes));\n return tokenResponse.accessToken;\n } else {\n const error = new CredentialUnavailableError(\n \"Could not retrieve the token associated with Visual Studio Code. Have you connected using the 'Azure Account' extension recently? To troubleshoot, visit https://aka.ms/azsdk/js/identity/vscodecredential/troubleshoot.\",\n );\n logger.getToken.info(formatError(scopes, error));\n throw error;\n }\n } else {\n const error = new CredentialUnavailableError(\n \"Could not retrieve the token associated with Visual Studio Code. Did you connect using the 'Azure Account' extension? To troubleshoot, visit https://aka.ms/azsdk/js/identity/vscodecredential/troubleshoot.\",\n );\n logger.getToken.info(formatError(scopes, error));\n throw error;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"visualStudioCodeCredential.js","sourceRoot":"","sources":["../../../src/credentials/visualStudioCodeCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM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AM,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,QAAQ,CACnB,MAAyB,EACzB,OAAyB;QAEzB,sDAAsD;QACtD,MAAM,UAAU,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;QACxC,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAEnC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,0BAA0B,CAClC,yDAAyD;gBACvD,uEAAuE;gBACvE,+EAA+E;gBAC/E,yCAAyC,CAC5C,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,4BAA4B,CAAC,UAAU,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;IACjF,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,cAAc,CAC1B,cAAsB,EACtB,MAAgB;QAEhB,IAAI,CAAC;YACH,MAAM,iBAAiB,GAAG,MAAM,QAAQ,CAAC,cAAc,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;YAC/E,OAAO,+BAA+B,CAAC,iBAAiB,CAAC,CAAC;QAC5D,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;YACjD,MAAM,IAAI,0BAA0B,CAClC,0DAA0D;gBACxD,uEAAuE;gBACvE,+EAA+E;gBAC/E,yCAAyC,CAC5C,CAAC;QACJ,CAAC;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport { credentialLogger, formatError } from \"../util/logging.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\nimport { CredentialUnavailableError } from \"../errors.js\";\nimport type { VisualStudioCodeCredentialOptions } from \"./visualStudioCodeCredentialOptions.js\";\nimport { checkTenantId } from \"../util/tenantIdUtils.js\";\nimport { createMsalClient, MsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { hasVSCodePlugin, vsCodeAuthRecordPath } from \"../msal/nodeFlows/msalPlugins.js\";\nimport { deserializeAuthenticationRecord } from \"../msal/utils.js\";\nimport { readFile } from \"node:fs/promises\";\nimport { AuthenticationRecord } from \"../msal/types.js\";\n\nconst CommonTenantId = \"common\";\nconst VSCodeClientId = \"aebc6443-996d-45c2-90f0-388ff96faa56\";\nconst logger = credentialLogger(\"VisualStudioCodeCredential\");\n\n// Map of unsupported Tenant IDs and the errors we will be throwing.\nconst unsupportedTenantIds: Record<string, string> = {\n adfs: \"The VisualStudioCodeCredential does not support authentication with ADFS tenants.\",\n};\n\nfunction checkUnsupportedTenant(tenantId: string): void {\n // If the Tenant ID isn't supported, we throw.\n const unsupportedTenantError = unsupportedTenantIds[tenantId];\n if (unsupportedTenantError) {\n throw new CredentialUnavailableError(unsupportedTenantError);\n }\n}\n\n/**\n * Connects to Azure using the user account signed in through the Azure Resources extension in Visual Studio Code.\n * Once the user has logged in via the extension, this credential can share the same refresh token\n * that is cached by the extension.\n */\nexport class VisualStudioCodeCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private msalClient: MsalClient | undefined;\n private options: VisualStudioCodeCredentialOptions;\n\n /**\n * Creates an instance of VisualStudioCodeCredential to use for automatically authenticating via VSCode.\n *\n * **Note**: `VisualStudioCodeCredential` is provided by a plugin package:\n * `@azure/identity-vscode`. If this package is not installed, then authentication using\n * `VisualStudioCodeCredential` will not be available.\n *\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(options?: VisualStudioCodeCredentialOptions) {\n this.options = options || {};\n\n if (options && options.tenantId) {\n checkTenantId(logger, options.tenantId);\n this.tenantId = options.tenantId;\n } else {\n this.tenantId = CommonTenantId;\n }\n\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n checkUnsupportedTenant(this.tenantId);\n }\n\n /**\n * Runs preparations for any further getToken request:\n * - Validates that the plugin is available.\n * - Loads the authentication record from VSCode if available.\n * - Creates the MSAL client with the loaded plugin and authentication record.\n */\n private async prepare(scopes: string[]): Promise<void> {\n const tenantId =\n processMultiTenantRequest(\n this.tenantId,\n this.options,\n this.additionallyAllowedTenantIds,\n logger,\n ) || this.tenantId;\n\n if (!hasVSCodePlugin() || !vsCodeAuthRecordPath) {\n throw new CredentialUnavailableError(\n \"Visual Studio Code Authentication is not available.\" +\n \" Ensure you have have Azure Resources Extension installed in VS Code,\" +\n \" signed into Azure via VS Code, installed the @azure/identity-vscode package,\" +\n \" and properly configured the extension.\",\n );\n }\n\n // Load the authentication record directly from the path\n const authenticationRecord = await this.loadAuthRecord(vsCodeAuthRecordPath, scopes);\n\n this.msalClient = createMsalClient(VSCodeClientId, tenantId, {\n ...this.options,\n isVSCodeCredential: true,\n brokerOptions: {\n enabled: true,\n parentWindowHandle: new Uint8Array(0),\n useDefaultBrokerAccount: true,\n },\n authenticationRecord,\n });\n }\n /**\n * The promise of the single preparation that will be executed at the first getToken request for an instance of this class.\n */\n private preparePromise: Promise<void> | undefined;\n\n /**\n * Runs preparations for any further getToken, but only once.\n */\n private prepareOnce(scopes: string[]): Promise<void> | undefined {\n if (!this.preparePromise) {\n this.preparePromise = this.prepare(scopes);\n }\n return this.preparePromise;\n }\n\n /**\n * Returns the token found by searching VSCode's authentication cache or\n * returns null if no token could be found.\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 public async getToken(\n scopes: string | string[],\n options?: GetTokenOptions,\n ): Promise<AccessToken> {\n // Load the plugin and authentication record only once\n const scopeArray = ensureScopes(scopes);\n await this.prepareOnce(scopeArray);\n\n if (!this.msalClient) {\n throw new CredentialUnavailableError(\n \"Visual Studio Code Authentication failed to initialize.\" +\n \" Ensure you have have Azure Resources Extension installed in VS Code,\" +\n \" signed into Azure via VS Code, installed the @azure/identity-vscode package,\" +\n \" and properly configured the extension.\",\n );\n }\n\n return this.msalClient.getTokenByInteractiveRequest(scopeArray, options || {});\n }\n\n /**\n * Loads the authentication record from the specified path.\n * @param authRecordPath - The path to the authentication record file.\n * @param scopes - The list of scopes for which the token will have access.\n * @returns The authentication record or undefined if loading fails.\n */\n private async loadAuthRecord(\n authRecordPath: string,\n scopes: string[],\n ): Promise<AuthenticationRecord> {\n try {\n const authRecordContent = await readFile(authRecordPath, { encoding: \"utf8\" });\n return deserializeAuthenticationRecord(authRecordContent);\n } catch (error: any) {\n logger.getToken.info(formatError(scopes, error));\n throw new CredentialUnavailableError(\n \"Cannot load authentication record in Visual Studio Code.\" +\n \" Ensure you have have Azure Resources Extension installed in VS Code,\" +\n \" signed into Azure via VS Code, installed the @azure/identity-vscode package,\" +\n \" and properly configured the extension.\",\n );\n }\n }\n}\n"]}
@@ -2,10 +2,6 @@ import type { MultiTenantTokenCredentialOptions } from "./multiTenantTokenCreden
2
2
  /**
3
3
  * Provides options to configure the Visual Studio Code credential.
4
4
  *
5
- * @deprecated This credential is deprecated because the VS Code Azure Account extension on which this credential
6
- * relies has been deprecated. Users should use other dev-time credentials, such as {@link AzureCliCredential},
7
- * {@link AzureDeveloperCliCredential}, or {@link AzurePowerShellCredential} for their
8
- * local development needs. See Azure Account extension deprecation notice [here](https://github.com/microsoft/vscode-azure-account/issues/964).
9
5
  */
10
6
  export interface VisualStudioCodeCredentialOptions extends MultiTenantTokenCredentialOptions {
11
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"visualStudioCodeCredentialOptions.d.ts","sourceRoot":"","sources":["../../../src/credentials/visualStudioCodeCredentialOptions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAEhG;;;;;;;GAOG;AACH,MAAM,WAAW,iCAAkC,SAAQ,iCAAiC;IAC1F;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
1
+ {"version":3,"file":"visualStudioCodeCredentialOptions.d.ts","sourceRoot":"","sources":["../../../src/credentials/visualStudioCodeCredentialOptions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAEhG;;;GAGG;AACH,MAAM,WAAW,iCAAkC,SAAQ,iCAAiC;IAC1F;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
@@ -1 +1 @@
1
- {"version":3,"file":"visualStudioCodeCredentialOptions.js","sourceRoot":"","sources":["../../../src/credentials/visualStudioCodeCredentialOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { MultiTenantTokenCredentialOptions } from \"./multiTenantTokenCredentialOptions.js\";\n\n/**\n * Provides options to configure the Visual Studio Code credential.\n *\n * @deprecated This credential is deprecated because the VS Code Azure Account extension on which this credential\n * relies has been deprecated. Users should use other dev-time credentials, such as {@link AzureCliCredential},\n * {@link AzureDeveloperCliCredential}, or {@link AzurePowerShellCredential} for their\n * local development needs. See Azure Account extension deprecation notice [here](https://github.com/microsoft/vscode-azure-account/issues/964).\n */\nexport interface VisualStudioCodeCredentialOptions extends MultiTenantTokenCredentialOptions {\n /**\n * Optionally pass in a Tenant ID to be used as part of the credential\n */\n tenantId?: string;\n}\n"]}
1
+ {"version":3,"file":"visualStudioCodeCredentialOptions.js","sourceRoot":"","sources":["../../../src/credentials/visualStudioCodeCredentialOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { MultiTenantTokenCredentialOptions } from \"./multiTenantTokenCredentialOptions.js\";\n\n/**\n * Provides options to configure the Visual Studio Code credential.\n *\n */\nexport interface VisualStudioCodeCredentialOptions extends MultiTenantTokenCredentialOptions {\n /**\n * Optionally pass in a Tenant ID to be used as part of the credential\n */\n tenantId?: string;\n}\n"]}
@@ -4,10 +4,6 @@
4
4
  * @returns an array of credentials (username and password)
5
5
  * @internal
6
6
  *
7
- * @deprecated This credential is deprecated because the VS Code Azure Account extension on which this credential
8
- * relies has been deprecated. Users should use other dev-time credentials, such as {@link AzureCliCredential},
9
- * {@link AzureDeveloperCliCredential}, or {@link AzurePowerShellCredential} for their
10
- * local development needs. See Azure Account extension deprecation notice [here](https://github.com/microsoft/vscode-azure-account/issues/964).
11
7
  */
12
8
  export type VSCodeCredentialFinder = () => Promise<Array<{
13
9
  account: string;
@@ -1 +1 @@
1
- {"version":3,"file":"visualStudioCodeCredentialPlugin.d.ts","sourceRoot":"","sources":["../../../src/credentials/visualStudioCodeCredentialPlugin.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"visualStudioCodeCredentialPlugin.d.ts","sourceRoot":"","sources":["../../../src/credentials/visualStudioCodeCredentialPlugin.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAAC"}