Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 94b2250

Browse files
author
Jesse Whitehouse
committedJul 12, 2023
Oauth: ignore ~/.netrc file for requests to unauthenticated endpoints
https://requests.readthedocs.io/en/latest/user/authentication/#new-forms-of-authentication Closes #121 Affects databricks/dbt-databricks#337 Signed-off-by: Jesse Whitehouse <[email protected]>
1 parent f45280d commit 94b2250

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed
 

‎src/databricks/sql/auth/oauth.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818

1919
logger = logging.getLogger(__name__)
2020

21+
class IgnoreNetrcAuth(requests.auth.AuthBase):
22+
"""This auth method is a no-op.
23+
24+
We use it to force requestslib to not use .netrc to write auth headers
25+
when making .post() requests to the oauth token endpoints, since these
26+
don't require authentication.
27+
28+
In cases where .netrc is outdated or corrupt, these requests will fail.
29+
30+
See issue #121
31+
"""
32+
def __call__(self, r):
33+
return r
2134

2235
class OAuthManager:
2336
def __init__(
@@ -43,7 +56,7 @@ def __fetch_well_known_config(self, hostname: str):
4356
known_config_url = self.idp_endpoint.get_openid_config_url(hostname)
4457

4558
try:
46-
response = requests.get(url=known_config_url)
59+
response = requests.get(url=known_config_url, auth=IgnoreNetrcAuth())
4760
except RequestException as e:
4861
logger.error(
4962
f"Unable to fetch OAuth configuration from {known_config_url}.\n"
@@ -149,7 +162,7 @@ def __send_token_request(token_request_url, data):
149162
"Accept": "application/json",
150163
"Content-Type": "application/x-www-form-urlencoded",
151164
}
152-
response = requests.post(url=token_request_url, data=data, headers=headers)
165+
response = requests.post(url=token_request_url, data=data, headers=headers, auth=IgnoreNetrcAuth())
153166
return response.json()
154167

155168
def __send_refresh_token_request(self, hostname, refresh_token):

0 commit comments

Comments
 (0)
Please sign in to comment.