Skip to content

Commit 05ab3e8

Browse files
committed
Nit
1 parent 5e2b792 commit 05ab3e8

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/databricks/sql/auth/authenticators.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from databricks.sql.auth.oauth import OAuthManager
88
from databricks.sql.auth.endpoint import get_oauth_endpoints
99
from databricks.sql.common.http import DatabricksHttpClient, OAuthResponse
10+
from urllib.parse import urlencode
1011

1112
# Private API: this is an evolving interface and it will change in the future.
1213
# Please must not depend on it in your applications.
@@ -197,7 +198,6 @@ class AzureServicePrincipalCredentialProvider(CredentialsProvider):
197198
"""
198199

199200
AZURE_AAD_ENDPOINT = "https://login.microsoftonline.com"
200-
DATABRICKS_SCOPE = "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default"
201201
AZURE_TOKEN_ENDPOINT = "oauth2/token"
202202

203203
def __init__(self, client_id: str, client_secret: str, tenant_id: str):
@@ -213,7 +213,9 @@ def auth_type(self) -> str:
213213
def __call__(self, *args, **kwargs) -> HeaderFactory:
214214
def header_factory() -> Dict[str, str]:
215215
self._refresh()
216-
return {HttpHeader.AUTHORIZATION: f"Bearer {self._token.access_token}"}
216+
return {
217+
HttpHeader.AUTHORIZATION.value: f"{self._token.token_type} {self._token.access_token}",
218+
}
217219

218220
return header_factory
219221

@@ -226,14 +228,15 @@ def _get_token(self) -> Token:
226228
f"{self.AZURE_AAD_ENDPOINT}/{self.tenant_id}/{self.AZURE_TOKEN_ENDPOINT}"
227229
)
228230
headers = {
229-
HttpHeader.CONTENT_TYPE: "application/x-www-form-urlencoded",
230-
}
231-
data = {
232-
"grant_type": "client_credentials",
233-
"client_id": self.client_id,
234-
"client_secret": self.client_secret,
235-
"scope": self.DATABRICKS_SCOPE,
231+
HttpHeader.CONTENT_TYPE.value: "application/x-www-form-urlencoded",
236232
}
233+
data = urlencode(
234+
{
235+
"grant_type": "client_credentials",
236+
"client_id": self.client_id,
237+
"client_secret": self.client_secret,
238+
}
239+
)
237240

238241
response = self._http_client.execute(
239242
method=HttpMethod.POST, url=request_url, headers=headers, data=data

src/databricks/sql/common/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def get_instance(cls) -> "DatabricksHttpClient":
5757
return cls._instance
5858

5959
def execute(self, method: HttpMethod, url: str, **kwargs) -> requests.Response:
60-
with self.session.request(method, url, **kwargs) as response:
60+
with self.session.request(method.value, url, **kwargs) as response:
6161
return response
6262

6363
def close(self):

0 commit comments

Comments
 (0)