Skip to content

Commit

Permalink
Issue ref delta-io#269: OAuth 2.0 Credential Format for Delta Sharing…
Browse files Browse the repository at this point in the history
… Python Client Pull Request

Signed-off-by: Dima Alberg <[email protected]>
  • Loading branch information
dialberg committed May 30, 2023
1 parent 516c5b1 commit c315cab
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions python/delta_sharing/rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,32 +147,32 @@ def __init__(self, profile: DeltaSharingProfile, num_retries=10):

def auth_session(self, profile):
self._session = requests.Session()
self._auth_broker(profile)
self.__auth_broker(profile)
if urlparse(profile.endpoint).hostname == "localhost":
self._session.verify = False

def _auth_broker(self, profile):
def __auth_broker(self, profile):
if profile.share_credentials_version == 2:
if profile.type == "persistent_oauth2.0":
self._auth_persistent_oauth2(profile)
self.__auth_persistent_oauth2(profile)
elif profile.type == "bearer_token":
self._auth_bearer_token(profile)
self.__auth_bearer_token(profile)
elif profile.type == "basic":
self._auth_basic(profile)
self.__auth_basic(profile)
else:
self._auth_bearer_token(profile)
self.__auth_bearer_token(profile)
else:
self._auth_bearer_token(profile)
self.__auth_bearer_token(profile)

def _auth_bearer_token(self, profile):
def __auth_bearer_token(self, profile):
self._session.headers.update(
{
"Authorization": f"Bearer {profile.bearer_token}",
"User-Agent": DataSharingRestClient.USER_AGENT,
}
)

def _auth_persistent_oauth2(self, profile):
def __auth_persistent_oauth2(self, profile):
headers = {"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json"}

Expand All @@ -191,7 +191,7 @@ def _auth_persistent_oauth2(self, profile):
}
)

def _auth_basic(self, profile):
def __auth_basic(self, profile):
self._session.auth = (profile.username, profile.password)

response = self._session.post(profile.endpoint,
Expand Down

0 comments on commit c315cab

Please sign in to comment.