Get Microsoft Entra ID (formerly Azure Active Directory) tokens for users by using the Azure CLI
Important
This article describes how to manually create Microsoft Entra ID tokens for users by using the Azure CLI.
Databricks does not recommend that you create Microsoft Entra ID tokens for Azure Databricks users manually. This is because each Microsoft Entra ID token is short-lived, typically expiring within one hour. After this time, you must manually generate a replacement Microsoft Entra ID token. Instead, use one of the participating tools or SDKs that implement the Databricks client unified authentication standard. These tools and SDKs automatically generate and replace expired Microsoft Entra ID tokens for you, leveraging the following Databricks authentication types:
You can use the Azure CLI to get Microsoft Entra ID access tokens for users.
Note
You can also define a service principal in Azure Active Directory and then get a Microsoft Entra ID access token for that service principal instead of for a user. See Get Microsoft Entra ID (formerly Azure AD) tokens for service principals.
Begin signing in to Azure by using the Azure CLI to run the az login command. Use the
--outputoption to display the command’s output in a different format (in this case, a table instead of JSON) for better readability. After you run this command, follow the on-screen instructions to finish signing in with your account.az login --output tableConfirm that you are signed in to the correct subscription for which you want to create your Microsoft Entra ID access token. To do this, in the output of the
az logincommand, look for the table row whereIsDefaultis set toTrue. The subscription’sNameindicates the current subscription.If you are not sure what the correct subscription should be, see Get subscription and tenant IDs in the Azure portal. Or, try running the
az databricks workspace listcommand later in this step.If you need to switch to a different subscription, run the az account set command, using the
--nameor--subscriptionoption to specify the correct subscription name or ID.az account set --name "<subscription-name>" # Or ... az account set --subscription <subscription-id>You can get the subscription ID for an Azure Databricks workspace by clicking your username > Azure Portal in the workspace navigation bar. On the Azure Databricks workspace resource page that appears, click Overview in the sidebar. Then look for the Subscription ID field, which contains the subscription ID.
If you do not have access to the Azure Portal, you can get the subscription ID for an Azure Databricks workspace by running the az databricks workspace list command, using the
--queryand--outputoptions to narrow down the results. Replaceadb-0000000000000000.0.azuredatabricks.netwith the name of your workspace instance, not including thehttps://. In this example, the00000000-0000-0000-0000-000000000000after/subscriptions/in the output is the subscription ID.az databricks workspace list --query "[?workspaceUrl==\`adb-0000000000000000.0.azuredatabricks.net\`].{id:id}" --output tsv # /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-rg/providers/Microsoft.Databricks/workspaces/my-wsIf the following message displays, you are signed in to the wrong tenant:
The subscription of '<subscription-id>' doesn't exist in cloud 'AzureCloud'.To sign in to the correct tenant, you must run theaz logincommand again, using the--tenantoption to specify the correct tenant ID.You can get the tenant ID for an Azure Databricks workspace by running the command
curl -v <per-workspace-URL>/aad/authand looking in the output< location: https://login.microsoftonline.com/00000000-0000-0000-0000-000000000000, where00000000-0000-0000-0000-000000000000is the tenant ID. See also Get subscription and tenant IDs in the Azure portal.az login --tenant <tenant-id> --output tableGenerate your Microsoft Entra ID access token by running the az account get-access-token command. Use the
--resourceoption to specify the unique resource ID for the Azure Databricks service, which is2ff814a6-3304-4ab8-85cb-cd0e6f879c1d. You can display just the Microsoft Entra ID token’s value in the output of the command by using the--queryand--outputoptions.az account get-access-token \ --resource 2ff814a6-3304-4ab8-85cb-cd0e6f879c1d \ --query "accessToken" \ --output tsv
Note
The MSAL-based Azure CLI uses Microsoft Authentication Library (MSAL) as the underlying authentication library. If you are not able to successfully use the Microsoft Entra ID access token that the Azure CLI generates, as an alternative you can try using MSAL directly to get a Microsoft Entra ID access token for a user. See Get Microsoft Entra ID (formerly Azure Active Directory) tokens for users by using MSAL.
Feedback
Submit and view feedback for