Skip to content

feat(database): add databricks oauth support - #34619

Closed
drummerwolli wants to merge 4 commits into
apache:masterfrom
drummerwolli:databricks-oauth
Closed

drummerwolli wants to merge 4 commits into
apache:masterfrom
drummerwolli:databricks-oauth

Conversation

@drummerwolli

Copy link
Copy Markdown
Contributor

SUMMARY

OAuth 2.0 support for Databricks

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

tbd

TESTING INSTRUCTIONS

  • set up oauth config in superset_config.py for databricks as described in the newly added docs
  • install databricks dependencies
  • run superset
  • set up a DB connection to Databricks
  • run a Query with that newly created connection and notice the Oauth login screen.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@github-actions github-actions Bot added the doc Namespace | Anything related to documentation label Aug 8, 2025
@dosubot dosubot Bot added the data:connect Namespace | Anything related to db connections / integrations label Aug 8, 2025

@korbit-ai korbit-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Design Duplicated OAuth2 Configuration ▹ view ✅ Fix detected
Security OAuth Client Secrets Exposed in Config File ▹ view 🧠 Incorrect
Functionality Hardcoded OAuth2 endpoints limit cloud provider support ▹ view ✅ Fix detected
Files scanned ​
File Path Reviewed
superset/db_engine_specs/databricks.py ✅
docs/docs/configuration/databases.mdx ✅

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

Comment thread superset/db_engine_specs/databricks.py Outdated
Comment on lines +455 to +460
oauth2_authorization_request_uri = (
"https://accounts.cloud.databricks.com/oidc/accounts/{}/v1/authorize"
)
oauth2_token_request_uri = (
"https://accounts.cloud.databricks.com/oidc/accounts/{}/v1/token" # noqa: S105
)

This comment was marked as resolved.

Comment thread superset/db_engine_specs/databricks.py Outdated
Comment on lines +455 to +457
oauth2_authorization_request_uri = (
"https://accounts.cloud.databricks.com/oidc/accounts/{}/v1/authorize"
)

This comment was marked as resolved.

