Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The Databricks JDBC Driver supports multiple authentication methods depending on your use case. This page describes how to configure each method and lists the required connection properties.
To configure authentication for the Databricks JDBC Driver, use one of the following methods:
- OAuth 2.0 token pass-through (including token federation with external identity providers)
- OAuth user-to-machine (U2M) authentication
- OAuth machine-to-machine (M2M) authentication
- Databricks personal access token
OAuth 2.0 token pass-through
The JDBC driver accepts OAuth tokens in the Auth_AccessToken property. You can pass either a Azure Databricks OAuth token directly, or a JSON Web Token (JWT) from an external identity provider. If you pass an external IdP token, Azure Databricks automatically exchanges it for a Azure Databricks token using token federation.
In the following examples, replace the following placeholders:
<oauth-token>with a Azure Databricks OAuth 2.0 token or an external IdP JWT.- To get the values for
<server-hostname>and<http-path>, see Configure a connection to Databricks using the Databricks JDBC Driver.
The required properties are:
AuthMechset to11(OAuth 2.0 authentication)Auth_Flowset to0(token pass-through mode)Auth_AccessTokenset to a Azure Databricks OAuth token or an external IdP JWT
See Authentication properties.
For a JDBC connection URL:
jdbc:databricks://<server-hostname>:443;httpPath=<http-path>;AuthMech=11;Auth_Flow=0;Auth_AccessToken=<oauth-token>
In Java code:
// ...
String url = "jdbc:databricks://<server-hostname>:443";
Properties p = new java.util.Properties();
p.put("httpPath", "<http-path>");
p.put("AuthMech", "11");
p.put("Auth_Flow", "0");
p.put("Auth_AccessToken", "<oauth-token>");
// ...
Connection conn = DriverManager.getConnection(url, p);
// ...
Token federation with an external identity provider
If you authenticate with a token from an external identity provider such as Okta, Microsoft Entra ID, Keycloak, or any OIDC-compliant IdP, Azure Databricks performs the token exchange automatically. The JDBC configuration is the same as token pass-through. Pass the IdP token in Auth_AccessToken and the driver handles the rest.
Before using token federation, you must:
- Create a federation policy in your Azure Databricks account that trusts the external IdP. A federation policy specifies the issuer URL, expected audience values, and the JWT claim used to map to an Azure Databricks user. See Authenticate access to Azure Databricks using OAuth token federation.
- Verify that a matching Azure Databricks user exists. The user's email or other identifier must match the
subject_claimvalue in the JWT. - Verify that the IdP's OIDC discovery endpoint is publicly reachable so Azure Databricks can fetch signing keys to verify the token.
OAuth user-to-machine (U2M) authentication
OAuth U2M authentication lets you sign in to Azure Databricks through a browser. The driver opens a browser window, you authenticate, and the driver receives an OAuth token. The driver uses the built-in OAuth client ID databricks-sql-jdbc.
This authentication type has no prerequisites. Tokens have a default lifetime of one hour and refresh automatically when they expire.
Note
OAuth U2M works only with locally run applications. It doesn't work with server-based or cloud-based applications.
In the following examples, replace the following placeholders:
<passphrase>with a passphrase of your choice. The driver uses this key for refresh token encryption.- To get the values for
<server-hostname>and<http-path>, see Configure a connection to Databricks using the Databricks JDBC Driver.
The required properties are:
AuthMechset to11(OAuth 2.0 authentication)Auth_Flowset to2(U2M browser-based mode)TokenCachePassPhraseset to the passphrase used to encrypt your cached OAuth U2M credentials. This prevents repeated browser-based authentications. To opt out of token caching, setEnableTokenCacheto0.
See Authentication properties.
In a JDBC connection URL:
jdbc:databricks://<server-hostname>:443;httpPath=<http-path>;AuthMech=11;Auth_Flow=2;TokenCachePassPhrase=<passphrase>;EnableTokenCache=0
In Java code:
// ...
String url = "jdbc:databricks://<server-hostname>:443";
Properties p = new java.util.Properties();
p.put("httpPath", "<http-path>");
p.put("AuthMech", "11");
p.put("Auth_Flow", "2");
p.put("TokenCachePassPhrase", "<passphrase>");
p.put("EnableTokenCache", "0");
// ...
Connection conn = DriverManager.getConnection(url, p);
// ...
OAuth machine-to-machine (M2M) authentication
The JDBC driver supports OAuth machine-to-machine (M2M) authentication using one of the following principals or identity. See Authorize service principal access to Azure Databricks with OAuth.
- A Databricks service principal
- An Azure managed service principal
- An Azure managed identity (system-assigned or user-assigned)
M2M using Databricks managed service principal
To configure authentication using a Databricks managed service principal:
Create a Databricks managed service-principal and assign it to Databricks accounts and workspaces.
Create a Databricks OAuth secret for the service principal. See Manually generate OAuth M2M access tokens.
Grant access permissions to clusters and SQL warehouses.
Add the following properties to your existing JDBC connection URL or
java.util.Propertiesobject:AuthMechset to11(OAuth 2.0 authentication)Auth_Flowset to1(M2M client credentials mode)OAuth2ClientIDset to the service principal's Application (client) ID valueOAuth2Secretset to the service principal's Databricks OAuth secret
M2M using Azure managed service principal
To configure authentication using an Azure managed service principal:
Create a Databricks OAuth secret for the service principal. See Manually generate OAuth M2M access tokens.
Grant access permissions to clusters and SQL warehouses.
Add the following properties to your existing JDBC connection URL or
java.util.Propertiesobject:AuthMechset to11(OAuth 2.0 authentication)Auth_Flowset to1(M2M client credentials mode)OAuth2ClientIDset to the service principal's Application (client) ID valueAzureTenantIDset to the Azure tenant ID found in Azure Active DirectoryOAuth2Secretset to the service principal's Databricks OAuth secret
M2M using Azure managed identities
To configure authentication using Azure managed identities:
Configure managed identities for your Azure resources.
Grant access permissions to clusters and SQL warehouses.
Add the following properties to your existing JDBC connection URL or
java.util.Propertiesobject:AuthMechset to11(OAuth 2.0 authentication)Auth_Flowset to3(managed identity mode)OAuth2ClientIDset to the Client ID of the managed identity. This is required only if you're using a user-assigned managed identity.Azure_workspace_resource_idset to your Databricks workspace's Azure Resource ID
Databricks personal access token
Note
Personal access tokens are best for testing scenarios. Azure Databricks recommends more secure authentication types for production scenarios.
To create a Databricks personal access token, follow the steps in Create personal access tokens for workspace users.
In the following examples, replace the following placeholders:
<personal-access-token>with the Databricks personal access token for your workspace user.- To get the values for
<server-hostname>and<http-path>, see Configure a connection to Databricks using the Databricks JDBC Driver.
The required properties are:
AuthMechset to3(token authentication)UIDset to the literal stringtokenPWDorpasswordset to your Databricks personal access token value
See Authentication properties.
In a JDBC connection URL:
jdbc:databricks://<server-hostname>:443;httpPath=<http-path>;AuthMech=3;UID=token;PWD=<personal-access-token>
In Java code:
// ...
String url = "jdbc:databricks://<server-hostname>:443";
Properties p = new java.util.Properties();
p.put("httpPath", "<http-path>");
p.put("AuthMech", "3");
p.put("UID", "token");
p.put("PWD", "<personal-access-token>");
// ...
Connection conn = DriverManager.getConnection(url, p);
// ...