-
Notifications
You must be signed in to change notification settings - Fork 455
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
Fixed issue with token URI not valid or returning error Bug#360 #361
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,9 +118,27 @@ def parse_response(resp, content, strict=False, content_type=None): | |
:param strict: strict mode for form urlencoded content | ||
:param content_type: assign a content type manually | ||
""" | ||
if not content_type: | ||
content_type = resp.headers.get('content-type', 'application/json') | ||
ct, options = parse_options_header(content_type) | ||
charset = options.get('charset', 'utf-8') | ||
|
||
if not content_type: | ||
|
||
try: | ||
return json.loads(content) | ||
|
||
except Exception as exception: | ||
log.debug("The content is not json") | ||
|
||
try: | ||
return get_etree().fromstring(content) | ||
|
||
except Exception as exception: | ||
log.debug("The content is not XML") | ||
|
||
if strict: | ||
return content | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for else. |
||
return url_decode(content, charset=charset).to_dict() | ||
|
||
if ct in ('application/json', 'text/javascript'): | ||
if not content: | ||
|
@@ -132,7 +150,7 @@ def parse_response(resp, content, strict=False, content_type=None): | |
|
||
if ct != 'application/x-www-form-urlencoded' and strict: | ||
return content | ||
charset = options.get('charset', 'utf-8') | ||
|
||
return url_decode(content, charset=charset).to_dict() | ||
|
||
|
||
|
@@ -641,13 +659,11 @@ def handle_oauth1_response(self, args): | |
uri, headers, to_bytes(data, self.encoding), | ||
method=self.access_token_method | ||
) | ||
data = parse_response(resp, content) | ||
|
||
if resp.code not in (200, 201): | ||
raise OAuthException( | ||
'Invalid response from %s' % self.name, | ||
type='invalid_response', data=data | ||
) | ||
return data | ||
return {'accessToken':None,'code':resp.code, 'msg':resp.msg} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will introduce a break change. |
||
|
||
return parse_response(resp, content) | ||
|
||
def handle_oauth2_response(self, args): | ||
"""Handles an oauth2 authorization response.""" | ||
|
@@ -685,13 +701,10 @@ def handle_oauth2_response(self, args): | |
self.access_token_method | ||
) | ||
|
||
data = parse_response(resp, content, content_type=self.content_type) | ||
if resp.code not in (200, 201): | ||
raise OAuthException( | ||
'Invalid response from %s' % self.name, | ||
type='invalid_response', data=data | ||
) | ||
return data | ||
return {'accessToken':None,'code':resp.code, 'msg':resp.msg} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will introduce a break change. |
||
|
||
return parse_response(resp, content, content_type=self.content_type) | ||
|
||
def handle_unknown_response(self): | ||
"""Handles a unknown authorization response.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single quote please.
And there are too many blank lines.