Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer OAuth Host #144

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions docusign_esign/client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ def request_jwt_user_token(self, client_id, user_id, oauth_host_name, private_ke
raise ArgumentException("Private key not supplied or is invalid!")
if not user_id:
raise ArgumentException("User Id not supplied or is invalid!")
# TODO: Make oauth_host_name optional and default to the instance property.
if not oauth_host_name:
raise ArgumentException("oAuthBasePath cannot be empty")

Expand Down Expand Up @@ -720,6 +721,7 @@ def request_jwt_application_token(self, client_id, oauth_host_name, private_key_

if not private_key_bytes:
raise ArgumentException("Private key not supplied or is invalid!")
# TODO: Make oauth_host_name optional and default to the instance property.
if not oauth_host_name:
raise ArgumentException("oAuthBasePath cannot be empty")

Expand Down Expand Up @@ -756,7 +758,7 @@ def get_user_info(self, access_token):
raise ArgumentException("Cannot find a valid access token."
" Make sure OAuth is configured before you try again.")
if not self.oauth_host_name:
raise ArgumentException("oAuthBasePath cannot be empty")
raise ArgumentException("The oauth_host_name property has not been set")

resource_path = '/oauth/userinfo'
headers = {"Authorization": "Bearer " + access_token}
Expand All @@ -774,6 +776,8 @@ def generate_access_token(self, client_id, client_secret, code):
"""
if not client_id or not client_secret or not code:
raise ArgumentException
if not self.oauth_host_name:
raise ArgumentException("The oauth_host_name property has not been set")
url = "https://{0}/oauth/token".format(self.oauth_host_name)
integrator_and_secret_key = b"Basic " + base64.b64encode(str.encode("{}:{}".format(client_id, client_secret)))
headers = {
Expand Down Expand Up @@ -804,17 +808,19 @@ def set_oauth_host_name(self, oauth_host_name=None):
self.oauth_host_name = oauth_host_name
return

if not oauth_host_name:
raise ArgumentException('oAuthBasePath cannot be empty')
if not self.base_path:
raise ArgumentException('Unable to infer oauth_host_name without base_path set')

# Derive OAuth Base Path if not given
if self.base_path.startswith("https://demo") or self.base_path.startswith("http://demo"):
self.oauth_host_name = OAuth.DEMO_OAUTH_BASE_PATH
elif self.base_path.startswith("https://stage") or self.base_path.startswith("http://stage"):
self.oauth_host_name = OAuth.STAGE_OAUTH_BASE_PATH
else:
elif self.base_path.startswith("https://docusign") or self.base_path.startswith("http://docusign"):
self.oauth_host_name = OAuth.PRODUCTION_OAUTH_BASE_PATH

raise ArgumentException('Unable to infer oauth_host_name from unknown base_path')

def set_access_token(self, token_obj):
"""

Expand Down