@@ -15,6 +15,7 @@ class AuthType(Enum):
1515 AZURE_OAUTH = "azure-oauth"
1616 # TODO: Token federation should be a feature that works with different auth types,
1717 # not an auth type itself. This will be refactored in a future change.
18+ # We will add a use_token_federation flag that can be used with any auth type.
1819 TOKEN_FEDERATION = "token-federation"
1920 # other supported types (access_token) can be inferred
2021 # we can add more types as needed later
@@ -49,10 +50,28 @@ def __init__(
4950
5051
5152def get_auth_provider (cfg : ClientContext ):
52- # TODO: In a future refactoring, token federation should be a feature that wraps
53- # any auth provider, not a separate auth type. The code below treats it as an auth type
54- # for backward compatibility, but this approach will be revised.
55-
53+ """
54+ Get an appropriate auth provider based on the provided configuration.
55+
56+ Token Federation Support:
57+ -----------------------
58+ Currently, token federation is implemented as a separate auth type, but the goal is to
59+ refactor it as a feature that can work with any auth type. The current implementation
60+ is maintained for backward compatibility while the refactoring is planned.
61+
62+ Future refactoring will introduce a `use_token_federation` flag that can be combined
63+ with any auth type to enable token federation.
64+
65+ Args:
66+ cfg: The client context containing configuration parameters
67+
68+ Returns:
69+ An appropriate AuthProvider instance
70+
71+ Raises:
72+ RuntimeError: If no valid authentication settings are provided
73+ """
74+ # If credentials_provider is explicitly provided
5675 if cfg .credentials_provider :
5776 # If token federation is enabled and credentials provider is provided,
5877 # wrap the credentials provider with DatabricksTokenFederationProvider
@@ -73,13 +92,15 @@ def get_auth_provider(cfg: ClientContext):
7392
7493 # If we don't have a credentials provider but have token federation auth type with access token
7594 if cfg .auth_type == AuthType .TOKEN_FEDERATION .value and cfg .access_token :
76- # If only access_token is provided with token federation, use create_token_federation_provider
95+ # Create a simple credentials provider and wrap it with token federation provider
7796 from databricks .sql .auth .token_federation import (
78- create_token_federation_provider ,
97+ DatabricksTokenFederationProvider ,
98+ SimpleCredentialsProvider ,
7999 )
80100
81- federation_provider = create_token_federation_provider (
82- cfg .access_token , cfg .hostname , cfg .identity_federation_client_id
101+ simple_provider = SimpleCredentialsProvider (cfg .access_token )
102+ federation_provider = DatabricksTokenFederationProvider (
103+ simple_provider , cfg .hostname , cfg .identity_federation_client_id
83104 )
84105 return ExternalAuthProvider (federation_provider )
85106
@@ -140,6 +161,27 @@ def get_client_id_and_redirect_port(use_azure_auth: bool):
140161
141162
142163def get_python_sql_connector_auth_provider (hostname : str , ** kwargs ):
164+ """
165+ Get an auth provider for the Python SQL connector.
166+
167+ This function is the main entry point for authentication in the SQL connector.
168+ It processes the parameters and creates an appropriate auth provider.
169+
170+ TODO: Future refactoring needed:
171+ 1. Add a use_token_federation flag that can be combined with any auth type
172+ 2. Remove TOKEN_FEDERATION as an auth_type while maintaining backward compatibility
173+ 3. Create a token federation wrapper that can wrap any existing auth provider
174+
175+ Args:
176+ hostname: The Databricks server hostname
177+ **kwargs: Additional configuration parameters
178+
179+ Returns:
180+ An appropriate AuthProvider instance
181+
182+ Raises:
183+ ValueError: If username/password authentication is attempted (no longer supported)
184+ """
143185 auth_type = kwargs .get ("auth_type" )
144186 (client_id , redirect_port_range ) = get_client_id_and_redirect_port (
145187 auth_type == AuthType .AZURE_OAUTH .value
@@ -150,10 +192,6 @@ def get_python_sql_connector_auth_provider(hostname: str, **kwargs):
150192 "Please use OAuth or access token instead."
151193 )
152194
153- # TODO: Future refactoring needed:
154- # - Add a use_token_federation flag that can be combined with any auth type
155- # - Remove TOKEN_FEDERATION as an auth_type and properly handle the underlying auth type
156- # - Maintain backward compatibility during transition
157195 cfg = ClientContext (
158196 hostname = normalize_host_name (hostname ),
159197 auth_type = auth_type ,
0 commit comments