@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.
- 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/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 +6 -6
@@ -0,0 +1,69 @@
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
2
|
+
// Licensed under the MIT License.
|
3
|
+
import { processMultiTenantRequest, resolveAdditionallyAllowedTenantIds, resolveTenantId, } from "../util/tenantIdUtils.js";
|
4
|
+
import { credentialLogger, formatError } from "../util/logging.js";
|
5
|
+
import { ensureScopes } from "../util/scopeUtils.js";
|
6
|
+
import { tracingClient } from "../util/tracing.js";
|
7
|
+
import { createMsalClient } from "../msal/nodeFlows/msalClient.js";
|
8
|
+
import { DeveloperSignOnClientId } from "../constants.js";
|
9
|
+
import { CredentialUnavailableError } from "../errors.js";
|
10
|
+
const logger = credentialLogger("BrokerCredential");
|
11
|
+
/**
|
12
|
+
* Enables authentication to Microsoft Entra ID using WAM (Web Account Manager) broker.
|
13
|
+
* This credential extends InteractiveBrowserCredential and provides additional broker-specific functionality.
|
14
|
+
*/
|
15
|
+
export class BrokerCredential {
|
16
|
+
brokerMsalClient;
|
17
|
+
brokerTenantId;
|
18
|
+
brokerAdditionallyAllowedTenantIds;
|
19
|
+
/**
|
20
|
+
* Creates an instance of BrokerCredential with the required broker options.
|
21
|
+
*
|
22
|
+
* This credential uses WAM (Web Account Manager) for authentication, which provides
|
23
|
+
* better security and user experience on Windows platforms.
|
24
|
+
*
|
25
|
+
* @param options - Options for configuring the broker credential, including required broker options.
|
26
|
+
*/
|
27
|
+
constructor(options) {
|
28
|
+
this.brokerTenantId = resolveTenantId(logger, options.tenantId);
|
29
|
+
this.brokerAdditionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options?.additionallyAllowedTenants);
|
30
|
+
const msalClientOptions = {
|
31
|
+
...options,
|
32
|
+
tokenCredentialOptions: options,
|
33
|
+
logger,
|
34
|
+
brokerOptions: {
|
35
|
+
enabled: true,
|
36
|
+
parentWindowHandle: new Uint8Array(0),
|
37
|
+
useDefaultBrokerAccount: true,
|
38
|
+
},
|
39
|
+
};
|
40
|
+
this.brokerMsalClient = createMsalClient(DeveloperSignOnClientId, this.brokerTenantId, msalClientOptions);
|
41
|
+
}
|
42
|
+
/**
|
43
|
+
* Authenticates with Microsoft Entra ID using WAM broker and returns an access token if successful.
|
44
|
+
* If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
|
45
|
+
*
|
46
|
+
* This method extends the base getToken method to support silentAuthenticationOnly option
|
47
|
+
* when using broker authentication.
|
48
|
+
*
|
49
|
+
* @param scopes - The list of scopes for which the token will have access.
|
50
|
+
* @param options - The options used to configure the token request, including silentAuthenticationOnly option.
|
51
|
+
*/
|
52
|
+
async getToken(scopes, options = {}) {
|
53
|
+
return tracingClient.withSpan(`${this.constructor.name}.getToken`, options, async (newOptions) => {
|
54
|
+
newOptions.tenantId = processMultiTenantRequest(this.brokerTenantId, newOptions, this.brokerAdditionallyAllowedTenantIds, logger);
|
55
|
+
const arrayScopes = ensureScopes(scopes);
|
56
|
+
try {
|
57
|
+
return this.brokerMsalClient.getBrokeredToken(arrayScopes, true, {
|
58
|
+
...newOptions,
|
59
|
+
disableAutomaticAuthentication: true,
|
60
|
+
});
|
61
|
+
}
|
62
|
+
catch (e) {
|
63
|
+
logger.getToken.info(formatError(arrayScopes, e));
|
64
|
+
throw new CredentialUnavailableError("Failed to acquire token using broker authentication", { cause: e });
|
65
|
+
}
|
66
|
+
});
|
67
|
+
}
|
68
|
+
}
|
69
|
+
//# sourceMappingURL=brokerCredential.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"brokerCredential.js","sourceRoot":"","sources":["../../../src/credentials/brokerCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,yBAAyB,EACzB,mCAAmC,EACnC,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAG1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAE1D,MAAM,MAAM,GAAG,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;AAEpD;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACnB,gBAAgB,CAAa;IAC7B,cAAc,CAAU;IACxB,kCAAkC,CAAW;IAErD;;;;;;;OAOG;IACH,YACE,OAA2F;QAE3F,IAAI,CAAC,cAAc,GAAG,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QAChE,IAAI,CAAC,kCAAkC,GAAG,mCAAmC,CAC3E,OAAO,EAAE,0BAA0B,CACpC,CAAC;QACF,MAAM,iBAAiB,GAAsB;YAC3C,GAAG,OAAO;YACV,sBAAsB,EAAE,OAAO;YAC/B,MAAM;YACN,aAAa,EAAE;gBACb,OAAO,EAAE,IAAI;gBACb,kBAAkB,EAAE,IAAI,UAAU,CAAC,CAAC,CAAC;gBACrC,uBAAuB,EAAE,IAAI;aAC9B;SACF,CAAC;QAEF,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CACtC,uBAAuB,EACvB,IAAI,CAAC,cAAc,EACnB,iBAAiB,CAClB,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;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,cAAc,EACnB,UAAU,EACV,IAAI,CAAC,kCAAkC,EACvC,MAAM,CACP,CAAC;YAEF,MAAM,WAAW,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;YACzC,IAAI,CAAC;gBACH,OAAO,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,WAAW,EAAE,IAAI,EAAE;oBAC/D,GAAG,UAAU;oBACb,8BAA8B,EAAE,IAAI;iBACrC,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;gBAClD,MAAM,IAAI,0BAA0B,CAClC,qDAAqD,EACrD,EAAE,KAAK,EAAE,CAAC,EAAE,CACb,CAAC;YACJ,CAAC;QACH,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 {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n resolveTenantId,\n} from \"../util/tenantIdUtils.js\";\n\nimport { credentialLogger, formatError } from \"../util/logging.js\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { tracingClient } from \"../util/tracing.js\";\nimport type { MsalClient, MsalClientOptions } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { DeveloperSignOnClientId } from \"../constants.js\";\nimport { TokenCredentialOptions } from \"../tokenCredentialOptions.js\";\nimport { MultiTenantTokenCredentialOptions } from \"./multiTenantTokenCredentialOptions.js\";\nimport { CredentialUnavailableError } from \"../errors.js\";\n\nconst logger = credentialLogger(\"BrokerCredential\");\n\n/**\n * Enables authentication to Microsoft Entra ID using WAM (Web Account Manager) broker.\n * This credential extends InteractiveBrowserCredential and provides additional broker-specific functionality.\n */\nexport class BrokerCredential implements TokenCredential {\n private brokerMsalClient: MsalClient;\n private brokerTenantId?: string;\n private brokerAdditionallyAllowedTenantIds: string[];\n\n /**\n * Creates an instance of BrokerCredential with the required broker options.\n *\n * This credential uses WAM (Web Account Manager) for authentication, which provides\n * better security and user experience on Windows platforms.\n *\n * @param options - Options for configuring the broker credential, including required broker options.\n */\n constructor(\n options: { tenantId?: string } & TokenCredentialOptions & MultiTenantTokenCredentialOptions,\n ) {\n this.brokerTenantId = resolveTenantId(logger, options.tenantId);\n this.brokerAdditionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n const msalClientOptions: MsalClientOptions = {\n ...options,\n tokenCredentialOptions: options,\n logger,\n brokerOptions: {\n enabled: true,\n parentWindowHandle: new Uint8Array(0),\n useDefaultBrokerAccount: true,\n },\n };\n\n this.brokerMsalClient = createMsalClient(\n DeveloperSignOnClientId,\n this.brokerTenantId,\n msalClientOptions,\n );\n }\n\n /**\n * Authenticates with Microsoft Entra ID using WAM broker 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 * This method extends the base getToken method to support silentAuthenticationOnly option\n * when using broker authentication.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure the token request, including silentAuthenticationOnly option.\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.brokerTenantId,\n newOptions,\n this.brokerAdditionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = ensureScopes(scopes);\n try {\n return this.brokerMsalClient.getBrokeredToken(arrayScopes, true, {\n ...newOptions,\n disableAutomaticAuthentication: true,\n });\n } catch (e: any) {\n logger.getToken.info(formatError(arrayScopes, e));\n throw new CredentialUnavailableError(\n \"Failed to acquire token using broker authentication\",\n { cause: e },\n );\n }\n },\n );\n }\n}\n"]}
|
@@ -13,6 +13,7 @@ export const logger = credentialLogger("ChainedTokenCredential");
|
|
13
13
|
* [ChainedTokenCredential overview](https://aka.ms/azsdk/js/identity/credential-chains#use-chainedtokencredential-for-granularity).
|
14
14
|
*/
|
15
15
|
export class ChainedTokenCredential {
|
16
|
+
_sources = [];
|
16
17
|
/**
|
17
18
|
* Creates an instance of ChainedTokenCredential using the given credentials.
|
18
19
|
*
|
@@ -35,7 +36,6 @@ export class ChainedTokenCredential {
|
|
35
36
|
* ```
|
36
37
|
*/
|
37
38
|
constructor(...sources) {
|
38
|
-
this._sources = [];
|
39
39
|
this._sources = sources;
|
40
40
|
}
|
41
41
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"chainedTokenCredential.js","sourceRoot":"","sources":["../../../src/credentials/chainedTokenCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,gBAAgB,CAAC,wBAAwB,CAAC,CAAC;AAEjE;;;;GAIG;AACH,MAAM,OAAO,sBAAsB;
|
1
|
+
{"version":3,"file":"chainedTokenCredential.js","sourceRoot":"","sources":["../../../src/credentials/chainedTokenCredential.ts"],"names":[],"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Ac,CAAC,CAAC;oBAChE,oBAAoB,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;gBAC1C,CAAC;gBAAC,OAAO,GAAQ,EAAE,CAAC;oBAClB,IACE,GAAG,CAAC,IAAI,KAAK,4BAA4B;wBACzC,GAAG,CAAC,IAAI,KAAK,6BAA6B,EAC1C,CAAC;wBACD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;oBACnB,CAAC;yBAAM,CAAC;wBACN,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;wBAC/C,MAAM,GAAG,CAAC;oBACZ,CAAC;gBACH,CAAC;YACH,CAAC;YAED,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAChC,MAAM,GAAG,GAAG,IAAI,4BAA4B,CAC1C,MAAM,EACN,+CAA+C,CAChD,CAAC;gBACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;gBAC/C,MAAM,GAAG,CAAC;YACZ,CAAC;YAED,MAAM,CAAC,QAAQ,CAAC,IAAI,CAClB,cAAc,oBAAoB,CAAC,WAAW,CAAC,IAAI,KAAK,aAAa,CAAC,MAAM,CAAC,EAAE,CAChF,CAAC;YAEF,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACnB,MAAM,IAAI,0BAA0B,CAAC,kCAAkC,CAAC,CAAC;YAC3E,CAAC;YACD,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAC;QACzC,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 { AggregateAuthenticationError, CredentialUnavailableError } from \"../errors.js\";\nimport { credentialLogger, formatError, formatSuccess } from \"../util/logging.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\n/**\n * @internal\n */\nexport const logger = credentialLogger(\"ChainedTokenCredential\");\n\n/**\n * Enables multiple `TokenCredential` implementations to be tried in order until\n * one of the getToken methods returns an access token. For more information, see\n * [ChainedTokenCredential overview](https://aka.ms/azsdk/js/identity/credential-chains#use-chainedtokencredential-for-granularity).\n */\nexport class ChainedTokenCredential implements TokenCredential {\n private _sources: TokenCredential[] = [];\n\n /**\n * Creates an instance of ChainedTokenCredential using the given credentials.\n *\n * @param sources - `TokenCredential` implementations to be tried in order.\n *\n * Example usage:\n * ```ts snippet:chained_token_credential_example\n * import { ClientSecretCredential, ChainedTokenCredential } from \"@azure/identity\";\n *\n * const tenantId = \"<tenant-id>\";\n * const clientId = \"<client-id>\";\n * const clientSecret = \"<client-secret>\";\n * const anotherClientId = \"<another-client-id>\";\n * const anotherSecret = \"<another-client-secret>\";\n *\n * const firstCredential = new ClientSecretCredential(tenantId, clientId, clientSecret);\n * const secondCredential = new ClientSecretCredential(tenantId, anotherClientId, anotherSecret);\n *\n * const credentialChain = new ChainedTokenCredential(firstCredential, secondCredential);\n * ```\n */\n constructor(...sources: TokenCredential[]) {\n this._sources = sources;\n }\n\n /**\n * Returns the first access token returned by one of the chained\n * `TokenCredential` implementations. Throws an {@link AggregateAuthenticationError}\n * when one or more credentials throws an {@link AuthenticationError} and\n * no credentials have returned an access token.\n *\n * This method is called automatically by Azure SDK client libraries. You may call this method\n * directly, but you must also handle token caching and token refreshing.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * `TokenCredential` implementation might make.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n const { token } = await this.getTokenInternal(scopes, options);\n return token;\n }\n\n private async getTokenInternal(\n scopes: string | string[],\n options: GetTokenOptions = {},\n ): Promise<{ token: AccessToken; successfulCredential: TokenCredential }> {\n let token: AccessToken | null = null;\n let successfulCredential: TokenCredential;\n const errors: Error[] = [];\n\n return tracingClient.withSpan(\n \"ChainedTokenCredential.getToken\",\n options,\n async (updatedOptions) => {\n for (let i = 0; i < this._sources.length && token === null; i++) {\n try {\n token = await this._sources[i].getToken(scopes, updatedOptions);\n successfulCredential = this._sources[i];\n } catch (err: any) {\n if (\n err.name === \"CredentialUnavailableError\" ||\n err.name === \"AuthenticationRequiredError\"\n ) {\n errors.push(err);\n } else {\n logger.getToken.info(formatError(scopes, err));\n throw err;\n }\n }\n }\n\n if (!token && errors.length > 0) {\n const err = new AggregateAuthenticationError(\n errors,\n \"ChainedTokenCredential authentication failed.\",\n );\n logger.getToken.info(formatError(scopes, err));\n throw err;\n }\n\n logger.getToken.info(\n `Result for ${successfulCredential.constructor.name}: ${formatSuccess(scopes)}`,\n );\n\n if (token === null) {\n throw new CredentialUnavailableError(\"Failed to retrieve a valid token\");\n }\n return { token, successfulCredential };\n },\n );\n }\n}\n"]}
|
@@ -10,6 +10,11 @@ const logger = credentialLogger("ClientAssertionCredential");
|
|
10
10
|
* Authenticates a service principal with a JWT assertion.
|
11
11
|
*/
|
12
12
|
export class ClientAssertionCredential {
|
13
|
+
msalClient;
|
14
|
+
tenantId;
|
15
|
+
additionallyAllowedTenantIds;
|
16
|
+
getAssertion;
|
17
|
+
options;
|
13
18
|
/**
|
14
19
|
* Creates an instance of the ClientAssertionCredential with the details
|
15
20
|
* needed to authenticate against Microsoft Entra ID with a client
|
@@ -31,10 +36,14 @@ export class ClientAssertionCredential {
|
|
31
36
|
throw new CredentialUnavailableError("ClientAssertionCredential: clientAssertion is a required parameter.");
|
32
37
|
}
|
33
38
|
this.tenantId = tenantId;
|
34
|
-
this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options
|
39
|
+
this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options?.additionallyAllowedTenants);
|
35
40
|
this.options = options;
|
36
41
|
this.getAssertion = getAssertion;
|
37
|
-
this.msalClient = createMsalClient(clientId, tenantId,
|
42
|
+
this.msalClient = createMsalClient(clientId, tenantId, {
|
43
|
+
...options,
|
44
|
+
logger,
|
45
|
+
tokenCredentialOptions: this.options,
|
46
|
+
});
|
38
47
|
}
|
39
48
|
/**
|
40
49
|
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"clientAssertionCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientAssertionCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EACL,yBAAyB,EACzB,mCAAmC,GACpC,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,MAAM,GAAG,gBAAgB,CAAC,2BAA2B,CAAC,CAAC;AAE7D;;GAEG;AACH,MAAM,OAAO,yBAAyB;
|
1
|
+
{"version":3,"file":"clientAssertionCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientAssertionCredential.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;AAGlC,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,MAAM,GAAG,gBAAgB,CAAC,2BAA2B,CAAC,CAAC;AAE7D;;GAEG;AACH,MAAM,OAAO,yBAAyB;IAC5B,UAAU,CAAa;IACvB,QAAQ,CAAS;IACjB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CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YAC9D,OAAO,IAAI,CAAC,UAAU,CAAC,yBAAyB,CAC9C,WAAW,EACX,IAAI,CAAC,YAAY,EACjB,UAAU,CACX,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type { MsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\n\nimport type { ClientAssertionCredentialOptions } from \"./clientAssertionCredentialOptions.js\";\nimport { CredentialUnavailableError } from \"../errors.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\nconst logger = credentialLogger(\"ClientAssertionCredential\");\n\n/**\n * Authenticates a service principal with a JWT assertion.\n */\nexport class ClientAssertionCredential implements TokenCredential {\n private msalClient: MsalClient;\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private getAssertion: () => Promise<string>;\n private options: ClientAssertionCredentialOptions;\n\n /**\n * Creates an instance of the ClientAssertionCredential with the details\n * needed to authenticate against Microsoft Entra ID with a client\n * assertion provided by the developer through the `getAssertion` function parameter.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param getAssertion - A function that retrieves the assertion for the credential to use.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n getAssertion: () => Promise<string>,\n options: ClientAssertionCredentialOptions = {},\n ) {\n if (!tenantId) {\n throw new CredentialUnavailableError(\n \"ClientAssertionCredential: tenantId is a required parameter.\",\n );\n }\n\n if (!clientId) {\n throw new CredentialUnavailableError(\n \"ClientAssertionCredential: clientId is a required parameter.\",\n );\n }\n\n if (!getAssertion) {\n throw new CredentialUnavailableError(\n \"ClientAssertionCredential: clientAssertion is a required parameter.\",\n );\n }\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.options = options;\n this.getAssertion = getAssertion;\n this.msalClient = createMsalClient(clientId, tenantId, {\n ...options,\n logger,\n tokenCredentialOptions: this.options,\n });\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(\n `${this.constructor.name}.getToken`,\n options,\n async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];\n return this.msalClient.getTokenByClientAssertion(\n arrayScopes,\n this.getAssertion,\n newOptions,\n );\n },\n );\n }\n}\n"]}
|
@@ -17,18 +17,25 @@ const logger = credentialLogger(credentialName);
|
|
17
17
|
*
|
18
18
|
*/
|
19
19
|
export class ClientCertificateCredential {
|
20
|
+
tenantId;
|
21
|
+
additionallyAllowedTenantIds;
|
22
|
+
certificateConfiguration;
|
23
|
+
sendCertificateChain;
|
24
|
+
msalClient;
|
20
25
|
constructor(tenantId, clientId, certificatePathOrConfiguration, options = {}) {
|
21
26
|
if (!tenantId || !clientId) {
|
22
27
|
throw new Error(`${credentialName}: tenantId and clientId are required parameters.`);
|
23
28
|
}
|
24
29
|
this.tenantId = tenantId;
|
25
|
-
this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options
|
30
|
+
this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options?.additionallyAllowedTenants);
|
26
31
|
this.sendCertificateChain = options.sendCertificateChain;
|
27
|
-
this.certificateConfiguration =
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
this.certificateConfiguration = {
|
33
|
+
...(typeof certificatePathOrConfiguration === "string"
|
34
|
+
? {
|
35
|
+
certificatePath: certificatePathOrConfiguration,
|
36
|
+
}
|
37
|
+
: certificatePathOrConfiguration),
|
38
|
+
};
|
32
39
|
const certificate = this.certificateConfiguration
|
33
40
|
.certificate;
|
34
41
|
const certificatePath = this.certificateConfiguration
|
@@ -39,7 +46,11 @@ export class ClientCertificateCredential {
|
|
39
46
|
if (certificate && certificatePath) {
|
40
47
|
throw new Error(`${credentialName}: To avoid unexpected behaviors, providing both the contents of a PEM certificate and the path to a PEM certificate is forbidden. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`);
|
41
48
|
}
|
42
|
-
this.msalClient = createMsalClient(clientId, tenantId,
|
49
|
+
this.msalClient = createMsalClient(clientId, tenantId, {
|
50
|
+
...options,
|
51
|
+
logger,
|
52
|
+
tokenCredentialOptions: options,
|
53
|
+
});
|
43
54
|
}
|
44
55
|
/**
|
45
56
|
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
@@ -58,8 +69,7 @@ export class ClientCertificateCredential {
|
|
58
69
|
});
|
59
70
|
}
|
60
71
|
async buildClientCertificate() {
|
61
|
-
|
62
|
-
const parts = await parseCertificate(this.certificateConfiguration, (_a = this.sendCertificateChain) !== null && _a !== void 0 ? _a : false);
|
72
|
+
const parts = await parseCertificate(this.certificateConfiguration, this.sendCertificateChain ?? false);
|
63
73
|
let privateKey;
|
64
74
|
if (this.certificateConfiguration.certificatePassword !== undefined) {
|
65
75
|
privateKey = createPrivateKey({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"clientCertificateCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientCertificateCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;A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,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;IAChG,CAAC;IAED,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,4DAA4D;SAC/F,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;SAC5C,MAAM,CAAC,KAAK,CAAC;SACb,WAAW,EAAE,CAAC;IAEjB,MAAM,gBAAgB,GAAG,UAAU,CAAC,QAAQ,CAAC;SAC1C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;SAC5C,MAAM,CAAC,KAAK,CAAC;SACb,WAAW,EAAE,CAAC;IAEjB,OAAO;QACL,mBAAmB;QACnB,gBAAgB;QAChB,UAAU;QACV,GAAG;KACJ,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type { MsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createHash, createPrivateKey } from \"node:crypto\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\n\nimport type { CertificateParts } from \"../msal/types.js\";\nimport type { ClientCertificateCredentialOptions } from \"./clientCertificateCredentialOptions.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { readFile } from \"node:fs/promises\";\nimport { tracingClient } from \"../util/tracing.js\";\nimport type {\n ClientCertificateCredentialPEMConfiguration,\n ClientCertificatePEMCertificate,\n ClientCertificatePEMCertificatePath,\n} from \"./clientCertificateCredentialModels.js\";\n\nconst credentialName = \"ClientCertificateCredential\";\nconst logger = credentialLogger(credentialName);\n\n/**\n * Enables authentication to Microsoft Entra ID using a PEM-encoded\n * certificate that is assigned to an App Registration. More information\n * on how to configure certificate authentication can be found here:\n *\n * https://learn.microsoft.com/azure/active-directory/develop/active-directory-certificate-credentials#register-your-certificate-with-azure-ad\n *\n */\nexport class ClientCertificateCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private certificateConfiguration: ClientCertificateCredentialPEMConfiguration;\n private sendCertificateChain?: boolean;\n private msalClient: MsalClient;\n\n /**\n * Creates an instance of the ClientCertificateCredential with the details\n * needed to authenticate against Microsoft Entra ID with a certificate.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param certificatePath - The path to a PEM-encoded public/private key certificate on the filesystem.\n * Ensure that certificate is in PEM format and contains both the public and private keys.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n certificatePath: string,\n options?: ClientCertificateCredentialOptions,\n );\n /**\n * Creates an instance of the ClientCertificateCredential with the details\n * needed to authenticate against Microsoft Entra ID with a certificate.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param configuration - Other parameters required, including the path of the certificate on the filesystem.\n * If the type is ignored, we will throw the value of the path to a PEM certificate.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n configuration: ClientCertificatePEMCertificatePath,\n options?: ClientCertificateCredentialOptions,\n );\n /**\n * Creates an instance of the ClientCertificateCredential with the details\n * needed to authenticate against Microsoft Entra ID with a certificate.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param configuration - Other parameters required, including the PEM-encoded certificate as a string.\n * If the type is ignored, we will throw the value of the PEM-encoded certificate.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n configuration: ClientCertificatePEMCertificate,\n options?: ClientCertificateCredentialOptions,\n );\n constructor(\n tenantId: string,\n clientId: string,\n certificatePathOrConfiguration: string | ClientCertificateCredentialPEMConfiguration,\n options: ClientCertificateCredentialOptions = {},\n ) {\n if (!tenantId || !clientId) {\n throw new Error(`${credentialName}: tenantId and clientId are required parameters.`);\n }\n\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.sendCertificateChain = options.sendCertificateChain;\n\n this.certificateConfiguration = {\n ...(typeof certificatePathOrConfiguration === \"string\"\n ? {\n certificatePath: certificatePathOrConfiguration,\n }\n : certificatePathOrConfiguration),\n };\n const certificate = (this.certificateConfiguration as ClientCertificatePEMCertificate)\n .certificate;\n const certificatePath = (this.certificateConfiguration as ClientCertificatePEMCertificatePath)\n .certificatePath;\n if (!this.certificateConfiguration || !(certificate || certificatePath)) {\n throw new Error(\n `${credentialName}: Provide either a PEM certificate in string form, or the path to that certificate in the filesystem. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n if (certificate && certificatePath) {\n throw new Error(\n `${credentialName}: To avoid unexpected behaviors, providing both the contents of a PEM certificate and the path to a PEM certificate is forbidden. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n this.msalClient = createMsalClient(clientId, tenantId, {\n ...options,\n logger,\n tokenCredentialOptions: options,\n });\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(`${credentialName}.getToken`, options, async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];\n const certificate = await this.buildClientCertificate();\n return this.msalClient.getTokenByClientCertificate(arrayScopes, certificate, newOptions);\n });\n }\n\n private async buildClientCertificate(): Promise<CertificateParts> {\n const parts = await parseCertificate(\n this.certificateConfiguration,\n this.sendCertificateChain ?? false,\n );\n\n let privateKey: string;\n if (this.certificateConfiguration.certificatePassword !== undefined) {\n privateKey = createPrivateKey({\n key: parts.certificateContents,\n passphrase: this.certificateConfiguration.certificatePassword,\n format: \"pem\",\n })\n .export({\n format: \"pem\",\n type: \"pkcs8\",\n })\n .toString();\n } else {\n privateKey = parts.certificateContents;\n }\n\n return {\n thumbprint: parts.thumbprint,\n thumbprintSha256: parts.thumbprintSha256,\n privateKey,\n x5c: parts.x5c,\n };\n }\n}\n\n/**\n * Parses a certificate into its relevant parts\n *\n * @param certificateConfiguration - The certificate contents or path to the certificate\n * @param sendCertificateChain - true if the entire certificate chain should be sent for SNI, false otherwise\n * @returns The parsed certificate parts and the certificate contents\n */\nexport async function parseCertificate(\n certificateConfiguration: ClientCertificateCredentialPEMConfiguration,\n sendCertificateChain: boolean,\n): Promise<Omit<CertificateParts, \"privateKey\"> & { certificateContents: string }> {\n const certificate = (certificateConfiguration as ClientCertificatePEMCertificate).certificate;\n const certificatePath = (certificateConfiguration as ClientCertificatePEMCertificatePath)\n .certificatePath;\n const certificateContents = certificate || (await readFile(certificatePath!, \"utf8\"));\n const x5c = sendCertificateChain ? certificateContents : undefined;\n\n const certificatePattern =\n /(-+BEGIN CERTIFICATE-+)(\\n\\r?|\\r\\n?)([A-Za-z0-9+/\\n\\r]+=*)(\\n\\r?|\\r\\n?)(-+END CERTIFICATE-+)/g;\n const publicKeys: string[] = [];\n\n // Match all possible certificates, in the order they are in the file. These will form the chain that is used for x5c\n let match;\n do {\n match = certificatePattern.exec(certificateContents);\n if (match) {\n publicKeys.push(match[3]);\n }\n } while (match);\n\n if (publicKeys.length === 0) {\n throw new Error(\"The file at the specified path does not contain a PEM-encoded certificate.\");\n }\n\n const thumbprint = createHash(\"sha1\") // CodeQL [SM04514] Needed for backward compatibility reason\n .update(Buffer.from(publicKeys[0], \"base64\"))\n .digest(\"hex\")\n .toUpperCase();\n\n const thumbprintSha256 = createHash(\"sha256\")\n .update(Buffer.from(publicKeys[0], \"base64\"))\n .digest(\"hex\")\n .toUpperCase();\n\n return {\n certificateContents,\n thumbprintSha256,\n thumbprint,\n x5c,\n };\n}\n"]}
|
1
|
+
{"version":3,"file":"clientCertificateCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientCertificateCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,yBAAyB,EACzB,mCAAmC,GACpC,MAAM,0BAA0B,CAAC;AAIlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAOnD,MAAM,cAAc,GAAG,6BAA6B,CAAC;AACrD,MAAM,MAAM,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,OAAO,2BAA2B;IAC9B,QAAQ,CAAS;IACjB,4BAA4B,CAAW;IACvC,wBAAwB,CAA8C;IACtE,oBAAoB,CAAW;IAC/B,UAAU,CAAa;IAkD/B,YACE,QAAgB,EAChB,QAAgB,EAChB,8BAAoF,EACpF,UAA8C,EAAE;QAEhD,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,GAAG,cAAc,kDAAkD,CAAC,CAAC;QACvF,CAAC;QAED,IAAI,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C;IACnB,MAAM,mBAAmB,GAAG,WAAW,IAAI,CAAC,MAAM,QAAQ,CAAC,eAAgB,EAAE,MAAM,CAAC,CAAC,CAAC;IACtF,MAAM,GAAG,GAAG,oBAAoB,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,SAAS,CAAC;IAEnE,MAAM,kBAAkB,GACtB,+FAA+F,CAAC;IAClG,MAAM,UAAU,GAAa,EAAE,CAAC;IAEhC,qHAAqH;IACrH,IAAI,KAAK,CAAC;IACV,GAAG,CAAC;QACF,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACrD,IAAI,KAAK,EAAE,CAAC;YACV,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC,QAAQ,KAAK,EAAE;IAEhB,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;IAChG,CAAC;IAED,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,4DAA4D;SAC/F,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;SAC5C,MAAM,CAAC,KAAK,CAAC;SACb,WAAW,EAAE,CAAC;IAEjB,MAAM,gBAAgB,GAAG,UAAU,CAAC,QAAQ,CAAC;SAC1C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;SAC5C,MAAM,CAAC,KAAK,CAAC;SACb,WAAW,EAAE,CAAC;IAEjB,OAAO;QACL,mBAAmB;QACnB,gBAAgB;QAChB,UAAU;QACV,GAAG;KACJ,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport type { MsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createMsalClient } from \"../msal/nodeFlows/msalClient.js\";\nimport { createHash, createPrivateKey } from \"node:crypto\";\nimport {\n processMultiTenantRequest,\n resolveAdditionallyAllowedTenantIds,\n} from \"../util/tenantIdUtils.js\";\n\nimport type { CertificateParts } from \"../msal/types.js\";\nimport type { ClientCertificateCredentialOptions } from \"./clientCertificateCredentialOptions.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { readFile } from \"node:fs/promises\";\nimport { tracingClient } from \"../util/tracing.js\";\nimport type {\n ClientCertificateCredentialPEMConfiguration,\n ClientCertificatePEMCertificate,\n ClientCertificatePEMCertificatePath,\n} from \"./clientCertificateCredentialModels.js\";\n\nconst credentialName = \"ClientCertificateCredential\";\nconst logger = credentialLogger(credentialName);\n\n/**\n * Enables authentication to Microsoft Entra ID using a PEM-encoded\n * certificate that is assigned to an App Registration. More information\n * on how to configure certificate authentication can be found here:\n *\n * https://learn.microsoft.com/azure/active-directory/develop/active-directory-certificate-credentials#register-your-certificate-with-azure-ad\n *\n */\nexport class ClientCertificateCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private certificateConfiguration: ClientCertificateCredentialPEMConfiguration;\n private sendCertificateChain?: boolean;\n private msalClient: MsalClient;\n\n /**\n * Creates an instance of the ClientCertificateCredential with the details\n * needed to authenticate against Microsoft Entra ID with a certificate.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param certificatePath - The path to a PEM-encoded public/private key certificate on the filesystem.\n * Ensure that certificate is in PEM format and contains both the public and private keys.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n certificatePath: string,\n options?: ClientCertificateCredentialOptions,\n );\n /**\n * Creates an instance of the ClientCertificateCredential with the details\n * needed to authenticate against Microsoft Entra ID with a certificate.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param configuration - Other parameters required, including the path of the certificate on the filesystem.\n * If the type is ignored, we will throw the value of the path to a PEM certificate.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n configuration: ClientCertificatePEMCertificatePath,\n options?: ClientCertificateCredentialOptions,\n );\n /**\n * Creates an instance of the ClientCertificateCredential with the details\n * needed to authenticate against Microsoft Entra ID with a certificate.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param configuration - Other parameters required, including the PEM-encoded certificate as a string.\n * If the type is ignored, we will throw the value of the PEM-encoded certificate.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n configuration: ClientCertificatePEMCertificate,\n options?: ClientCertificateCredentialOptions,\n );\n constructor(\n tenantId: string,\n clientId: string,\n certificatePathOrConfiguration: string | ClientCertificateCredentialPEMConfiguration,\n options: ClientCertificateCredentialOptions = {},\n ) {\n if (!tenantId || !clientId) {\n throw new Error(`${credentialName}: tenantId and clientId are required parameters.`);\n }\n\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.sendCertificateChain = options.sendCertificateChain;\n\n this.certificateConfiguration = {\n ...(typeof certificatePathOrConfiguration === \"string\"\n ? {\n certificatePath: certificatePathOrConfiguration,\n }\n : certificatePathOrConfiguration),\n };\n const certificate = (this.certificateConfiguration as ClientCertificatePEMCertificate)\n .certificate;\n const certificatePath = (this.certificateConfiguration as ClientCertificatePEMCertificatePath)\n .certificatePath;\n if (!this.certificateConfiguration || !(certificate || certificatePath)) {\n throw new Error(\n `${credentialName}: Provide either a PEM certificate in string form, or the path to that certificate in the filesystem. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n if (certificate && certificatePath) {\n throw new Error(\n `${credentialName}: To avoid unexpected behaviors, providing both the contents of a PEM certificate and the path to a PEM certificate is forbidden. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`,\n );\n }\n this.msalClient = createMsalClient(clientId, tenantId, {\n ...options,\n logger,\n tokenCredentialOptions: options,\n });\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(`${credentialName}.getToken`, options, async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];\n const certificate = await this.buildClientCertificate();\n return this.msalClient.getTokenByClientCertificate(arrayScopes, certificate, newOptions);\n });\n }\n\n private async buildClientCertificate(): Promise<CertificateParts> {\n const parts = await parseCertificate(\n this.certificateConfiguration,\n this.sendCertificateChain ?? false,\n );\n\n let privateKey: string;\n if (this.certificateConfiguration.certificatePassword !== undefined) {\n privateKey = createPrivateKey({\n key: parts.certificateContents,\n passphrase: this.certificateConfiguration.certificatePassword,\n format: \"pem\",\n })\n .export({\n format: \"pem\",\n type: \"pkcs8\",\n })\n .toString();\n } else {\n privateKey = parts.certificateContents;\n }\n\n return {\n thumbprint: parts.thumbprint,\n thumbprintSha256: parts.thumbprintSha256,\n privateKey,\n x5c: parts.x5c,\n };\n }\n}\n\n/**\n * Parses a certificate into its relevant parts\n *\n * @param certificateConfiguration - The certificate contents or path to the certificate\n * @param sendCertificateChain - true if the entire certificate chain should be sent for SNI, false otherwise\n * @returns The parsed certificate parts and the certificate contents\n */\nexport async function parseCertificate(\n certificateConfiguration: ClientCertificateCredentialPEMConfiguration,\n sendCertificateChain: boolean,\n): Promise<Omit<CertificateParts, \"privateKey\"> & { certificateContents: string }> {\n const certificate = (certificateConfiguration as ClientCertificatePEMCertificate).certificate;\n const certificatePath = (certificateConfiguration as ClientCertificatePEMCertificatePath)\n .certificatePath;\n const certificateContents = certificate || (await readFile(certificatePath!, \"utf8\"));\n const x5c = sendCertificateChain ? certificateContents : undefined;\n\n const certificatePattern =\n /(-+BEGIN CERTIFICATE-+)(\\n\\r?|\\r\\n?)([A-Za-z0-9+/\\n\\r]+=*)(\\n\\r?|\\r\\n?)(-+END CERTIFICATE-+)/g;\n const publicKeys: string[] = [];\n\n // Match all possible certificates, in the order they are in the file. These will form the chain that is used for x5c\n let match;\n do {\n match = certificatePattern.exec(certificateContents);\n if (match) {\n publicKeys.push(match[3]);\n }\n } while (match);\n\n if (publicKeys.length === 0) {\n throw new Error(\"The file at the specified path does not contain a PEM-encoded certificate.\");\n }\n\n const thumbprint = createHash(\"sha1\") // CodeQL [SM04514] Needed for backward compatibility reason\n .update(Buffer.from(publicKeys[0], \"base64\"))\n .digest(\"hex\")\n .toUpperCase();\n\n const thumbprintSha256 = createHash(\"sha256\")\n .update(Buffer.from(publicKeys[0], \"base64\"))\n .digest(\"hex\")\n .toUpperCase();\n\n return {\n certificateContents,\n thumbprintSha256,\n thumbprint,\n x5c,\n };\n}\n"]}
|
@@ -16,6 +16,10 @@ const logger = credentialLogger("ClientSecretCredential");
|
|
16
16
|
*
|
17
17
|
*/
|
18
18
|
export class ClientSecretCredential {
|
19
|
+
tenantId;
|
20
|
+
additionallyAllowedTenantIds;
|
21
|
+
msalClient;
|
22
|
+
clientSecret;
|
19
23
|
/**
|
20
24
|
* Creates an instance of the ClientSecretCredential with the details
|
21
25
|
* needed to authenticate against Microsoft Entra ID with a client
|
@@ -38,8 +42,12 @@ export class ClientSecretCredential {
|
|
38
42
|
}
|
39
43
|
this.clientSecret = clientSecret;
|
40
44
|
this.tenantId = tenantId;
|
41
|
-
this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options
|
42
|
-
this.msalClient = createMsalClient(clientId, tenantId,
|
45
|
+
this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options?.additionallyAllowedTenants);
|
46
|
+
this.msalClient = createMsalClient(clientId, tenantId, {
|
47
|
+
...options,
|
48
|
+
logger,
|
49
|
+
tokenCredentialOptions: options,
|
50
|
+
});
|
43
51
|
}
|
44
52
|
/**
|
45
53
|
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"clientSecretCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientSecretCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EACL,yBAAyB,EACzB,mCAAmC,GACpC,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC1D,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,wBAAwB,CAAC,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,OAAO,sBAAsB;
|
1
|
+
{"version":3,"file":"clientSecretCredential.js","sourceRoot":"","sources":["../../../src/credentials/clientSecretCredential.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;AAGlC,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,o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G,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,sBAAsB,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;QAC5F,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 type { ClientSecretCredentialOptions } from \"./clientSecretCredentialOptions.js\";\nimport { CredentialUnavailableError } from \"../errors.js\";\nimport { credentialLogger } from \"../util/logging.js\";\nimport { ensureScopes } from \"../util/scopeUtils.js\";\nimport { tracingClient } from \"../util/tracing.js\";\n\nconst logger = credentialLogger(\"ClientSecretCredential\");\n\n/**\n * Enables authentication to Microsoft Entra ID using a client secret\n * that was generated for an App Registration. More information on how\n * to configure a client secret can be found here:\n *\n * https://learn.microsoft.com/entra/identity-platform/quickstart-configure-app-access-web-apis#add-credentials-to-your-web-application\n *\n */\nexport class ClientSecretCredential implements TokenCredential {\n private tenantId: string;\n private additionallyAllowedTenantIds: string[];\n private msalClient: MsalClient;\n private clientSecret: string;\n\n /**\n * Creates an instance of the ClientSecretCredential with the details\n * needed to authenticate against Microsoft Entra ID with a client\n * secret.\n *\n * @param tenantId - The Microsoft Entra tenant (directory) ID.\n * @param clientId - The client (application) ID of an App Registration in the tenant.\n * @param clientSecret - A client secret that was generated for the App Registration.\n * @param options - Options for configuring the client which makes the authentication request.\n */\n constructor(\n tenantId: string,\n clientId: string,\n clientSecret: string,\n options: ClientSecretCredentialOptions = {},\n ) {\n if (!tenantId) {\n throw new CredentialUnavailableError(\n \"ClientSecretCredential: tenantId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.\",\n );\n }\n\n if (!clientId) {\n throw new CredentialUnavailableError(\n \"ClientSecretCredential: clientId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.\",\n );\n }\n\n if (!clientSecret) {\n throw new CredentialUnavailableError(\n \"ClientSecretCredential: clientSecret is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.\",\n );\n }\n\n this.clientSecret = clientSecret;\n this.tenantId = tenantId;\n this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(\n options?.additionallyAllowedTenants,\n );\n\n this.msalClient = createMsalClient(clientId, tenantId, {\n ...options,\n logger,\n tokenCredentialOptions: options,\n });\n }\n\n /**\n * Authenticates with Microsoft Entra ID and returns an access token if successful.\n * If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n async getToken(scopes: string | string[], options: GetTokenOptions = {}): Promise<AccessToken> {\n return tracingClient.withSpan(\n `${this.constructor.name}.getToken`,\n options,\n async (newOptions) => {\n newOptions.tenantId = processMultiTenantRequest(\n this.tenantId,\n newOptions,\n this.additionallyAllowedTenantIds,\n logger,\n );\n\n const arrayScopes = ensureScopes(scopes);\n return this.msalClient.getTokenByClientSecret(arrayScopes, this.clientSecret, newOptions);\n },\n );\n }\n}\n"]}
|
@@ -1,20 +1,6 @@
|
|
1
1
|
import type { DefaultAzureCredentialClientIdOptions, DefaultAzureCredentialOptions, DefaultAzureCredentialResourceIdOptions } from "./defaultAzureCredentialOptions.js";
|
2
2
|
import { ChainedTokenCredential } from "./chainedTokenCredential.js";
|
3
3
|
import type { TokenCredential } from "@azure/core-auth";
|
4
|
-
/**
|
5
|
-
* Creates a {@link ManagedIdentityCredential} from the provided options.
|
6
|
-
* @param options - Options to configure the credential.
|
7
|
-
*
|
8
|
-
* @internal
|
9
|
-
*/
|
10
|
-
export declare function createDefaultManagedIdentityCredential(options?: DefaultAzureCredentialOptions | DefaultAzureCredentialResourceIdOptions | DefaultAzureCredentialClientIdOptions): TokenCredential;
|
11
|
-
/**
|
12
|
-
* Creates an {@link EnvironmentCredential} from the provided options.
|
13
|
-
* @param options - Options to configure the credential.
|
14
|
-
*
|
15
|
-
* @internal
|
16
|
-
*/
|
17
|
-
export declare function createEnvironmentCredential(options?: DefaultAzureCredentialOptions): TokenCredential;
|
18
4
|
/**
|
19
5
|
* A no-op credential that logs the reason it was skipped if getToken is called.
|
20
6
|
* @internal
|
@@ -35,12 +21,24 @@ export declare class UnavailableDefaultCredential implements TokenCredential {
|
|
35
21
|
* - {@link EnvironmentCredential}
|
36
22
|
* - {@link WorkloadIdentityCredential}
|
37
23
|
* - {@link ManagedIdentityCredential}
|
24
|
+
* - {@link VisualStudioCodeCredential}
|
38
25
|
* - {@link AzureCliCredential}
|
39
26
|
* - {@link AzurePowerShellCredential}
|
40
27
|
* - {@link AzureDeveloperCliCredential}
|
41
28
|
*
|
42
29
|
* Consult the documentation of these credential types for more information
|
43
30
|
* on how they attempt authentication.
|
31
|
+
*
|
32
|
+
* Selecting credentials
|
33
|
+
*
|
34
|
+
* Set environment variable AZURE_TOKEN_CREDENTIALS to select a subset of the credential chain.
|
35
|
+
* DefaultAzureCredential will try only the specified credential(s), but its other behavior remains the same.
|
36
|
+
* Valid values for AZURE_TOKEN_CREDENTIALS are the name of any single type in the above chain, for example
|
37
|
+
* "EnvironmentCredential" or "AzureCliCredential", and these special values:
|
38
|
+
*
|
39
|
+
* - "dev": try [VisualStudioCodeCredential], [AzureCliCredential], [AzurePowerShellCredential] and [AzureDeveloperCliCredential], in that order
|
40
|
+
* - "prod": try [EnvironmentCredential], [WorkloadIdentityCredential], and [ManagedIdentityCredential], in that order
|
41
|
+
*
|
44
42
|
*/
|
45
43
|
export declare class DefaultAzureCredential extends ChainedTokenCredential {
|
46
44
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"defaultAzureCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/defaultAzureCredential.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qCAAqC,EACrC,6BAA6B,EAC7B,uCAAuC,EACxC,MAAM,oCAAoC,CAAC;
|
1
|
+
{"version":3,"file":"defaultAzureCredential.d.ts","sourceRoot":"","sources":["../../../src/credentials/defaultAzureCredential.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qCAAqC,EACrC,6BAA6B,EAC7B,uCAAuC,EACxC,MAAM,oCAAoC,CAAC;AAO5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAgBxD;;;GAGG;AACH,qBAAa,4BAA6B,YAAW,eAAe;IAClE,iCAAiC,EAAE,MAAM,CAAC;IAC1C,cAAc,EAAE,MAAM,CAAC;gBAEX,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAKnD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAM1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;IAChE;;;;OAIG;gBACS,OAAO,CAAC,EAAE,qCAAqC;IAE3D;;;;OAIG;gBACS,OAAO,CAAC,EAAE,uCAAuC;IAE7D;;;;OAIG;gBACS,OAAO,CAAC,EAAE,6BAA6B;CAoFpD"}
|