Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Add requests timeout #112

Merged
merged 2 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions adal/authentication_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AuthenticationContext(object):

def __init__(
self, authority, validate_authority=None, cache=None,
api_version='1.0'):
api_version='1.0', timeout=None):
'''Creates a new AuthenticationContext object.

By default the authority will be checked against a list of known Azure
Expand All @@ -70,6 +70,9 @@ def __init__(
Developers are now encouraged to set it as None explicitly,
which means the underlying API version will be automatically chosen.
In next major release, this default value will be changed to None.
:param timeout: (optional) requests timeout. How long to wait for the server to send
data before giving up, as a float, or a `(connect timeout,
read timeout) <timeouts>` tuple.
'''
self.authority = Authority(authority, validate_authority is None or validate_authority)
self._oauth2client = None
Expand All @@ -89,7 +92,8 @@ def __init__(
self._call_context = {
'options': GLOBAL_ADAL_OPTIONS,
'api_version': api_version,
'verify_ssl': None if env_value is None else not env_value # mainly for tracing through proxy
'verify_ssl': None if env_value is None else not env_value, # mainly for tracing through proxy
'timeout':timeout
}
self._token_requests_with_user_code = {}
self.cache = cache or TokenCache()
Expand Down
6 changes: 4 additions & 2 deletions adal/oauth2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ def get_token(self, oauth_parameters):
resp = requests.post(token_url.geturl(),
data=url_encoded_token_request,
headers=post_options['headers'],
verify=self._call_context.get('verify_ssl', None))
verify=self._call_context.get('verify_ssl', None),
timeout=self._call_context.get('timeout', None))

util.log_return_correlation_id(self._log, operation, resp)
except Exception:
Expand Down Expand Up @@ -294,7 +295,8 @@ def get_user_code_info(self, oauth_parameters):
resp = requests.post(device_code_url.geturl(),
data=url_encoded_code_request,
headers=post_options['headers'],
verify=self._call_context.get('verify_ssl', None))
verify=self._call_context.get('verify_ssl', None),
timeout=self._call_context.get('timeout', None))
util.log_return_correlation_id(self._log, operation, resp)
except Exception:
self._log.exception("%(operation)s request failed", {"operation": operation})
Expand Down