Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
43 changes: 28 additions & 15 deletions flask_oauthlib/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Owner

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.


try:
return get_etree().fromstring(content)

except Exception as exception:
log.debug("The content is not XML")

if strict:
return content
else:
Copy link
Owner

Choose a reason for hiding this comment

The 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:
Expand All @@ -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()


Expand Down Expand Up @@ -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}
Copy link
Owner

Choose a reason for hiding this comment

The 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."""
Expand Down Expand Up @@ -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}
Copy link
Owner

Choose a reason for hiding this comment

The 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."""
Expand Down