77from databricks .sql .auth .oauth import OAuthManager
88from databricks .sql .auth .endpoint import get_oauth_endpoints
99from 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
0 commit comments