Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 = ""
if resp.text:
return_error_string = u"{} and server response: {}".format(return_error_string, resp.text)
try:
error_response = resp.json()
except ValueError:
pass
raise AdalError(return_error_string, error_response)
else:
self._parse_discovery_response(resp.text)
options = util.create_request_options(self, {'headers': {'Content-Type': 'application/soap+xml'}})
try:
operation = "Mex Get"
resp = requests.get(self._url, headers=options['headers'],
verify=self._call_context.get('verify_ssl', None),
proxies=self._call_context.get('proxies', None))
util.log_return_correlation_id(self._log, operation, resp)
except Exception:
self._log.exception(
"%(operation)s request failed", {"operation": operation})
raise
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 = ""
if resp.text:
return_error_string = u"{} and server response: {}".format(return_error_string, resp.text)
try:
error_response = resp.json()
except ValueError:
pass
raise AdalError(return_error_string, error_response)
else:
try:
self._mex_doc = resp.text
#options = {'errorHandler':self._log.error}
self._dom = ET.fromstring(self._mex_doc)
self._parents = {c:p for p in self._dom.iter() for c in p}
self._parse()
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')
return user_code_info
else:
if resp.status_code == 429:
resp.raise_for_status() # Will raise requests.exceptions.HTTPError
return_error_string = _ERROR_TEMPLATE.format(operation, resp.status_code)
error_response = ""
if resp.text:
return_error_string = u"{} and server response: {}".format(return_error_string,
resp.text)
try:
error_response = resp.json()
except ValueError:
pass