FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

OAuth: don't override auth headers with contents of .netrc file by susodapop · Pull Request #122 · databricks/databricks-sql-python · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (1) .py  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Add support for Cloud Fetch
- Fix: Revised SQLAlchemy dialect and examples for compatibility with SQLAlchemy==1.3.x
- Fix: oauth would fail if expired credentials appeared in ~/.netrc

## 2.7.0 (2023-06-26)

Expand Down
22 changes: 20 additions & 2 deletions src/databricks/sql/auth/oauth.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@
logger = logging.getLogger(__name__)


class IgnoreNetrcAuth(requests.auth.AuthBase):
"""This auth method is a no-op.

We use it to force requestslib to not use .netrc to write auth headers
when making .post() requests to the oauth token endpoints, since these
don't require authentication.

In cases where .netrc is outdated or corrupt, these requests will fail.

See issue #121
"""

def __call__(self, r):
return r


class OAuthManager:
def __init__(
self,
Expand All @@ -43,7 +59,7 @@ def __fetch_well_known_config(self, hostname: str):
known_config_url = self.idp_endpoint.get_openid_config_url(hostname)

try:
response = requests.get(url=known_config_url)
response = requests.get(url=known_config_url, auth=IgnoreNetrcAuth())
except RequestException as e:
logger.error(
f"Unable to fetch OAuth configuration from {known_config_url}.\n"
Expand Down Expand Up @@ -149,7 +165,9 @@ def __send_token_request(token_request_url, data):
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
}
response = requests.post(url=token_request_url, data=data, headers=headers)
response = requests.post(
url=token_request_url, data=data, headers=headers, auth=IgnoreNetrcAuth()
)
return response.json()

def __send_refresh_token_request(self, hostname, refresh_token):
Expand Down

Back | FazBrowse Home | New Git URL