refactor(db-engine-specs): use standard OAuth 2.0 params in base class (#37010)

This commit is contained in:
Enzo Martellucci
2026-01-09 17:44:32 +01:00
committed by GitHub
parent f48322c17d
commit ea90d1f141
5 changed files with 91 additions and 4 deletions

View File

@@ -894,3 +894,52 @@ def test_extract_errors_no_match_falls_back(mocker: MockerFixture) -> None:
engine_name="ExampleEngine",
)
assert result == [expected]
def test_get_oauth2_authorization_uri_standard_params(mocker: MockerFixture) -> None:
"""
Test that BaseEngineSpec.get_oauth2_authorization_uri uses standard OAuth 2.0
parameters only and does not include provider-specific params like prompt=consent.
"""
from urllib.parse import parse_qs, urlparse
from superset.db_engine_specs.base import BaseEngineSpec
from superset.superset_typing import OAuth2ClientConfig, OAuth2State
from superset.utils.oauth2 import decode_oauth2_state
config: OAuth2ClientConfig = {
"id": "client-id",
"secret": "client-secret",
"scope": "read write",
"redirect_uri": "http://localhost:8088/api/v1/database/oauth2/",
"authorization_request_uri": "https://oauth.example.com/authorize",
"token_request_uri": "https://oauth.example.com/token",
"request_content_type": "json",
}
state: OAuth2State = {
"database_id": 1,
"user_id": 1,
"default_redirect_uri": "http://localhost:8088/api/v1/oauth2/",
"tab_id": "1234",
}
url = BaseEngineSpec.get_oauth2_authorization_uri(config, state)
parsed = urlparse(url)
assert parsed.netloc == "oauth.example.com"
assert parsed.path == "/authorize"
query = parse_qs(parsed.query)
# Verify standard OAuth 2.0 parameters are included
assert query["scope"][0] == "read write"
assert query["response_type"][0] == "code"
assert query["client_id"][0] == "client-id"
assert query["redirect_uri"][0] == "http://localhost:8088/api/v1/database/oauth2/"
encoded_state = query["state"][0].replace("%2E", ".")
assert decode_oauth2_state(encoded_state) == state
# Verify Google-specific parameters are NOT included (standard OAuth 2.0)
assert "prompt" not in query
assert "access_type" not in query
assert "include_granted_scopes" not in query

View File

@@ -638,6 +638,11 @@ def test_get_oauth2_authorization_uri(
encoded_state = query["state"][0].replace("%2E", ".")
assert decode_oauth2_state(encoded_state) == state
# Verify Google-specific OAuth parameters are included
assert query["access_type"][0] == "offline"
assert query["include_granted_scopes"][0] == "false"
assert query["prompt"][0] == "consent"
def test_get_oauth2_token(
mocker: MockerFixture,

View File

@@ -231,7 +231,7 @@ def test_get_sql_results_oauth2(mocker: MockerFixture, app) -> None:
"error_type": SupersetErrorType.OAUTH2_REDIRECT,
"level": ErrorLevel.WARNING,
"extra": {
"url": "https://abcd1234.snowflakecomputing.com/oauth/authorize?scope=refresh_token+session%3Arole%3AUSERADMIN&access_type=offline&include_granted_scopes=false&response_type=code&state=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9%252EeyJleHAiOjE2MTcyMzU1MDAsImRhdGFiYXNlX2lkIjoxLCJ1c2VyX2lkIjo0MiwiZGVmYXVsdF9yZWRpcmVjdF91cmkiOiJodHRwOi8vbG9jYWxob3N0L2FwaS92MS9kYXRhYmFzZS9vYXV0aDIvIiwidGFiX2lkIjoiZmIxMWY1MjgtNmViYS00YThhLTgzN2UtNmIwZDM5ZWU5MTg3In0%252E7nLkei6-V8sVk_Pgm8cFhk0tnKRKayRE1Vc7RxuM9mw&redirect_uri=http%3A%2F%2Flocalhost%2Fapi%2Fv1%2Fdatabase%2Foauth2%2F&client_id=my_client_id&prompt=consent",
"url": "https://abcd1234.snowflakecomputing.com/oauth/authorize?scope=refresh_token+session%3Arole%3AUSERADMIN&response_type=code&state=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9%252EeyJleHAiOjE2MTcyMzU1MDAsImRhdGFiYXNlX2lkIjoxLCJ1c2VyX2lkIjo0MiwiZGVmYXVsdF9yZWRpcmVjdF91cmkiOiJodHRwOi8vbG9jYWxob3N0L2FwaS92MS9kYXRhYmFzZS9vYXV0aDIvIiwidGFiX2lkIjoiZmIxMWY1MjgtNmViYS00YThhLTgzN2UtNmIwZDM5ZWU5MTg3In0%252E7nLkei6-V8sVk_Pgm8cFhk0tnKRKayRE1Vc7RxuM9mw&redirect_uri=http%3A%2F%2Flocalhost%2Fapi%2Fv1%2Fdatabase%2Foauth2%2F&client_id=my_client_id",
"tab_id": "fb11f528-6eba-4a8a-837e-6b0d39ee9187",
"redirect_uri": "http://localhost/api/v1/database/oauth2/",
},