Comment on lines +539 to +546
DATABASE_OAUTH2_CLIENTS = {
"Databricks (legacy)": {
"id": "your-databricks-client-id",
"secret": "your-databricks-client-secret",
"scope": "sql",
"authorization_request_uri": "https://accounts.cloud.databricks.com/oidc/accounts/{account_id}/v1/authorize",
"token_request_uri": "https://accounts.cloud.databricks.com/oidc/accounts/{account_id}/v1/token",
},

This comment was marked as resolved.

@codecov

codecov Bot commented Aug 8, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 38.09524% with 39 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.78%. Comparing base (1d08665) to head (1f7898c).

Files with missing lines Patch % Lines
superset/db_engine_specs/databricks.py 38.09% 39 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #34619      +/-   ##
==========================================
- Coverage   64.37%   63.78%   -0.59%     
==========================================
  Files        2653     2653              
  Lines      145177   145240      +63     
  Branches    33495    33503       +8     
==========================================
- Hits        93457    92643     -814     
- Misses      50025    50900     +875     
- Partials     1695     1697       +2     
Flag Coverage Δ
hive 39.24% <38.09%> (-0.01%) ⬇️
mysql 57.95% <38.09%> (-0.02%) ⬇️
postgres 58.02% <38.09%> (-0.03%) ⬇️
presto 40.82% <38.09%> (-0.01%) ⬇️
python 58.23% <38.09%> (-1.25%) ⬇️
sqlite 57.67% <38.09%> (-0.02%) ⬇️
unit ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@drummerwolli
drummerwolli marked this pull request as draft August 8, 2025 13:56
@drummerwolli

Copy link
Copy Markdown
Contributor Author

I'm currently testing this internally and will report back here, hence there might not be any visible activity in this PR in the next days.

@rusackas
rusackas marked this pull request as ready for review June 23, 2026 18:47
@dosubot dosubot Bot added authentication:sso Single Sign On data:connect:databricks Databricks DB Experience labels Jun 23, 2026
@rusackas

Copy link
Copy Markdown
Member

@drummerwolli checking back in on this, the Databricks OAuth support looks worth landing. Did the internal testing pan out? It'll need a rebase and a unit-test fix to go green, so I'll tacke this now and leave it open for further review.

@bito-code-review bito-code-review Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent Run #6cc2a6

Actionable Suggestions - 1
  • superset/db_engine_specs/databricks.py - 1
    • CWE-20: Unformatted Placeholders in OAuth2 URI · Line 731-733
Additional Suggestions - 1
  • tests/unit_tests/db_engine_specs/test_databricks.py - 1
    • SEMANTIC_DUPLICATION | Test consolidation needed · Line 660-694
      This test is semantically identical to `test_get_oauth2_fresh_token_native` (lines 623-657). Neither `DatabricksNativeEngineSpec` nor `DatabricksPythonConnectorEngineSpec` overrides `get_oauth2_fresh_token`, so both call the same `BaseEngineSpec` implementation with identical configuration. Consider consolidating or testing a meaningful behavioral difference.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • tests/unit_tests/db_engine_specs/test_databricks.py - 1
  • docs/docs/configuration/databases.mdx - 1
  • superset/db_engine_specs/databricks.py - 1
Review Details
  • Files reviewed - 4 · Commit Range: 732f66b..0b786fc
    • docs/docs/configuration/databases.mdx
    • superset/db_engine_specs/databricks.py
    • tests/unit_tests/db_engine_specs/test_databricks.py
    • tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Comment on lines +731 to +733
"authorization_request_uri": cls._oauth2_endpoints[provider][
"authorization_request_uri"
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CWE-20: Unformatted Placeholders in OAuth2 URI

OAuth2 endpoints contain {} placeholders for account/tenant IDs that are never filled. Azure authorization will request https://login.microsoftonline.com//oauth2/v2.0/authorize (double slash) because {} is passed literally. AWS/GCP will similarly receive malformed URIs. Extract the appropriate ID from database.extra JSON (e.g., aws_account_id, azure_tenant_id) and call .format(account_id) on the endpoint string before use. (CWE-20)

Code suggestion
Check the AI-generated fix before applying
              provider = cls._detect_cloud_provider(database)
 +            import json
 +            extra_config = json.loads(database.extra or "{}")
 +
 +            # Get the appropriate account/tenant ID for the provider
 +            account_id = (
 +                extra_config.get("azure_tenant_id") or
 +                extra_config.get("aws_account_id") or
 +                ""
 +            )
 +
              from typing import cast
 
              config = cast(
                  "OAuth2ClientConfig",
                  dict(config)
                  | {
                      "authorization_request_uri": cls._oauth2_endpoints[provider][
 -                        "authorization_request_uri"
 -                    ]
 +                        "authorization_request_uri"
 +                    ].format(account_id)
                  },
              )
 
          return super().get_oauth2_authorization_uri(config, state)

Code Review Run #6cc2a6


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them



@pytest.fixture
def mock_database_aws(mocker: MockerFixture):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add an explicit return type annotation to this fixture so the new function is fully typed. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This is a newly added Python fixture function and it lacks a return type annotation.
The rule requires new Python functions to be fully typed, including return values.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py
**Line:** 35:35
**Comment:**
	*Custom Rule: Add an explicit return type annotation to this fixture so the new function is fully typed.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

}


def test_cloud_provider_detection_aws(mock_database_aws) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add a concrete type hint for the fixture argument used by this test function. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This new test function has an untyped parameter, mock_database_aws.
The custom rule requires newly added Python functions to be fully typed, so this is a real violation.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py
**Line:** 86:86
**Comment:**
	*Custom Rule: Add a concrete type hint for the fixture argument used by this test function.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +128 to +132
def test_get_oauth2_authorization_uri_aws(
mocker: MockerFixture,
oauth2_config: OAuth2ClientConfig,
mock_database_aws,
) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add a type annotation for the mock_database_aws parameter in this new test function signature. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

The function is newly added and one of its parameters, mock_database_aws, has no type annotation.
That violates the rule requiring new Python functions to be fully typed.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py
**Line:** 128:132
**Comment:**
	*Custom Rule: Add a type annotation for the `mock_database_aws` parameter in this new test function signature.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +160 to +164
def test_get_oauth2_authorization_uri_azure(
mocker: MockerFixture,
oauth2_config: OAuth2ClientConfig,
mock_database_azure,
) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add a type annotation for the untyped fixture parameter in this function signature. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

This is a new function and it includes an untyped parameter, mock_database_azure.
The rule explicitly requires full type hints for new Python functions, so the suggestion is valid.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py
**Line:** 160:164
**Comment:**
	*Custom Rule: Add a type annotation for the untyped fixture parameter in this function signature.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +233 to +237
def test_python_connector_oauth2_authorization_uri_azure(
mocker: MockerFixture,
oauth2_config: OAuth2ClientConfig,
mock_database_azure,
) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Add a type hint for the mock_database_azure argument so all parameters in this new function are typed. [custom_rule]

