Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_user_code_info(self, oauth_parameters):
device_code_url = self._create_device_code_url()
url_encoded_code_request = urlencode(oauth_parameters)
post_options = util.create_request_options(self, _REQ_OPTION)
operation = "Get Device Code"
try:
resp = requests.post(device_code_url.geturl(),
data=url_encoded_code_request,
headers=post_options['headers'],
verify=self._call_context.get('verify_ssl', None),
proxies=self._call_context.get('proxies', 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})
raise
if util.is_http_success(resp.status_code):
user_code_info = self._handle_get_device_code_response(resp.text)
user_code_info['correlation_id'] = resp.headers.get('client-request-id')
def get_token_with_polling(self, oauth_parameters, refresh_internal, expires_in):
token_url = self._create_token_url()
url_encoded_code_request = urlencode(oauth_parameters)
post_options = util.create_request_options(self, _REQ_OPTION)
operation = "Get token with device code"
max_times_for_retry = math.floor(expires_in/refresh_internal)
for _ in range(int(max_times_for_retry)):
if self._cancel_polling_request:
raise AdalError('Polling_Request_Cancelled')
resp = requests.post(
token_url.geturl(),
data=url_encoded_code_request, headers=post_options['headers'],
proxies=self._call_context.get('proxies', None),
verify=self._call_context.get('verify_ssl', None))
if resp.status_code == 429:
resp.raise_for_status() # Will raise requests.exceptions.HTTPError
def discover(self):
options = util.create_request_options(self, {'headers': {'Accept':'application/json'}})
user_realm_url = self._get_user_realm_url()
self._log.debug("Performing user realm discovery at: %(user_realm_url)s",
{"user_realm_url": user_realm_url.geturl()})
operation = 'User Realm Discovery'
resp = requests.get(user_realm_url.geturl(), headers=options['headers'],
proxies=self._call_context.get('proxies', None),
verify=self._call_context.get('verify_ssl', None))
util.log_return_correlation_id(self._log, operation, resp)
if resp.status_code == 429:
resp.raise_for_status() # Will raise requests.exceptions.HTTPError
if not util.is_http_success(resp.status_code):
return_error_string = u"{} request returned http error: {}".format(operation,
resp.status_code)
error_response = ""
def get_token(self, oauth_parameters):
token_url = self._create_token_url()
url_encoded_token_request = urlencode(oauth_parameters)
post_options = util.create_request_options(self, _REQ_OPTION)
operation = "Get Token"
try:
resp = requests.post(token_url.geturl(),
data=url_encoded_token_request,
headers=post_options['headers'],
verify=self._call_context.get('verify_ssl', None),
proxies=self._call_context.get('proxies', 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})
raise