@azure/identity 4.10.3-alpha.20250714.3 → 4.11.0-alpha.20250718.3
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.
- package/README.md +19 -1
- package/dist/browser/client/identityClient.js +30 -18
- package/dist/browser/client/identityClient.js.map +1 -1
- package/dist/browser/constants.d.ts +1 -1
- package/dist/browser/constants.d.ts.map +1 -1
- package/dist/browser/constants.js +1 -1
- package/dist/browser/constants.js.map +1 -1
- package/dist/browser/credentials/brokerCredential.d.ts +35 -0
- package/dist/browser/credentials/brokerCredential.d.ts.map +1 -0
- package/dist/browser/credentials/brokerCredential.js +69 -0
- package/dist/browser/credentials/brokerCredential.js.map +1 -0
- package/dist/browser/credentials/chainedTokenCredential.js +1 -1
- package/dist/browser/credentials/chainedTokenCredential.js.map +1 -1
- package/dist/browser/credentials/clientSecretCredential-browser.mjs.map +1 -1
- package/dist/browser/credentials/clientSecretCredential.js +7 -2
- package/dist/browser/credentials/defaultAzureCredentialFunctions.d.ts +62 -0
- package/dist/browser/credentials/defaultAzureCredentialFunctions.d.ts.map +1 -0
- package/dist/browser/credentials/defaultAzureCredentialFunctions.js +143 -0
- package/dist/browser/credentials/defaultAzureCredentialFunctions.js.map +1 -0
- package/dist/browser/credentials/interactiveBrowserCredential-browser.mjs.map +1 -1
- package/dist/browser/credentials/interactiveBrowserCredential.js +19 -6
- package/dist/browser/credentials/managedIdentityCredential/imdsMsi.js +4 -6
- package/dist/browser/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
- package/dist/browser/credentials/managedIdentityCredential/imdsRetryPolicy.js +2 -2
- package/dist/browser/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
- package/dist/browser/credentials/managedIdentityCredential/tokenExchangeMsi.js +7 -1
- package/dist/browser/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
- package/dist/browser/credentials/usernamePasswordCredential-browser.mjs.map +1 -1
- package/dist/browser/credentials/usernamePasswordCredential.js +7 -1
- package/dist/browser/credentials/visualStudioCodeCredentialOptions.d.ts +0 -4
- package/dist/browser/credentials/visualStudioCodeCredentialOptions.d.ts.map +1 -1
- package/dist/browser/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
- package/dist/browser/credentials/visualStudioCodeCredentialPlugin.d.ts +0 -4
- package/dist/browser/credentials/visualStudioCodeCredentialPlugin.d.ts.map +1 -1
- package/dist/browser/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
- package/dist/browser/errors.js +21 -0
- package/dist/browser/errors.js.map +1 -1
- package/dist/browser/msal/browserFlows/msalBrowserCommon.js +15 -15
- package/dist/browser/msal/browserFlows/msalBrowserCommon.js.map +1 -1
- package/dist/browser/msal/nodeFlows/msalClient.d.ts +13 -0
- package/dist/browser/msal/nodeFlows/msalClient.d.ts.map +1 -1
- package/dist/browser/msal/nodeFlows/msalClient.js +127 -94
- package/dist/browser/msal/nodeFlows/msalClient.js.map +1 -1
- package/dist/browser/msal/nodeFlows/msalPlugins.d.ts +19 -1
- package/dist/browser/msal/nodeFlows/msalPlugins.d.ts.map +1 -1
- package/dist/browser/msal/nodeFlows/msalPlugins.js +61 -16
- package/dist/browser/msal/nodeFlows/msalPlugins.js.map +1 -1
- package/dist/browser/msal/utils.js +3 -4
- package/dist/browser/msal/utils.js.map +1 -1
- package/dist/browser/plugins/provider.d.ts +2 -2
- package/dist/browser/plugins/provider.d.ts.map +1 -1
- package/dist/browser/plugins/provider.js.map +1 -1
- package/dist/browser/regionalAuthority.js +1 -2
- package/dist/browser/regionalAuthority.js.map +1 -1
- package/dist/browser/tokenProvider.js +1 -2
- package/dist/browser/tokenProvider.js.map +1 -1
- package/dist/browser/util/logging.js +6 -2
- package/dist/browser/util/logging.js.map +1 -1
- package/dist/browser/util/processMultiTenantRequest-browser.mjs.map +1 -1
- package/dist/browser/util/processMultiTenantRequest.js +1 -2
- package/dist/browser/util/processUtils.d.ts +1 -1
- package/dist/browser/util/processUtils.d.ts.map +1 -1
- package/dist/browser/util/processUtils.js +1 -1
- package/dist/browser/util/processUtils.js.map +1 -1
- package/dist/commonjs/client/identityClient.js +30 -18
- package/dist/commonjs/client/identityClient.js.map +1 -1
- package/dist/commonjs/constants.d.ts +1 -1
- package/dist/commonjs/constants.d.ts.map +1 -1
- package/dist/commonjs/constants.js +1 -1
- package/dist/commonjs/constants.js.map +1 -1
- package/dist/commonjs/credentials/authorizationCodeCredential.js +17 -3
- package/dist/commonjs/credentials/authorizationCodeCredential.js.map +1 -1
- package/dist/commonjs/credentials/azureCliCredential.js +15 -12
- package/dist/commonjs/credentials/azureCliCredential.js.map +1 -1
- package/dist/commonjs/credentials/azureDeveloperCliCredential.js +12 -10
- package/dist/commonjs/credentials/azureDeveloperCliCredential.js.map +1 -1
- package/dist/commonjs/credentials/azurePipelinesCredential.js +9 -5
- package/dist/commonjs/credentials/azurePipelinesCredential.js.map +1 -1
- package/dist/commonjs/credentials/azurePowerShellCredential.js +10 -7
- package/dist/commonjs/credentials/azurePowerShellCredential.js.map +1 -1
- package/dist/commonjs/credentials/brokerCredential.d.ts +35 -0
- package/dist/commonjs/credentials/brokerCredential.d.ts.map +1 -0
- package/dist/commonjs/credentials/brokerCredential.js +73 -0
- package/dist/commonjs/credentials/brokerCredential.js.map +1 -0
- package/dist/commonjs/credentials/chainedTokenCredential.js +1 -1
- package/dist/commonjs/credentials/chainedTokenCredential.js.map +1 -1
- package/dist/commonjs/credentials/clientAssertionCredential.js +11 -2
- package/dist/commonjs/credentials/clientAssertionCredential.js.map +1 -1
- package/dist/commonjs/credentials/clientCertificateCredential.js +19 -9
- package/dist/commonjs/credentials/clientCertificateCredential.js.map +1 -1
- package/dist/commonjs/credentials/clientSecretCredential.js +10 -2
- package/dist/commonjs/credentials/clientSecretCredential.js.map +1 -1
- package/dist/commonjs/credentials/defaultAzureCredential.d.ts +12 -14
- package/dist/commonjs/credentials/defaultAzureCredential.d.ts.map +1 -1
- package/dist/commonjs/credentials/defaultAzureCredential.js +48 -113
- package/dist/commonjs/credentials/defaultAzureCredential.js.map +1 -1
- package/dist/commonjs/credentials/defaultAzureCredentialFunctions.d.ts +62 -0
- package/dist/commonjs/credentials/defaultAzureCredentialFunctions.d.ts.map +1 -0
- package/dist/commonjs/credentials/defaultAzureCredentialFunctions.js +153 -0
- package/dist/commonjs/credentials/defaultAzureCredentialFunctions.js.map +1 -0
- package/dist/commonjs/credentials/deviceCodeCredential.js +24 -10
- package/dist/commonjs/credentials/deviceCodeCredential.js.map +1 -1
- package/dist/commonjs/credentials/environmentCredential.js +4 -6
- package/dist/commonjs/credentials/environmentCredential.js.map +1 -1
- package/dist/commonjs/credentials/interactiveBrowserCredential.js +30 -11
- package/dist/commonjs/credentials/interactiveBrowserCredential.js.map +1 -1
- package/dist/commonjs/credentials/managedIdentityCredential/imdsMsi.js +4 -6
- package/dist/commonjs/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
- package/dist/commonjs/credentials/managedIdentityCredential/imdsRetryPolicy.js +2 -2
- package/dist/commonjs/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
- package/dist/commonjs/credentials/managedIdentityCredential/index.js +28 -18
- package/dist/commonjs/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist/commonjs/credentials/managedIdentityCredential/tokenExchangeMsi.js +7 -1
- package/dist/commonjs/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
- package/dist/commonjs/credentials/onBehalfOfCredential.js +13 -1
- package/dist/commonjs/credentials/onBehalfOfCredential.js.map +1 -1
- package/dist/commonjs/credentials/usernamePasswordCredential.js +10 -2
- package/dist/commonjs/credentials/usernamePasswordCredential.js.map +1 -1
- package/dist/commonjs/credentials/visualStudioCodeCredential.d.ts +15 -26
- package/dist/commonjs/credentials/visualStudioCodeCredential.d.ts.map +1 -1
- package/dist/commonjs/credentials/visualStudioCodeCredential.js +69 -130
- package/dist/commonjs/credentials/visualStudioCodeCredential.js.map +1 -1
- package/dist/commonjs/credentials/visualStudioCodeCredentialOptions.d.ts +0 -4
- package/dist/commonjs/credentials/visualStudioCodeCredentialOptions.d.ts.map +1 -1
- package/dist/commonjs/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
- package/dist/commonjs/credentials/visualStudioCodeCredentialPlugin.d.ts +0 -4
- package/dist/commonjs/credentials/visualStudioCodeCredentialPlugin.d.ts.map +1 -1
- package/dist/commonjs/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
- package/dist/commonjs/credentials/workloadIdentityCredential.js +5 -3
- package/dist/commonjs/credentials/workloadIdentityCredential.js.map +1 -1
- package/dist/commonjs/errors.js +21 -0
- package/dist/commonjs/errors.js.map +1 -1
- package/dist/commonjs/msal/browserFlows/msalBrowserCommon.js +15 -15
- package/dist/commonjs/msal/browserFlows/msalBrowserCommon.js.map +1 -1
- package/dist/commonjs/msal/nodeFlows/msalClient.d.ts +13 -0
- package/dist/commonjs/msal/nodeFlows/msalClient.d.ts.map +1 -1
- package/dist/commonjs/msal/nodeFlows/msalClient.js +127 -94
- package/dist/commonjs/msal/nodeFlows/msalClient.js.map +1 -1
- package/dist/commonjs/msal/nodeFlows/msalPlugins.d.ts +19 -1
- package/dist/commonjs/msal/nodeFlows/msalPlugins.d.ts.map +1 -1
- package/dist/commonjs/msal/nodeFlows/msalPlugins.js +63 -17
- package/dist/commonjs/msal/nodeFlows/msalPlugins.js.map +1 -1
- package/dist/commonjs/msal/utils.js +3 -4
- package/dist/commonjs/msal/utils.js.map +1 -1
- package/dist/commonjs/plugins/consumer.d.ts.map +1 -1
- package/dist/commonjs/plugins/consumer.js +1 -2
- package/dist/commonjs/plugins/consumer.js.map +1 -1
- package/dist/commonjs/plugins/provider.d.ts +2 -2
- package/dist/commonjs/plugins/provider.d.ts.map +1 -1
- package/dist/commonjs/plugins/provider.js.map +1 -1
- package/dist/commonjs/regionalAuthority.js +1 -2
- package/dist/commonjs/regionalAuthority.js.map +1 -1
- package/dist/commonjs/tokenProvider.js +1 -2
- package/dist/commonjs/tokenProvider.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/commonjs/util/logging.js +6 -2
- package/dist/commonjs/util/logging.js.map +1 -1
- package/dist/commonjs/util/processMultiTenantRequest.js +2 -3
- package/dist/commonjs/util/processMultiTenantRequest.js.map +1 -1
- package/dist/commonjs/util/processUtils.d.ts +1 -1
- package/dist/commonjs/util/processUtils.d.ts.map +1 -1
- package/dist/commonjs/util/processUtils.js +2 -2
- package/dist/commonjs/util/processUtils.js.map +1 -1
- package/dist/esm/client/identityClient.js +30 -18
- package/dist/esm/client/identityClient.js.map +1 -1
- package/dist/esm/constants.d.ts +1 -1
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/credentials/authorizationCodeCredential.js +17 -3
- package/dist/esm/credentials/authorizationCodeCredential.js.map +1 -1
- package/dist/esm/credentials/azureCliCredential.js +15 -12
- package/dist/esm/credentials/azureCliCredential.js.map +1 -1
- package/dist/esm/credentials/azureDeveloperCliCredential.js +12 -10
- package/dist/esm/credentials/azureDeveloperCliCredential.js.map +1 -1
- package/dist/esm/credentials/azurePipelinesCredential.js +9 -5
- package/dist/esm/credentials/azurePipelinesCredential.js.map +1 -1
- package/dist/esm/credentials/azurePowerShellCredential.js +10 -7
- package/dist/esm/credentials/azurePowerShellCredential.js.map +1 -1
- package/dist/esm/credentials/brokerCredential.d.ts +35 -0
- package/dist/esm/credentials/brokerCredential.d.ts.map +1 -0
- package/dist/esm/credentials/brokerCredential.js +69 -0
- package/dist/esm/credentials/brokerCredential.js.map +1 -0
- package/dist/esm/credentials/chainedTokenCredential.js +1 -1
- package/dist/esm/credentials/chainedTokenCredential.js.map +1 -1
- package/dist/esm/credentials/clientAssertionCredential.js +11 -2
- package/dist/esm/credentials/clientAssertionCredential.js.map +1 -1
- package/dist/esm/credentials/clientCertificateCredential.js +19 -9
- package/dist/esm/credentials/clientCertificateCredential.js.map +1 -1
- package/dist/esm/credentials/clientSecretCredential.js +10 -2
- package/dist/esm/credentials/clientSecretCredential.js.map +1 -1
- package/dist/esm/credentials/defaultAzureCredential.d.ts +12 -14
- package/dist/esm/credentials/defaultAzureCredential.d.ts.map +1 -1
- package/dist/esm/credentials/defaultAzureCredential.js +43 -106
- package/dist/esm/credentials/defaultAzureCredential.js.map +1 -1
- package/dist/esm/credentials/defaultAzureCredentialFunctions.d.ts +62 -0
- package/dist/esm/credentials/defaultAzureCredentialFunctions.d.ts.map +1 -0
- package/dist/esm/credentials/defaultAzureCredentialFunctions.js +143 -0
- package/dist/esm/credentials/defaultAzureCredentialFunctions.js.map +1 -0
- package/dist/esm/credentials/deviceCodeCredential.js +24 -10
- package/dist/esm/credentials/deviceCodeCredential.js.map +1 -1
- package/dist/esm/credentials/environmentCredential.js +4 -6
- package/dist/esm/credentials/environmentCredential.js.map +1 -1
- package/dist/esm/credentials/interactiveBrowserCredential.js +30 -11
- package/dist/esm/credentials/interactiveBrowserCredential.js.map +1 -1
- package/dist/esm/credentials/managedIdentityCredential/imdsMsi.js +4 -6
- package/dist/esm/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
- package/dist/esm/credentials/managedIdentityCredential/imdsRetryPolicy.js +2 -2
- package/dist/esm/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
- package/dist/esm/credentials/managedIdentityCredential/index.js +28 -18
- package/dist/esm/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist/esm/credentials/managedIdentityCredential/tokenExchangeMsi.js +7 -1
- package/dist/esm/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
- package/dist/esm/credentials/onBehalfOfCredential.js +13 -1
- package/dist/esm/credentials/onBehalfOfCredential.js.map +1 -1
- package/dist/esm/credentials/usernamePasswordCredential.js +10 -2
- package/dist/esm/credentials/usernamePasswordCredential.js.map +1 -1
- package/dist/esm/credentials/visualStudioCodeCredential.d.ts +15 -26
- package/dist/esm/credentials/visualStudioCodeCredential.d.ts.map +1 -1
- package/dist/esm/credentials/visualStudioCodeCredential.js +69 -128
- package/dist/esm/credentials/visualStudioCodeCredential.js.map +1 -1
- package/dist/esm/credentials/visualStudioCodeCredentialOptions.d.ts +0 -4
- package/dist/esm/credentials/visualStudioCodeCredentialOptions.d.ts.map +1 -1
- package/dist/esm/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
- package/dist/esm/credentials/visualStudioCodeCredentialPlugin.d.ts +0 -4
- package/dist/esm/credentials/visualStudioCodeCredentialPlugin.d.ts.map +1 -1
- package/dist/esm/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
- package/dist/esm/credentials/workloadIdentityCredential.js +5 -3
- package/dist/esm/credentials/workloadIdentityCredential.js.map +1 -1
- package/dist/esm/errors.js +21 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/msal/browserFlows/msalBrowserCommon.js +15 -15
- package/dist/esm/msal/browserFlows/msalBrowserCommon.js.map +1 -1
- package/dist/esm/msal/nodeFlows/msalClient.d.ts +13 -0
- package/dist/esm/msal/nodeFlows/msalClient.d.ts.map +1 -1
- package/dist/esm/msal/nodeFlows/msalClient.js +127 -94
- package/dist/esm/msal/nodeFlows/msalClient.js.map +1 -1
- package/dist/esm/msal/nodeFlows/msalPlugins.d.ts +19 -1
- package/dist/esm/msal/nodeFlows/msalPlugins.d.ts.map +1 -1
- package/dist/esm/msal/nodeFlows/msalPlugins.js +61 -16
- package/dist/esm/msal/nodeFlows/msalPlugins.js.map +1 -1
- package/dist/esm/msal/utils.js +3 -4
- package/dist/esm/msal/utils.js.map +1 -1
- package/dist/esm/plugins/consumer.d.ts.map +1 -1
- package/dist/esm/plugins/consumer.js +2 -3
- package/dist/esm/plugins/consumer.js.map +1 -1
- package/dist/esm/plugins/provider.d.ts +2 -2
- package/dist/esm/plugins/provider.d.ts.map +1 -1
- package/dist/esm/plugins/provider.js.map +1 -1
- package/dist/esm/regionalAuthority.js +1 -2
- package/dist/esm/regionalAuthority.js.map +1 -1
- package/dist/esm/tokenProvider.js +1 -2
- package/dist/esm/tokenProvider.js.map +1 -1
- package/dist/esm/util/logging.js +6 -2
- package/dist/esm/util/logging.js.map +1 -1
- package/dist/esm/util/processMultiTenantRequest.js +2 -3
- package/dist/esm/util/processMultiTenantRequest.js.map +1 -1
- package/dist/esm/util/processUtils.d.ts +1 -1
- package/dist/esm/util/processUtils.d.ts.map +1 -1
- package/dist/esm/util/processUtils.js +1 -1
- package/dist/esm/util/processUtils.js.map +1 -1
- package/dist/workerd/client/identityClient.js +30 -18
- package/dist/workerd/client/identityClient.js.map +1 -1
- package/dist/workerd/constants.d.ts +1 -1
- package/dist/workerd/constants.d.ts.map +1 -1
- package/dist/workerd/constants.js +1 -1
- package/dist/workerd/constants.js.map +1 -1
- package/dist/workerd/credentials/authorizationCodeCredential.js +17 -3
- package/dist/workerd/credentials/authorizationCodeCredential.js.map +1 -1
- package/dist/workerd/credentials/azureCliCredential.js +15 -12
- package/dist/workerd/credentials/azureCliCredential.js.map +1 -1
- package/dist/workerd/credentials/azureDeveloperCliCredential.js +12 -10
- package/dist/workerd/credentials/azureDeveloperCliCredential.js.map +1 -1
- package/dist/workerd/credentials/azurePipelinesCredential.js +9 -5
- package/dist/workerd/credentials/azurePipelinesCredential.js.map +1 -1
- package/dist/workerd/credentials/azurePowerShellCredential.js +10 -7
- package/dist/workerd/credentials/azurePowerShellCredential.js.map +1 -1
- package/dist/workerd/credentials/brokerCredential.d.ts +35 -0
- package/dist/workerd/credentials/brokerCredential.d.ts.map +1 -0
- package/dist/workerd/credentials/brokerCredential.js +69 -0
- package/dist/workerd/credentials/brokerCredential.js.map +1 -0
- package/dist/workerd/credentials/chainedTokenCredential.js +1 -1
- package/dist/workerd/credentials/chainedTokenCredential.js.map +1 -1
- package/dist/workerd/credentials/clientAssertionCredential.js +11 -2
- package/dist/workerd/credentials/clientAssertionCredential.js.map +1 -1
- package/dist/workerd/credentials/clientCertificateCredential.js +19 -9
- package/dist/workerd/credentials/clientCertificateCredential.js.map +1 -1
- package/dist/workerd/credentials/clientSecretCredential.js +10 -2
- package/dist/workerd/credentials/clientSecretCredential.js.map +1 -1
- package/dist/workerd/credentials/defaultAzureCredential.d.ts +12 -14
- package/dist/workerd/credentials/defaultAzureCredential.d.ts.map +1 -1
- package/dist/workerd/credentials/defaultAzureCredential.js +43 -106
- package/dist/workerd/credentials/defaultAzureCredential.js.map +1 -1
- package/dist/workerd/credentials/defaultAzureCredentialFunctions.d.ts +62 -0
- package/dist/workerd/credentials/defaultAzureCredentialFunctions.d.ts.map +1 -0
- package/dist/workerd/credentials/defaultAzureCredentialFunctions.js +143 -0
- package/dist/workerd/credentials/defaultAzureCredentialFunctions.js.map +1 -0
- package/dist/workerd/credentials/deviceCodeCredential.js +24 -10
- package/dist/workerd/credentials/deviceCodeCredential.js.map +1 -1
- package/dist/workerd/credentials/environmentCredential.js +4 -6
- package/dist/workerd/credentials/environmentCredential.js.map +1 -1
- package/dist/workerd/credentials/interactiveBrowserCredential.js +30 -11
- package/dist/workerd/credentials/interactiveBrowserCredential.js.map +1 -1
- package/dist/workerd/credentials/managedIdentityCredential/imdsMsi.js +4 -6
- package/dist/workerd/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
- package/dist/workerd/credentials/managedIdentityCredential/imdsRetryPolicy.js +2 -2
- package/dist/workerd/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
- package/dist/workerd/credentials/managedIdentityCredential/index.js +28 -18
- package/dist/workerd/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist/workerd/credentials/managedIdentityCredential/tokenExchangeMsi.js +7 -1
- package/dist/workerd/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
- package/dist/workerd/credentials/onBehalfOfCredential.js +13 -1
- package/dist/workerd/credentials/onBehalfOfCredential.js.map +1 -1
- package/dist/workerd/credentials/usernamePasswordCredential.js +10 -2
- package/dist/workerd/credentials/usernamePasswordCredential.js.map +1 -1
- package/dist/workerd/credentials/visualStudioCodeCredential.d.ts +15 -26
- package/dist/workerd/credentials/visualStudioCodeCredential.d.ts.map +1 -1
- package/dist/workerd/credentials/visualStudioCodeCredential.js +69 -128
- package/dist/workerd/credentials/visualStudioCodeCredential.js.map +1 -1
- package/dist/workerd/credentials/visualStudioCodeCredentialOptions.d.ts +0 -4
- package/dist/workerd/credentials/visualStudioCodeCredentialOptions.d.ts.map +1 -1
- package/dist/workerd/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
- package/dist/workerd/credentials/visualStudioCodeCredentialPlugin.d.ts +0 -4
- package/dist/workerd/credentials/visualStudioCodeCredentialPlugin.d.ts.map +1 -1
- package/dist/workerd/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
- package/dist/workerd/credentials/workloadIdentityCredential.js +5 -3
- package/dist/workerd/credentials/workloadIdentityCredential.js.map +1 -1
- package/dist/workerd/errors.js +21 -0
- package/dist/workerd/errors.js.map +1 -1
- package/dist/workerd/msal/browserFlows/msalBrowserCommon.js +15 -15
- package/dist/workerd/msal/browserFlows/msalBrowserCommon.js.map +1 -1
- package/dist/workerd/msal/nodeFlows/msalClient.d.ts +13 -0
- package/dist/workerd/msal/nodeFlows/msalClient.d.ts.map +1 -1
- package/dist/workerd/msal/nodeFlows/msalClient.js +127 -94
- package/dist/workerd/msal/nodeFlows/msalClient.js.map +1 -1
- package/dist/workerd/msal/nodeFlows/msalPlugins.d.ts +19 -1
- package/dist/workerd/msal/nodeFlows/msalPlugins.d.ts.map +1 -1
- package/dist/workerd/msal/nodeFlows/msalPlugins.js +61 -16
- package/dist/workerd/msal/nodeFlows/msalPlugins.js.map +1 -1
- package/dist/workerd/msal/utils.js +3 -4
- package/dist/workerd/msal/utils.js.map +1 -1
- package/dist/workerd/plugins/consumer.d.ts.map +1 -1
- package/dist/workerd/plugins/consumer.js +2 -3
- package/dist/workerd/plugins/consumer.js.map +1 -1
- package/dist/workerd/plugins/provider.d.ts +2 -2
- package/dist/workerd/plugins/provider.d.ts.map +1 -1
- package/dist/workerd/plugins/provider.js.map +1 -1
- package/dist/workerd/regionalAuthority.js +1 -2
- package/dist/workerd/regionalAuthority.js.map +1 -1
- package/dist/workerd/tokenProvider.js +1 -2
- package/dist/workerd/tokenProvider.js.map +1 -1
- package/dist/workerd/util/logging.js +6 -2
- package/dist/workerd/util/logging.js.map +1 -1
- package/dist/workerd/util/processMultiTenantRequest.js +2 -3
- package/dist/workerd/util/processMultiTenantRequest.js.map +1 -1
- package/dist/workerd/util/processUtils.d.ts +1 -1
- package/dist/workerd/util/processUtils.d.ts.map +1 -1
- package/dist/workerd/util/processUtils.js +1 -1
- package/dist/workerd/util/processUtils.js.map +1 -1
- package/package.json +2 -2
@@ -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
|
-
*
|
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
|
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
|
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;
|
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"}
|
@@ -2,27 +2,19 @@
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
3
3
|
// Licensed under the MIT License.
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
5
|
-
exports.VisualStudioCodeCredential =
|
6
|
-
exports.getPropertyFromVSCode = getPropertyFromVSCode;
|
7
|
-
const tslib_1 = require("tslib");
|
5
|
+
exports.VisualStudioCodeCredential = void 0;
|
8
6
|
const logging_js_1 = require("../util/logging.js");
|
9
7
|
const tenantIdUtils_js_1 = require("../util/tenantIdUtils.js");
|
10
|
-
const constants_js_1 = require("../constants.js");
|
11
8
|
const errors_js_1 = require("../errors.js");
|
12
|
-
const identityClient_js_1 = require("../client/identityClient.js");
|
13
9
|
const tenantIdUtils_js_2 = require("../util/tenantIdUtils.js");
|
14
|
-
const
|
15
|
-
const
|
16
|
-
const
|
10
|
+
const msalClient_js_1 = require("../msal/nodeFlows/msalClient.js");
|
11
|
+
const scopeUtils_js_1 = require("../util/scopeUtils.js");
|
12
|
+
const msalPlugins_js_1 = require("../msal/nodeFlows/msalPlugins.js");
|
13
|
+
const utils_js_1 = require("../msal/utils.js");
|
14
|
+
const promises_1 = require("node:fs/promises");
|
17
15
|
const CommonTenantId = "common";
|
18
|
-
const
|
16
|
+
const VSCodeClientId = "aebc6443-996d-45c2-90f0-388ff96faa56";
|
19
17
|
const logger = (0, logging_js_1.credentialLogger)("VisualStudioCodeCredential");
|
20
|
-
let findCredentials = undefined;
|
21
|
-
exports.vsCodeCredentialControl = {
|
22
|
-
setVsCodeCredentialFinder(finder) {
|
23
|
-
findCredentials = finder;
|
24
|
-
},
|
25
|
-
};
|
26
18
|
// Map of unsupported Tenant IDs and the errors we will be throwing.
|
27
19
|
const unsupportedTenantIds = {
|
28
20
|
adfs: "The VisualStudioCodeCredential does not support authentication with ADFS tenants.",
|
@@ -34,79 +26,27 @@ function checkUnsupportedTenant(tenantId) {
|
|
34
26
|
throw new errors_js_1.CredentialUnavailableError(unsupportedTenantError);
|
35
27
|
}
|
36
28
|
}
|
37
|
-
const mapVSCodeAuthorityHosts = {
|
38
|
-
AzureCloud: constants_js_1.AzureAuthorityHosts.AzurePublicCloud,
|
39
|
-
AzureChina: constants_js_1.AzureAuthorityHosts.AzureChina,
|
40
|
-
AzureGermanCloud: constants_js_1.AzureAuthorityHosts.AzureGermany,
|
41
|
-
AzureUSGovernment: constants_js_1.AzureAuthorityHosts.AzureGovernment,
|
42
|
-
};
|
43
|
-
/**
|
44
|
-
* Attempts to load a specific property from the VSCode configurations of the current OS.
|
45
|
-
* If it fails at any point, returns undefined.
|
46
|
-
*/
|
47
|
-
function getPropertyFromVSCode(property) {
|
48
|
-
const settingsPath = ["User", "settings.json"];
|
49
|
-
// Eventually we can add more folders for more versions of VSCode.
|
50
|
-
const vsCodeFolder = "Code";
|
51
|
-
const homedir = node_os_1.default.homedir();
|
52
|
-
function loadProperty(...pathSegments) {
|
53
|
-
const fullPath = node_path_1.default.join(...pathSegments, vsCodeFolder, ...settingsPath);
|
54
|
-
const settings = JSON.parse(node_fs_1.default.readFileSync(fullPath, { encoding: "utf8" }));
|
55
|
-
return settings[property];
|
56
|
-
}
|
57
|
-
try {
|
58
|
-
let appData;
|
59
|
-
switch (process.platform) {
|
60
|
-
case "win32":
|
61
|
-
appData = process.env.APPDATA;
|
62
|
-
return appData ? loadProperty(appData) : undefined;
|
63
|
-
case "darwin":
|
64
|
-
return loadProperty(homedir, "Library", "Application Support");
|
65
|
-
case "linux":
|
66
|
-
return loadProperty(homedir, ".config");
|
67
|
-
default:
|
68
|
-
return;
|
69
|
-
}
|
70
|
-
}
|
71
|
-
catch (e) {
|
72
|
-
logger.info(`Failed to load the Visual Studio Code configuration file. Error: ${e.message}`);
|
73
|
-
return;
|
74
|
-
}
|
75
|
-
}
|
76
29
|
/**
|
77
|
-
* Connects to Azure using the
|
30
|
+
* Connects to Azure using the user account signed in through the Azure Resources extension in Visual Studio Code.
|
78
31
|
* Once the user has logged in via the extension, this credential can share the same refresh token
|
79
32
|
* that is cached by the extension.
|
80
|
-
*
|
81
|
-
* It's a [known issue](https://github.com/Azure/azure-sdk-for-js/issues/20500) that this credential doesn't
|
82
|
-
* work with [Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account)
|
83
|
-
* versions newer than **0.9.11**. A long-term fix to this problem is in progress. In the meantime, consider
|
84
|
-
* authenticating with {@link AzureCliCredential}.
|
85
|
-
*
|
86
|
-
* @deprecated This credential is deprecated because the VS Code Azure Account extension on which this credential
|
87
|
-
* relies has been deprecated. Users should use other dev-time credentials, such as {@link AzureCliCredential},
|
88
|
-
* {@link AzureDeveloperCliCredential}, or {@link AzurePowerShellCredential} for their
|
89
|
-
* local development needs. See Azure Account extension deprecation notice [here](https://github.com/microsoft/vscode-azure-account/issues/964).
|
90
|
-
*
|
91
33
|
*/
|
92
34
|
class VisualStudioCodeCredential {
|
35
|
+
tenantId;
|
36
|
+
additionallyAllowedTenantIds;
|
37
|
+
msalClient;
|
38
|
+
options;
|
93
39
|
/**
|
94
40
|
* Creates an instance of VisualStudioCodeCredential to use for automatically authenticating via VSCode.
|
95
41
|
*
|
96
42
|
* **Note**: `VisualStudioCodeCredential` is provided by a plugin package:
|
97
|
-
* `@azure/identity-vscode`. If this package is not installed
|
98
|
-
* using the plugin API (`useIdentityPlugin`), then authentication using
|
43
|
+
* `@azure/identity-vscode`. If this package is not installed, then authentication using
|
99
44
|
* `VisualStudioCodeCredential` will not be available.
|
100
45
|
*
|
101
46
|
* @param options - Options for configuring the client which makes the authentication request.
|
102
47
|
*/
|
103
48
|
constructor(options) {
|
104
|
-
|
105
|
-
// Or just `AzureCloud` by default.
|
106
|
-
this.cloudName = (getPropertyFromVSCode("azure.cloud") || "AzureCloud");
|
107
|
-
// Picking an authority host based on the cloud name.
|
108
|
-
const authorityHost = mapVSCodeAuthorityHosts[this.cloudName];
|
109
|
-
this.identityClient = new identityClient_js_1.IdentityClient(Object.assign({ authorityHost }, options));
|
49
|
+
this.options = options || {};
|
110
50
|
if (options && options.tenantId) {
|
111
51
|
(0, tenantIdUtils_js_2.checkTenantId)(logger, options.tenantId);
|
112
52
|
this.tenantId = options.tenantId;
|
@@ -114,26 +54,46 @@ class VisualStudioCodeCredential {
|
|
114
54
|
else {
|
115
55
|
this.tenantId = CommonTenantId;
|
116
56
|
}
|
117
|
-
this.additionallyAllowedTenantIds = (0, tenantIdUtils_js_1.resolveAdditionallyAllowedTenantIds)(options
|
57
|
+
this.additionallyAllowedTenantIds = (0, tenantIdUtils_js_1.resolveAdditionallyAllowedTenantIds)(options?.additionallyAllowedTenants);
|
118
58
|
checkUnsupportedTenant(this.tenantId);
|
119
59
|
}
|
120
60
|
/**
|
121
|
-
* Runs preparations for any further getToken request
|
61
|
+
* Runs preparations for any further getToken request:
|
62
|
+
* - Validates that the plugin is available.
|
63
|
+
* - Loads the authentication record from VSCode if available.
|
64
|
+
* - Creates the MSAL client with the loaded plugin and authentication record.
|
122
65
|
*/
|
123
|
-
async prepare() {
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
66
|
+
async prepare(scopes) {
|
67
|
+
const tenantId = (0, tenantIdUtils_js_1.processMultiTenantRequest)(this.tenantId, this.options, this.additionallyAllowedTenantIds, logger) || this.tenantId;
|
68
|
+
if (!(0, msalPlugins_js_1.hasVSCodePlugin)() || !msalPlugins_js_1.vsCodeAuthRecordPath) {
|
69
|
+
throw new errors_js_1.CredentialUnavailableError("Visual Studio Code Authentication is not available." +
|
70
|
+
" Ensure you have have Azure Resources Extension installed in VS Code," +
|
71
|
+
" signed into Azure via VS Code, installed the @azure/identity-vscode package," +
|
72
|
+
" and properly configured the extension.");
|
128
73
|
}
|
129
|
-
|
74
|
+
// Load the authentication record directly from the path
|
75
|
+
const authenticationRecord = await this.loadAuthRecord(msalPlugins_js_1.vsCodeAuthRecordPath, scopes);
|
76
|
+
this.msalClient = (0, msalClient_js_1.createMsalClient)(VSCodeClientId, tenantId, {
|
77
|
+
...this.options,
|
78
|
+
isVSCodeCredential: true,
|
79
|
+
brokerOptions: {
|
80
|
+
enabled: true,
|
81
|
+
parentWindowHandle: new Uint8Array(0),
|
82
|
+
useDefaultBrokerAccount: true,
|
83
|
+
},
|
84
|
+
authenticationRecord,
|
85
|
+
});
|
130
86
|
}
|
87
|
+
/**
|
88
|
+
* The promise of the single preparation that will be executed at the first getToken request for an instance of this class.
|
89
|
+
*/
|
90
|
+
preparePromise;
|
131
91
|
/**
|
132
92
|
* Runs preparations for any further getToken, but only once.
|
133
93
|
*/
|
134
|
-
prepareOnce() {
|
94
|
+
prepareOnce(scopes) {
|
135
95
|
if (!this.preparePromise) {
|
136
|
-
this.preparePromise = this.prepare();
|
96
|
+
this.preparePromise = this.prepare(scopes);
|
137
97
|
}
|
138
98
|
return this.preparePromise;
|
139
99
|
}
|
@@ -146,55 +106,34 @@ class VisualStudioCodeCredential {
|
|
146
106
|
* `TokenCredential` implementation might make.
|
147
107
|
*/
|
148
108
|
async getToken(scopes, options) {
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
if (
|
153
|
-
throw new errors_js_1.CredentialUnavailableError(
|
154
|
-
"
|
155
|
-
"
|
156
|
-
"and
|
157
|
-
"`useIdentityPlugin(vsCodePlugin)` before creating a `VisualStudioCodeCredential`.",
|
158
|
-
"To troubleshoot, visit https://aka.ms/azsdk/js/identity/vscodecredential/troubleshoot.",
|
159
|
-
].join(" "));
|
160
|
-
}
|
161
|
-
let scopeString = typeof scopes === "string" ? scopes : scopes.join(" ");
|
162
|
-
// Check to make sure the scope we get back is a valid scope
|
163
|
-
if (!scopeString.match(/^[0-9a-zA-Z-.:/]+$/)) {
|
164
|
-
const error = new Error("Invalid scope was specified by the user or calling client");
|
165
|
-
logger.getToken.info((0, logging_js_1.formatError)(scopes, error));
|
166
|
-
throw error;
|
167
|
-
}
|
168
|
-
if (scopeString.indexOf("offline_access") < 0) {
|
169
|
-
scopeString += " offline_access";
|
109
|
+
// Load the plugin and authentication record only once
|
110
|
+
const scopeArray = (0, scopeUtils_js_1.ensureScopes)(scopes);
|
111
|
+
await this.prepareOnce(scopeArray);
|
112
|
+
if (!this.msalClient) {
|
113
|
+
throw new errors_js_1.CredentialUnavailableError("Visual Studio Code Authentication failed to initialize." +
|
114
|
+
" Ensure you have have Azure Resources Extension installed in VS Code," +
|
115
|
+
" signed into Azure via VS Code, installed the @azure/identity-vscode package," +
|
116
|
+
" and properly configured the extension.");
|
170
117
|
}
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
const tokenResponse = await this.identityClient.refreshAccessToken(tenantId, AzureAccountClientId, scopeString, refreshToken, undefined);
|
184
|
-
if (tokenResponse) {
|
185
|
-
logger.getToken.info((0, logging_js_1.formatSuccess)(scopes));
|
186
|
-
return tokenResponse.accessToken;
|
187
|
-
}
|
188
|
-
else {
|
189
|
-
const error = new errors_js_1.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.");
|
190
|
-
logger.getToken.info((0, logging_js_1.formatError)(scopes, error));
|
191
|
-
throw error;
|
192
|
-
}
|
118
|
+
return this.msalClient.getTokenByInteractiveRequest(scopeArray, options || {});
|
119
|
+
}
|
120
|
+
/**
|
121
|
+
* Loads the authentication record from the specified path.
|
122
|
+
* @param authRecordPath - The path to the authentication record file.
|
123
|
+
* @param scopes - The list of scopes for which the token will have access.
|
124
|
+
* @returns The authentication record or undefined if loading fails.
|
125
|
+
*/
|
126
|
+
async loadAuthRecord(authRecordPath, scopes) {
|
127
|
+
try {
|
128
|
+
const authRecordContent = await (0, promises_1.readFile)(authRecordPath, { encoding: "utf8" });
|
129
|
+
return (0, utils_js_1.deserializeAuthenticationRecord)(authRecordContent);
|
193
130
|
}
|
194
|
-
|
195
|
-
const error = new errors_js_1.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.");
|
131
|
+
catch (error) {
|
196
132
|
logger.getToken.info((0, logging_js_1.formatError)(scopes, error));
|
197
|
-
throw
|
133
|
+
throw new errors_js_1.CredentialUnavailableError("Cannot load authentication record in Visual Studio Code." +
|
134
|
+
" Ensure you have have Azure Resources Extension installed in VS Code," +
|
135
|
+
" signed into Azure via VS Code, installed the @azure/identity-vscode package," +
|
136
|
+
" and properly configured the extension.");
|
198
137
|
}
|
199
138
|
}
|
200
139
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"visualStudioCodeCredential.js","sourceRoot":"","sources":["../../../src/credentials/visualStudioCodeCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAwDlC,sDA6BC;;AAlFD,mDAAkF;AAClF,+DAGkC;AAClC,kDAAsD;AACtD,4CAA0D;AAC1D,mEAA6D;AAG7D,+DAAyD;AACzD,8DAAyB;AACzB,8DAAyB;AACzB,kEAA6B;AAE7B,MAAM,cAAc,GAAG,QAAQ,CAAC;AAChC,MAAM,oBAAoB,GAAG,sCAAsC,CAAC,CAAC,8CAA8C;AACnH,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,4BAA4B,CAAC,CAAC;AAE9D,IAAI,eAAe,GAAuC,SAAS,CAAC;AAEvD,QAAA,uBAAuB,GAAG;IACrC,yBAAyB,CAAC,MAA8B;QACtD,eAAe,GAAG,MAAM,CAAC;IAC3B,CAAC;CACF,CAAC;AAEF,oEAAoE;AACpE,MAAM,oBAAoB,GAA2B;IACnD,IAAI,EAAE,mFAAmF;CAC1F,CAAC;AAEF,SAAS,sBAAsB,CAAC,QAAgB;IAC9C,8CAA8C;IAC9C,MAAM,sBAAsB,GAAG,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC9D,IAAI,sBAAsB,EAAE,CAAC;QAC3B,MAAM,IAAI,sCAA0B,CAAC,sBAAsB,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC;AAID,MAAM,uBAAuB,GAAqC;IAChE,UAAU,EAAE,kCAAmB,CAAC,gBA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C,yFAAyF;QACzF,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,GAC9B,MAAA,MAAA,WAAW,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,IAAA,0BAAa,EAAC,MAAM,CAAC,CAAC,CAAC;gBAC5C,OAAO,aAAa,CAAC,WAAW,CAAC;YACnC,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,GAAG,IAAI,sCAA0B,CAC1C,0NAA0N,CAC3N,CAAC;gBACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAA,wBAAW,EAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;gBACjD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,GAAG,IAAI,sCAA0B,CAC1C,8MAA8M,CAC/M,CAAC;YACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAA,wBAAW,EAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;YACjD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA9JD,gEA8JC","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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QACxC,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAEnC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,sCAA0B,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,IAAA,mBAAQ,EAAC,cAAc,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;YAC/E,OAAO,IAAA,0CAA+B,EAAC,iBAAiB,CAAC,CAAC;QAC5D,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAA,wBAAW,EAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;YACjD,MAAM,IAAI,sCAA0B,CAClC,0DAA0D;gBACxD,uEAAuE;gBACvE,+EAA+E;gBAC/E,yCAAyC,CAC5C,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAxID,gEAwIC","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
|
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
|
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
|
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"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"visualStudioCodeCredentialPlugin.js","sourceRoot":"","sources":["../../../src/credentials/visualStudioCodeCredentialPlugin.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * A function that searches for credentials in the Visual Studio Code credential store.\n *\n * @returns an array of credentials (username and password)\n * @internal\n *\n
|
1
|
+
{"version":3,"file":"visualStudioCodeCredentialPlugin.js","sourceRoot":"","sources":["../../../src/credentials/visualStudioCodeCredentialPlugin.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * A function that searches for credentials in the Visual Studio Code credential store.\n *\n * @returns an array of credentials (username and password)\n * @internal\n *\n */\nexport type VSCodeCredentialFinder = () => Promise<Array<{ account: string; password: string }>>;\n"]}
|
@@ -37,18 +37,20 @@ const logger = (0, logging_js_1.credentialLogger)(credentialName);
|
|
37
37
|
* Workload ID</a> for more information.
|
38
38
|
*/
|
39
39
|
class WorkloadIdentityCredential {
|
40
|
+
client;
|
41
|
+
azureFederatedTokenFileContent = undefined;
|
42
|
+
cacheDate = undefined;
|
43
|
+
federatedTokenFilePath;
|
40
44
|
/**
|
41
45
|
* WorkloadIdentityCredential supports Microsoft Entra Workload ID on Kubernetes.
|
42
46
|
*
|
43
47
|
* @param options - The identity client options to use for authentication.
|
44
48
|
*/
|
45
49
|
constructor(options) {
|
46
|
-
this.azureFederatedTokenFileContent = undefined;
|
47
|
-
this.cacheDate = undefined;
|
48
50
|
// Logging environment variables for error details
|
49
51
|
const assignedEnv = (0, logging_js_1.processEnvVars)(exports.SupportedWorkloadEnvironmentVariables).assigned.join(", ");
|
50
52
|
logger.info(`Found the following environment variables: ${assignedEnv}`);
|
51
|
-
const workloadIdentityCredentialOptions = options
|
53
|
+
const workloadIdentityCredentialOptions = options ?? {};
|
52
54
|
const tenantId = workloadIdentityCredentialOptions.tenantId || process.env.AZURE_TENANT_ID;
|
53
55
|
const clientId = workloadIdentityCredentialOptions.clientId || process.env.AZURE_CLIENT_ID;
|
54
56
|
this.federatedTokenFilePath =
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"workloadIdentityCredential.js","sourceRoot":"","sources":["../../../src/credentials/workloadIdentityCredential.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,mDAAsE;AAEtE,iFAA2E;AAC3E,4CAA0D;AAE1D,+DAAyD;AACzD,+CAA4C;AAE5C,MAAM,cAAc,GAAG,4BAA4B,CAAC;AACpD;;;;;;GAMG;AACU,QAAA,qCAAqC,GAAG;IACnD,iBAAiB;IACjB,iBAAiB;IACjB,4BAA4B;CAC7B,CAAC;AACF,MAAM,MAAM,GAAG,IAAA,6BAAgB,EAAC,cAAc,CAAC,CAAC;AAChD;;;;;;;;;;;;;GAaG;AACH,MAAa,0BAA0B;IAMrC;;;;OAIG;IACH,YAAY,OAA2C;QAT/C,mCAA8B,GAAuB,SAAS,CAAC;QAC/D,cAAS,GAAuB,SAAS,CAAC;QAShD,kDAAkD;QAClD,MAAM,WAAW,GAAG,IA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CAAC,GAAG,EAAE,CAAC;YAC9B,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,8BAA8B,CAAC;IAC7C,CAAC;CACF;AAzGD,gEAyGC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport { credentialLogger, processEnvVars } from \"../util/logging.js\";\n\nimport { ClientAssertionCredential } from \"./clientAssertionCredential.js\";\nimport { CredentialUnavailableError } from \"../errors.js\";\nimport type { WorkloadIdentityCredentialOptions } from \"./workloadIdentityCredentialOptions.js\";\nimport { checkTenantId } from \"../util/tenantIdUtils.js\";\nimport { readFile } from \"node:fs/promises\";\n\nconst credentialName = \"WorkloadIdentityCredential\";\n/**\n * Contains the list of all supported environment variable names so that an\n * appropriate error message can be generated when no credentials can be\n * configured.\n *\n * @internal\n */\nexport const SupportedWorkloadEnvironmentVariables = [\n \"AZURE_TENANT_ID\",\n \"AZURE_CLIENT_ID\",\n \"AZURE_FEDERATED_TOKEN_FILE\",\n];\nconst logger = credentialLogger(credentialName);\n/**\n * Workload Identity authentication is a feature in Azure that allows applications running on virtual machines (VMs)\n * to access other Azure resources without the need for a service principal or managed identity. With Workload Identity\n * authentication, applications authenticate themselves using their own identity, rather than using a shared service\n * principal or managed identity. Under the hood, Workload Identity authentication uses the concept of Service Account\n * Credentials (SACs), which are automatically created by Azure and stored securely in the VM. By using Workload\n * Identity authentication, you can avoid the need to manage and rotate service principals or managed identities for\n * each application on each VM. Additionally, because SACs are created automatically and managed by Azure, you don't\n * need to worry about storing and securing sensitive credentials themselves.\n * The WorkloadIdentityCredential supports Microsoft Entra Workload ID authentication on Azure Kubernetes and acquires\n * a token using the SACs available in the Azure Kubernetes environment.\n * Refer to <a href=\"https://learn.microsoft.com/azure/aks/workload-identity-overview\">Microsoft Entra\n * Workload ID</a> for more information.\n */\nexport class WorkloadIdentityCredential implements TokenCredential {\n private client: ClientAssertionCredential | undefined;\n private azureFederatedTokenFileContent: string | undefined = undefined;\n private cacheDate: number | undefined = undefined;\n private federatedTokenFilePath: string | undefined;\n\n /**\n * WorkloadIdentityCredential supports Microsoft Entra Workload ID on Kubernetes.\n *\n * @param options - The identity client options to use for authentication.\n */\n constructor(options?: WorkloadIdentityCredentialOptions) {\n // Logging environment variables for error details\n const assignedEnv = processEnvVars(SupportedWorkloadEnvironmentVariables).assigned.join(\", \");\n logger.info(`Found the following environment variables: ${assignedEnv}`);\n\n const workloadIdentityCredentialOptions = options ?? {};\n const tenantId = workloadIdentityCredentialOptions.tenantId || process.env.AZURE_TENANT_ID;\n const clientId = workloadIdentityCredentialOptions.clientId || process.env.AZURE_CLIENT_ID;\n this.federatedTokenFilePath =\n workloadIdentityCredentialOptions.tokenFilePath || process.env.AZURE_FEDERATED_TOKEN_FILE;\n if (tenantId) {\n checkTenantId(logger, tenantId);\n }\n if (!clientId) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. clientId is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - \"AZURE_CLIENT_ID\".\n See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`,\n );\n }\n\n if (!tenantId) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. tenantId is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - \"AZURE_TENANT_ID\".\n See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`,\n );\n }\n\n if (!this.federatedTokenFilePath) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. federatedTokenFilePath is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - \"AZURE_FEDERATED_TOKEN_FILE\".\n See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`,\n );\n }\n\n logger.info(\n `Invoking ClientAssertionCredential with tenant ID: ${tenantId}, clientId: ${workloadIdentityCredentialOptions.clientId} and federated token path: [REDACTED]`,\n );\n this.client = new ClientAssertionCredential(\n tenantId,\n clientId,\n this.readFileContents.bind(this),\n options,\n );\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n public async getToken(\n scopes: string | string[],\n options?: GetTokenOptions,\n ): Promise<AccessToken> {\n if (!this.client) {\n const errorMessage = `${credentialName}: is unavailable. tenantId, clientId, and federatedTokenFilePath are required parameters. \n In DefaultAzureCredential and ManagedIdentityCredential, these can be provided as environment variables - \n \"AZURE_TENANT_ID\",\n \"AZURE_CLIENT_ID\",\n \"AZURE_FEDERATED_TOKEN_FILE\". See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`;\n logger.info(errorMessage);\n throw new CredentialUnavailableError(errorMessage);\n }\n logger.info(\"Invoking getToken() of Client Assertion Credential\");\n return this.client.getToken(scopes, options);\n }\n\n private async readFileContents(): Promise<string> {\n // Cached assertions expire after 5 minutes\n if (this.cacheDate !== undefined && Date.now() - this.cacheDate >= 1000 * 60 * 5) {\n this.azureFederatedTokenFileContent = undefined;\n }\n if (!this.federatedTokenFilePath) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. Invalid file path provided ${this.federatedTokenFilePath}.`,\n );\n }\n if (!this.azureFederatedTokenFileContent) {\n const file = await readFile(this.federatedTokenFilePath, \"utf8\");\n const value = file.trim();\n if (!value) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. No content on the file ${this.federatedTokenFilePath}.`,\n );\n } else {\n this.azureFederatedTokenFileContent = value;\n this.cacheDate = Date.now();\n }\n }\n return this.azureFederatedTokenFileContent;\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"workloadIdentityCredential.js","sourceRoot":"","sources":["../../../src/credentials/worklo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CAAC;YACjC,MAAM,IAAI,sCAA0B,CAClC,GAAG,cAAc,gDAAgD,IAAI,CAAC,sBAAsB,GAAG,CAChG,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,8BAA8B,EAAE,CAAC;YACzC,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;YACjE,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAC1B,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,MAAM,IAAI,sCAA0B,CAClC,GAAG,cAAc,4CAA4C,IAAI,CAAC,sBAAsB,GAAG,CAC5F,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,8BAA8B,GAAG,KAAK,CAAC;gBAC5C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC9B,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,8BAA8B,CAAC;IAC7C,CAAC;CACF;AAzGD,gEAyGC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport { credentialLogger, processEnvVars } from \"../util/logging.js\";\n\nimport { ClientAssertionCredential } from \"./clientAssertionCredential.js\";\nimport { CredentialUnavailableError } from \"../errors.js\";\nimport type { WorkloadIdentityCredentialOptions } from \"./workloadIdentityCredentialOptions.js\";\nimport { checkTenantId } from \"../util/tenantIdUtils.js\";\nimport { readFile } from \"node:fs/promises\";\n\nconst credentialName = \"WorkloadIdentityCredential\";\n/**\n * Contains the list of all supported environment variable names so that an\n * appropriate error message can be generated when no credentials can be\n * configured.\n *\n * @internal\n */\nexport const SupportedWorkloadEnvironmentVariables = [\n \"AZURE_TENANT_ID\",\n \"AZURE_CLIENT_ID\",\n \"AZURE_FEDERATED_TOKEN_FILE\",\n];\nconst logger = credentialLogger(credentialName);\n/**\n * Workload Identity authentication is a feature in Azure that allows applications running on virtual machines (VMs)\n * to access other Azure resources without the need for a service principal or managed identity. With Workload Identity\n * authentication, applications authenticate themselves using their own identity, rather than using a shared service\n * principal or managed identity. Under the hood, Workload Identity authentication uses the concept of Service Account\n * Credentials (SACs), which are automatically created by Azure and stored securely in the VM. By using Workload\n * Identity authentication, you can avoid the need to manage and rotate service principals or managed identities for\n * each application on each VM. Additionally, because SACs are created automatically and managed by Azure, you don't\n * need to worry about storing and securing sensitive credentials themselves.\n * The WorkloadIdentityCredential supports Microsoft Entra Workload ID authentication on Azure Kubernetes and acquires\n * a token using the SACs available in the Azure Kubernetes environment.\n * Refer to <a href=\"https://learn.microsoft.com/azure/aks/workload-identity-overview\">Microsoft Entra\n * Workload ID</a> for more information.\n */\nexport class WorkloadIdentityCredential implements TokenCredential {\n private client: ClientAssertionCredential | undefined;\n private azureFederatedTokenFileContent: string | undefined = undefined;\n private cacheDate: number | undefined = undefined;\n private federatedTokenFilePath: string | undefined;\n\n /**\n * WorkloadIdentityCredential supports Microsoft Entra Workload ID on Kubernetes.\n *\n * @param options - The identity client options to use for authentication.\n */\n constructor(options?: WorkloadIdentityCredentialOptions) {\n // Logging environment variables for error details\n const assignedEnv = processEnvVars(SupportedWorkloadEnvironmentVariables).assigned.join(\", \");\n logger.info(`Found the following environment variables: ${assignedEnv}`);\n\n const workloadIdentityCredentialOptions = options ?? {};\n const tenantId = workloadIdentityCredentialOptions.tenantId || process.env.AZURE_TENANT_ID;\n const clientId = workloadIdentityCredentialOptions.clientId || process.env.AZURE_CLIENT_ID;\n this.federatedTokenFilePath =\n workloadIdentityCredentialOptions.tokenFilePath || process.env.AZURE_FEDERATED_TOKEN_FILE;\n if (tenantId) {\n checkTenantId(logger, tenantId);\n }\n if (!clientId) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. clientId is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - \"AZURE_CLIENT_ID\".\n See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`,\n );\n }\n\n if (!tenantId) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. tenantId is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - \"AZURE_TENANT_ID\".\n See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`,\n );\n }\n\n if (!this.federatedTokenFilePath) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. federatedTokenFilePath is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - \"AZURE_FEDERATED_TOKEN_FILE\".\n See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`,\n );\n }\n\n logger.info(\n `Invoking ClientAssertionCredential with tenant ID: ${tenantId}, clientId: ${workloadIdentityCredentialOptions.clientId} and federated token path: [REDACTED]`,\n );\n this.client = new ClientAssertionCredential(\n tenantId,\n clientId,\n this.readFileContents.bind(this),\n options,\n );\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n public async getToken(\n scopes: string | string[],\n options?: GetTokenOptions,\n ): Promise<AccessToken> {\n if (!this.client) {\n const errorMessage = `${credentialName}: is unavailable. tenantId, clientId, and federatedTokenFilePath are required parameters. \n In DefaultAzureCredential and ManagedIdentityCredential, these can be provided as environment variables - \n \"AZURE_TENANT_ID\",\n \"AZURE_CLIENT_ID\",\n \"AZURE_FEDERATED_TOKEN_FILE\". See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`;\n logger.info(errorMessage);\n throw new CredentialUnavailableError(errorMessage);\n }\n logger.info(\"Invoking getToken() of Client Assertion Credential\");\n return this.client.getToken(scopes, options);\n }\n\n private async readFileContents(): Promise<string> {\n // Cached assertions expire after 5 minutes\n if (this.cacheDate !== undefined && Date.now() - this.cacheDate >= 1000 * 60 * 5) {\n this.azureFederatedTokenFileContent = undefined;\n }\n if (!this.federatedTokenFilePath) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. Invalid file path provided ${this.federatedTokenFilePath}.`,\n );\n }\n if (!this.azureFederatedTokenFileContent) {\n const file = await readFile(this.federatedTokenFilePath, \"utf8\");\n const value = file.trim();\n if (!value) {\n throw new CredentialUnavailableError(\n `${credentialName}: is unavailable. No content on the file ${this.federatedTokenFilePath}.`,\n );\n } else {\n this.azureFederatedTokenFileContent = value;\n this.cacheDate = Date.now();\n }\n }\n return this.azureFederatedTokenFileContent;\n }\n}\n"]}
|
package/dist/commonjs/errors.js
CHANGED
@@ -35,6 +35,14 @@ exports.AuthenticationErrorName = "AuthenticationError";
|
|
35
35
|
* the specific failure.
|
36
36
|
*/
|
37
37
|
class AuthenticationError extends Error {
|
38
|
+
/**
|
39
|
+
* The HTTP status code returned from the authentication request.
|
40
|
+
*/
|
41
|
+
statusCode;
|
42
|
+
/**
|
43
|
+
* The error response details.
|
44
|
+
*/
|
45
|
+
errorResponse;
|
38
46
|
constructor(statusCode, errorBody, options) {
|
39
47
|
let errorResponse = {
|
40
48
|
error: "unknown",
|
@@ -90,6 +98,11 @@ exports.AggregateAuthenticationErrorName = "AggregateAuthenticationError";
|
|
90
98
|
* for authentication failures from credentials in a {@link ChainedTokenCredential}.
|
91
99
|
*/
|
92
100
|
class AggregateAuthenticationError extends Error {
|
101
|
+
/**
|
102
|
+
* The array of error objects that were thrown while trying to authenticate
|
103
|
+
* with the credentials in a {@link ChainedTokenCredential}.
|
104
|
+
*/
|
105
|
+
errors;
|
93
106
|
constructor(errors, errorMessage) {
|
94
107
|
const errorDetail = errors.join("\n");
|
95
108
|
super(`${errorMessage}\n${errorDetail}`);
|
@@ -113,6 +126,14 @@ function convertOAuthErrorResponseToErrorResponse(errorBody) {
|
|
113
126
|
* Error used to enforce authentication after trying to retrieve a token silently.
|
114
127
|
*/
|
115
128
|
class AuthenticationRequiredError extends Error {
|
129
|
+
/**
|
130
|
+
* The list of scopes for which the token will have access.
|
131
|
+
*/
|
132
|
+
scopes;
|
133
|
+
/**
|
134
|
+
* The options passed to the getToken request.
|
135
|
+
*/
|
136
|
+
getTokenOptions;
|
116
137
|
constructor(
|
117
138
|
/**
|
118
139
|
* Optional parameters. A message can be specified. The {@link GetTokenOptions} of the request can also be specified to more easily associate the error with the received parameters.
|