Severity Level: Minor ⚠️

Why it matters? 🤔

The new test function has an untyped parameter, mock_database_azure.
This matches the custom rule that newly added Python functions must be fully typed.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py
**Line:** 233:237
**Comment:**
	*Custom Rule: Add a type hint for the `mock_database_azure` argument so all parameters in this new function are typed.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@netlify

netlify Bot commented Jun 24, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 1f7898c
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a3b53ecbb90210008d26d00
😎 Deploy Preview https://deploy-preview-34619--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines +287 to +300
_oauth2_endpoints = {
"aws": {
"authorization_request_uri": "https://accounts.cloud.databricks.com/oidc/accounts/{}/v1/authorize",
"token_request_uri": "https://accounts.cloud.databricks.com/oidc/accounts/{}/v1/token",
},
"azure": {
"authorization_request_uri": "https://login.microsoftonline.com/{}/oauth2/v2.0/authorize",
"token_request_uri": "https://login.microsoftonline.com/{}/oauth2/v2.0/token",
},
"gcp": {
"authorization_request_uri": "https://accounts.gcp.databricks.com/oidc/accounts/{}/v1/authorize",
"token_request_uri": "https://accounts.gcp.databricks.com/oidc/accounts/{}/v1/token",
},
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The OAuth endpoint templates contain {} placeholders but no formatting step ever fills them with account/tenant identifiers. This generates invalid authorization/token URLs (for example paths with empty or literal placeholder segments), causing OAuth requests to fail against real providers. Build concrete URIs from required config values before sending users to OAuth endpoints. [api mismatch]

Severity Level: Critical 🚨
- ❌ Databricks OAuth2 login redirects to invalid authorization URLs.
- ⚠️ Users cannot complete OAuth2 authentication for Databricks.
Steps of Reproduction ✅
1. Configure an OAuth2 client for Databricks (either globally in `DATABASE_OAUTH2_CLIENTS`
or per-database in `encrypted_extra["oauth2_client_info"]`) so that
`Database.get_oauth2_config()` returns a valid `OAuth2ClientConfig` (see
`superset/models/core.py:33-43` and `superset/db_engine_specs/base.py:725-175`).

2. Trigger OAuth2 for a Databricks database (native or Python connector) without an
existing token, so `Database.start_oauth2_dance()` calls
`db_engine_spec.start_oauth2_dance(self)`; `BaseEngineSpec.start_oauth2_dance` at
`superset/db_engine_specs/base.py:643-143` then calls
`cls.get_oauth2_authorization_uri(oauth2_config, state, code_verifier=...)`.

3. In `DatabricksNativeEngineSpec.get_oauth2_authorization_uri` or
`DatabricksPythonConnectorEngineSpec.get_oauth2_authorization_uri`
(`superset/db_engine_specs/databricks.py:158-188` and `435-465`), the method detects the
cloud provider via `_detect_cloud_provider` and overwrites
`config["authorization_request_uri"]` with the corresponding template from
`_oauth2_endpoints` defined at `superset/db_engine_specs/databricks.py:287-300`, such as
`"https://accounts.cloud.databricks.com/oidc/accounts/{}/v1/authorize"`, without
substituting the `{}` placeholder.

4. `BaseEngineSpec.get_oauth2_authorization_uri` at
`superset/db_engine_specs/base.py:178-206` then uses this unformatted template as `uri`
and appends query parameters, producing an authorization URL whose path still contains
`"{}"` instead of an account/tenant identifier, leading the identity provider
(Databricks/Azure/GCP) to reject or 404 the request when the browser is redirected.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/db_engine_specs/databricks.py
**Line:** 287:300
**Comment:**
	*Api Mismatch: The OAuth endpoint templates contain `{}` placeholders but no formatting step ever fills them with account/tenant identifiers. This generates invalid authorization/token URLs (for example paths with empty or literal placeholder segments), causing OAuth requests to fail against real providers. Build concrete URIs from required config values before sending users to OAuth endpoints.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +549 to +551
supports_oauth2 = True
oauth2_exception = OAuth2RedirectError
oauth2_scope = "sql"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: OAuth2 is enabled without enforcing per-user query caching for this engine. Since authentication becomes user-token based, shared cache entries can be reused across users unless per-user caching is forced, which can leak one user's results to another. Add backend enforcement so OAuth2-enabled Databricks connections always use per-user cache keys. [cache]

Severity Level: Critical 🚨
- ❌ Databricks OAuth2 query cache entries may leak between users.
- ⚠️ Cache behavior conflicts with per-user auth expectations.
- ⚠️ Security posture weaker than required for OAuth2 engines.
Steps of Reproduction ✅
1. Observe that `DatabricksNativeEngineSpec` and `DatabricksPythonConnectorEngineSpec`
declare `supports_oauth2 = True` and define `impersonate_user` to inject a per-user OAuth2
access token into the SQLAlchemy URL/connect_args at
`superset/db_engine_specs/databricks.py:328-349` and `116-139`, while
`Database._get_sqla_engine` in `superset/models/core.py:28-49` calls
`self.db_engine_spec.impersonate_user(self, effective_username, access_token,
sqlalchemy_url, engine_kwargs)` when `self.impersonate_user` is true.

2. Query caching keys are constructed in `viz.BaseViz.cache_key` at
`superset/viz.py:504-513`, which calls
`add_impersonation_cache_key_if_needed(self.datasource.database, cache_dict)` before
hashing, so per-user cache separation only happens if that helper adds an
`"impersonation_key"`.

3. `add_impersonation_cache_key_if_needed` in `superset/utils/cache_keys.py:33-25` adds an
impersonation-based cache key only when one of the following holds: (a) feature flag
`CACHE_IMPERSONATION` is enabled and `database.impersonate_user` is true, (b) feature flag
`CACHE_QUERY_BY_USER` is enabled, or (c) `database.extra` JSON sets `"per_user_caching":
true`; it does not automatically enforce per-user cache keys for OAuth2-enabled engines.

4. In a Databricks OAuth2 configuration where `supports_oauth2` is true, the connection
uses per-user tokens via `impersonate_user`, but the admin has neither enabled
`per_user_caching` nor the relevant feature flags, different users issuing the same query
against the same Databricks database will get identical cache keys and share cached
results, potentially exposing one user's query results to another despite authentication
being per-user.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/db_engine_specs/databricks.py
**Line:** 549:551
**Comment:**
	*Cache: OAuth2 is enabled without enforcing per-user query caching for this engine. Since authentication becomes user-token based, shared cache entries can be reused across users unless per-user caching is forced, which can leak one user's results to another. Add backend enforcement so OAuth2-enabled Databricks connections always use per-user cache keys.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +555 to +556
oauth2_token_request_uri = "" # Set dynamically

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The class declares an empty default token endpoint while relying on base refresh-token logic, which uses config["token_request_uri"] directly. With the documented auto-detection setup (no explicit token URI), refresh requests will call an empty URL and fail at runtime. Ensure a concrete token endpoint is resolved for refresh flows too, not only initial code exchange. [incomplete implementation]

Severity Level: Major ⚠️
- ❌ Databricks OAuth2 access tokens cannot be refreshed.
- ⚠️ Users lose connectivity once initial tokens expire.
- ⚠️ Admins cannot rely on documented optional token URI default.
Steps of Reproduction ✅
1. Configure a Databricks OAuth2 client only with `id` and `secret` in
`DATABASE_OAUTH2_CLIENTS` (leaving `"token_request_uri"` unset), so
`BaseEngineSpec.get_oauth2_config` at `superset/db_engine_specs/base.py:725-175` builds a
config where `config["token_request_uri"]` falls back to `cls.oauth2_token_request_uri`.

2. For `DatabricksNativeEngineSpec` or `DatabricksPythonConnectorEngineSpec`,
`oauth2_token_request_uri` is explicitly set to an empty string at
`superset/db_engine_specs/databricks.py:555-556` and `432-433`, so
`config["token_request_uri"]` becomes `""` when no explicit token URI is provided.

3. After an initial token has been obtained (despite other issues), when the access token
expires, `superset/utils/oauth2.get_oauth2_access_token` at
`superset/utils/oauth2.py:9-45` calls `refresh_oauth2_token`, which in turn calls
`db_engine_spec.get_oauth2_fresh_token(config, token.refresh_token)` using the same
`config` with `token_request_uri=""`.

4. Since Databricks specs do not override `get_oauth2_fresh_token`,
`BaseEngineSpec.get_oauth2_fresh_token` at `superset/db_engine_specs/base.py:244-260` uses
`config["token_request_uri"]` as `uri` in `requests.post(uri, data=req_body,
timeout=timeout)`; with `uri=""`, the HTTP client raises an invalid-URL error and token
refresh fails, breaking Databricks OAuth2 connections once tokens expire when admins rely
on engine defaults for the token URI.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/db_engine_specs/databricks.py
**Line:** 555:556
**Comment:**
	*Incomplete Implementation: The class declares an empty default token endpoint while relying on base refresh-token logic, which uses `config["token_request_uri"]` directly. With the documented auto-detection setup (no explicit token URI), refresh requests will call an empty URL and fail at runtime. Ensure a concrete token endpoint is resolved for refresh flows too, not only initial code exchange.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +607 to +611
"OAuth2ClientConfig",
dict(config)
| {"token_request_uri": cls._oauth2_endpoints["aws"]["token_request_uri"]},
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Token exchange is hardcoded to AWS endpoints for all Databricks providers. For Azure and GCP connections this sends authorization codes to the wrong token endpoint, which will fail token exchange and break OAuth login. Use the same provider-specific endpoint resolution used for authorization URI generation. [api mismatch]

Severity Level: Critical 🚨
- ❌ Azure Databricks OAuth2 login fails at token exchange.
- ❌ GCP Databricks OAuth2 login fails at token exchange.
- ⚠️ Multi-cloud Databricks OAuth2 support is effectively unusable.
Steps of Reproduction ✅
1. Configure a Databricks database whose hostname indicates Azure or GCP (e.g.
`adb-...azuredatabricks.net` or `...gcp.databricks.com`) so that `_detect_cloud_provider`
in `superset/db_engine_specs/databricks.py:303-326` returns `"azure"` or `"gcp"`, and set
up a valid OAuth2 client so `Database.get_oauth2_config()` succeeds.

2. Complete the OAuth2 authorization step so the provider (Azure or GCP) redirects back to
Superset with an authorization `code`; `DatabaseOAuth2Command.run` in
`superset/commands/database/oauth2.py:40-39` then retrieves `oauth2_config` via
`self._database.get_oauth2_config()` and calls
`self._database.db_engine_spec.get_oauth2_token(oauth2_config, code, code_verifier)`.

3. In `DatabricksNativeEngineSpec.get_oauth2_token` and
`DatabricksPythonConnectorEngineSpec.get_oauth2_token`
(`superset/db_engine_specs/databricks.py:191-213` and `468-490`), the code constructs a
new config via `dict(config) | {"token_request_uri":
cls._oauth2_endpoints["aws"]["token_request_uri"]}`, forcing the token exchange to always
target the AWS Databricks token endpoint defined in
`_oauth2_endpoints["aws"]["token_request_uri"]` regardless of the actual cloud provider.

4. `BaseEngineSpec.get_oauth2_token` at `superset/db_engine_specs/base.py:209-241` then
POSTs the Azure- or GCP-issued authorization code to this AWS endpoint, which will reject
the foreign code, causing an HTTP error and preventing `DatabaseOAuth2Command.run` from
storing any tokens for non-AWS Databricks deployments.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/db_engine_specs/databricks.py
**Line:** 607:611
**Comment:**
	*Api Mismatch: Token exchange is hardcoded to AWS endpoints for all Databricks providers. For Azure and GCP connections this sends authorization codes to the wrong token endpoint, which will fail token exchange and break OAuth login. Use the same provider-specific endpoint resolution used for authorization URI generation.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@bito-code-review

bito-code-review Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #8b6a9f

Actionable Suggestions - 0
Additional Suggestions
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

Review Details
  • Files reviewed - 4 · Commit Range: 14139b9..1f7898c
    • docs/user_docs_versioned_docs/version-6.0.0/configuration/databases.mdx
    • superset/db_engine_specs/databricks.py
    • tests/unit_tests/db_engine_specs/test_databricks.py
    • tests/unit_tests/db_engine_specs/test_databricks_multi_cloud.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@drummerwolli

Copy link
Copy Markdown
Contributor Author

@rusackas unfortunately we pivoted away from Databricks and are moving now to Databricks native tooling now instead (Dashboards, SQL Editor, Genie). So there is no interest anymore from my side to continue here. i'm happy if someone else wants to pick up where i left off.

@rusackas

Copy link
Copy Markdown
Member

Thanks for the honest update @drummerwolli, and no worries at all. The OAuth support still looks worth landing, so I'll adopt this and carry it the rest of the way including getting the unit tests green. Appreciate the work you put in here.

@rusackas

Copy link
Copy Markdown
Member

Closing in favor of #41421. Thanks again @drummerwolli

@rusackas rusackas closed this Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

authentication:sso Single Sign On data:connect:databricks Databricks DB Experience data:connect Namespace | Anything related to db connections / integrations doc Namespace | Anything related to documentation size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants