Skip to content

Commit

Permalink
Allow configuration of outgoing request protocol
Browse files Browse the repository at this point in the history
Remove hardcoded HTTPS in URLs for outgoing requests to make the library more friendly to integration testing, where SSL is a pain.

See #253.
  • Loading branch information
garry-jeromson committed Mar 29, 2021
1 parent 86e5c7d commit 29d5250
Show file tree
Hide file tree
Showing 35 changed files with 97 additions and 73 deletions.
2 changes: 1 addition & 1 deletion auth0/v3/authentication/authorize_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ def authorize(self, client_id, audience=None, state=None, redirect_uri=None,
}

return self.get(
'https://{}/authorize'.format(self.domain),
'{}://{}/authorize'.format(self.protocol, self.domain),
params=params)
3 changes: 2 additions & 1 deletion auth0/v3/authentication/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class AuthenticationBase(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, telemetry=True, timeout=5.0):
def __init__(self, domain, telemetry=True, timeout=5.0, protocol="https"):
self.domain = domain
self.timeout = timeout
self.protocol = protocol
self.base_headers = {'Content-Type': 'application/json'}

if telemetry:
Expand Down
6 changes: 3 additions & 3 deletions auth0/v3/authentication/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def login(self, client_id, username, password, connection, id_token=None,
body.update({'id_token': id_token})
if device:
body.update({'device': device})
return self.post('https://{}/oauth/ro'.format(self.domain), data=body)
return self.post('{}://{}/oauth/ro'.format(self.protocol, self.domain), data=body)

def signup(self, client_id, email, password, connection, username=None, user_metadata=None,
given_name=None, family_name=None, name=None, nickname=None, picture=None):
Expand Down Expand Up @@ -88,7 +88,7 @@ def signup(self, client_id, email, password, connection, username=None, user_met
if picture:
body.update({'picture': picture})

return self.post('https://{}/dbconnections/signup'.format(self.domain), data=body)
return self.post('{}://{}/dbconnections/signup'.format(self.protocol, self.domain), data=body)

def change_password(self, client_id, email, connection, password=None):
"""Asks to change a password for a given user.
Expand All @@ -105,4 +105,4 @@ def change_password(self, client_id, email, connection, password=None):
'connection': connection,
}

return self.post('https://{}/dbconnections/change_password'.format(self.domain), data=body)
return self.post('{}://{}/dbconnections/change_password'.format(self.protocol, self.domain), data=body)
2 changes: 1 addition & 1 deletion auth0/v3/authentication/delegated.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def get_token(self, client_id, target, api_type, grant_type,
raise ValueError('Either id_token or refresh_token must '
'have a value')

return self.post('https://{}/delegation'.format(self.domain), data=data)
return self.post('{}://{}/delegation'.format(self.protocol, self.domain), data=data)
7 changes: 3 additions & 4 deletions auth0/v3/authentication/enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ def saml_metadata(self, client_id):
client_id (str): Client Id of the application to get the SAML metadata for.
"""

return self.get(url='https://{}/samlp/metadata/{}'.format(self.domain,
client_id))
return self.get(url='{}://{}/samlp/metadata/{}'.format(self.protocol, self.domain, client_id))

def wsfed_metadata(self):
"""Returns the WS-Federation Metadata.
"""

url = 'https://{}/wsfed/FederationMetadata' \
url = '{}://{}/wsfed/FederationMetadata' \
'/2007-06/FederationMetadata.xml'

return self.get(url=url.format(self.domain))
return self.get(url=url.format(self.protocol, self.domain))
10 changes: 5 additions & 5 deletions auth0/v3/authentication/get_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def authorization_code(self, client_id, client_secret, code,
"""

return self.post(
'https://{}/oauth/token'.format(self.domain),
'{}://{}/oauth/token'.format(self.protocol, self.domain),
data={
'client_id': client_id,
'client_secret': client_secret,
Expand Down Expand Up @@ -71,7 +71,7 @@ def authorization_code_pkce(self, client_id, code_verifier, code,
"""

return self.post(
'https://{}/oauth/token'.format(self.domain),
'{}://{}/oauth/token'.format(self.protocol, self.domain),
data={
'client_id': client_id,
'code_verifier': code_verifier,
Expand Down Expand Up @@ -105,7 +105,7 @@ def client_credentials(self, client_id, client_secret, audience,
"""

return self.post(
'https://{}/oauth/token'.format(self.domain),
'{}://{}/oauth/token'.format(self.protocol, self.domain),
data={
'client_id': client_id,
'client_secret': client_secret,
Expand Down Expand Up @@ -151,7 +151,7 @@ def login(self, client_id, client_secret, username, password, scope, realm,
"""

return self.post(
'https://{}/oauth/token'.format(self.domain),
'{}://{}/oauth/token'.format(self.protocol, self.domain),
data={
'client_id': client_id,
'username': username,
Expand Down Expand Up @@ -187,7 +187,7 @@ def refresh_token(self, client_id, client_secret, refresh_token, grant_type='ref
"""

return self.post(
'https://{}/oauth/token'.format(self.domain),
'{}://{}/oauth/token'.format(self.protocol, self.domain),
data={
'client_id': client_id,
'client_secret': client_secret,
Expand Down
7 changes: 4 additions & 3 deletions auth0/v3/authentication/logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ def logout(self, client_id, return_to, federated=False):

if federated is True:
return self.get(
'https://{}/v2/logout?federated&client_id={}&returnTo={}'.format(
self.domain, client_id, return_to)
'{}://{}/v2/logout?federated&client_id={}&returnTo={}'.format(
self.protocol, self.domain, client_id, return_to)
)
return self.get(
'https://{}/v2/logout?client_id={}&returnTo={}'.format(self.domain,
'{}://{}/v2/logout?client_id={}&returnTo={}'.format(self.protocol,
self.domain,
client_id,
return_to)
)
6 changes: 3 additions & 3 deletions auth0/v3/authentication/passwordless.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def email(self, client_id, email, send='link', auth_params=None, client_secret=N
data.update({'client_secret': client_secret})

return self.post(
'https://{}/passwordless/start'.format(self.domain),
'{}://{}/passwordless/start'.format(self.protocol, self.domain),
data=data
)

Expand Down Expand Up @@ -75,7 +75,7 @@ def sms(self, client_id, phone_number, client_secret=None):
data.update({'client_secret': client_secret})

return self.post(
'https://{}/passwordless/start'.format(self.domain),
'{}://{}/passwordless/start'.format(self.protocol, self.domain),
data=data
)

Expand All @@ -93,7 +93,7 @@ def sms_login(self, client_id, phone_number, code, scope='openid'):
"""

return self.post(
'https://{}/oauth/ro'.format(self.domain),
'{}://{}/oauth/ro'.format(self.protocol, self.domain),
data={
'client_id': client_id,
'connection': 'sms',
Expand Down
2 changes: 1 addition & 1 deletion auth0/v3/authentication/revoke_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def revoke_refresh_token(self, client_id, token, client_secret=None):
if client_secret:
body.update({'client_secret': client_secret})

return self.post('https://{}/oauth/revoke'.format(self.domain), data=body)
return self.post('{}://{}/oauth/revoke'.format(self.protocol, self.domain), data=body)
2 changes: 1 addition & 1 deletion auth0/v3/authentication/social.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def login(self, client_id, access_token, connection, scope='openid'):
"""

return self.post(
'https://{}/oauth/access_token'.format(self.domain),
'{}://{}/oauth/access_token'.format(self.protocol, self.domain),
data={
'client_id': client_id,
'access_token': access_token,
Expand Down
4 changes: 2 additions & 2 deletions auth0/v3/authentication/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def userinfo(self, access_token):
"""

return self.get(
url='https://{}/userinfo'.format(self.domain),
url='{}://{}/userinfo'.format(self.protocol, self.domain),
headers={'Authorization': 'Bearer {}'.format(access_token)}
)

Expand All @@ -43,6 +43,6 @@ def tokeninfo(self, jwt):
"""
warnings.warn("/tokeninfo will be deprecated in future releases", DeprecationWarning)
return self.post(
url='https://{}/tokeninfo'.format(self.domain),
url='{}://{}/tokeninfo'.format(self.protocol, self.domain),
data={'id_token': jwt}
)
4 changes: 2 additions & 2 deletions auth0/v3/management/blacklists.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Blacklists(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0):
self.url = 'https://{}/api/v2/blacklists/tokens'.format(domain)
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
self.url = '{}://{}/api/v2/blacklists/tokens'.format(protocol, domain)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)

def get(self, aud=None):
Expand Down
5 changes: 3 additions & 2 deletions auth0/v3/management/client_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class ClientGrants(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)

def _url(self, id=None):
url = 'https://{}/api/v2/client-grants'.format(self.domain)
url = '{}://{}/api/v2/client-grants'.format(self.protocol, self.domain)
if id is not None:
return '{}/{}'.format(url, id)
return url
Expand Down
5 changes: 3 additions & 2 deletions auth0/v3/management/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class Clients(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)

def _url(self, id=None):
url = 'https://{}/api/v2/clients'.format(self.domain)
url = '{}://{}/api/v2/clients'.format(self.protocol, self.domain)
if id is not None:
return '{}/{}'.format(url, id)
return url
Expand Down
5 changes: 3 additions & 2 deletions auth0/v3/management/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class Connections(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)

def _url(self, id=None):
url = 'https://{}/api/v2/connections'.format(self.domain)
url = '{}://{}/api/v2/connections'.format(self.protocol, self.domain)
if id is not None:
return '{}/{}'.format(url, id)
return url
Expand Down
5 changes: 3 additions & 2 deletions auth0/v3/management/custom_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class CustomDomains(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)

def _url(self, id=None):
url = 'https://%s/api/v2/custom-domains' % self.domain
url = '{}://{}/api/v2/custom-domains'.format(self.protocol, self.domain)
if id is not None:
return url + '/' + id
return url
Expand Down
5 changes: 3 additions & 2 deletions auth0/v3/management/device_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class DeviceCredentials(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)

def _url(self, id=None):
url = 'https://{}/api/v2/device-credentials'.format(self.domain)
url = '{}://{}/api/v2/device-credentials'.format(self.protocol, self.domain)
if id is not None:
return '{}/{}'.format(url, id)
return url
Expand Down
5 changes: 3 additions & 2 deletions auth0/v3/management/email_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class EmailTemplates(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)

def _url(self, id=None):
url = 'https://{}/api/v2/email-templates'.format(self.domain)
url = '{}://{}/api/v2/email-templates'.format(self.protocol, self.domain)
if id is not None:
return '{}/{}'.format(url, id)
return url
Expand Down
5 changes: 3 additions & 2 deletions auth0/v3/management/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class Emails(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)

def _url(self, id=None):
url = 'https://{}/api/v2/emails/provider'.format(self.domain)
url = '{}://{}/api/v2/emails/provider'.format(self.protocol, self.domain)
if id is not None:
return '{}/{}'.format(url, id)
return url
Expand Down
5 changes: 3 additions & 2 deletions auth0/v3/management/grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class Grants(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)

def _url(self, id=None):
url = 'https://%s/api/v2/grants' % self.domain
url = '{}://{}/api/v2/grants'.format(self.protocol, self.domain)
if id is not None:
return url + '/' + id
return url
Expand Down
5 changes: 3 additions & 2 deletions auth0/v3/management/guardian.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class Guardian(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)

def _url(self, id=None):
url = 'https://{}/api/v2/guardian'.format(self.domain)
url = '{}://{}/api/v2/guardian'.format(self.protocol, self.domain)
if id is not None:
return '{}/{}'.format(url, id)
return url
Expand Down
5 changes: 3 additions & 2 deletions auth0/v3/management/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class Hooks(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)

def _url(self, id=None):
url = "https://{}/api/v2/hooks".format(self.domain)
url = "{}://{}/api/v2/hooks".format(self.protocol, self.domain)
if id is not None:
return "{}/{}".format(url, id)
return url
Expand Down
5 changes: 3 additions & 2 deletions auth0/v3/management/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class Jobs(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)

def _url(self, path=None):
url = 'https://{}/api/v2/jobs'.format(self.domain)
url = '{}://{}/api/v2/jobs'.format(self.protocol, self.domain)
if path is not None:
return '{}/{}'.format(url, path)
return url
Expand Down
5 changes: 3 additions & 2 deletions auth0/v3/management/log_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class LogStreams(object):
(defaults to 5.0 for both)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)

def _url(self, id=None):
url = 'https://{}/api/v2/log-streams'.format(self.domain)
url = '{}://{}/api/v2/log-streams'.format(self.protocol, self.domain)
if id is not None:
return '{}/{}'.format(url, id)
return url
Expand Down
Loading

0 comments on commit 29d5250

Please sign in to comment.