Fixed issue with token URI not valid or returning error Bug#360#361
Open
mayankberi1 wants to merge 3 commits intolepture:masterfrom
mayankberi1:bug_fix#360
Open
Fixed issue with token URI not valid or returning error Bug#360#361mayankberi1 wants to merge 3 commits intolepture:masterfrom mayankberi1:bug_fix#360
mayankberi1 wants to merge 3 commits intolepture:masterfrom
mayankberi1:bug_fix#360
Conversation
1. Fixed the code to handle content_type missing from headers. instead of defaulting it to JSON, now trying to load it to json, xml, or then simply returning the content. Code was failing when the content_type was missing but the content was not of json type. 2. Handled the case where an exception was raised when the token URL responsed in a code other than 200 or 201. Instead of raising OauthException now returning the error code in a dictionary so that it can be handled or displayed.
Owner
|
With the release of Authlib 0.2. It is stable enough to use the Flask Client in Authlib. It is more stable than Flask-OAuthlib. |
Author
|
Hi
Sure understand but i have also given a fix to this issue. I hope you merge
it to the trunk. It will take some time and effort for people to move to
the new library...please take a look at the fix i hv given.
Thanks
Mayank Beri
On 25 Nov. 2017 23:41, "Hsiaoming Yang" <notifications@github.com> wrote:
With the release of Authlib 0.2. It is stable enough to use the Flask
Client in Authlib. It is more stable than Flask-OAuthlib.
authlib/authlib#2 <authlib/authlib#2>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#361 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Adgh7wY5jV9Yvumgn4ZI-rHi8DL80ucBks5s6Ar0gaJpZM4QmvZ_>
.
|
lepture
reviewed
Nov 26, 2017
flask_oauthlib/client.py
Outdated
| type='invalid_response', data=data | ||
| ) | ||
| return data | ||
| return {'accessToken':None,'code':resp.code, 'msg':resp.msg} |
Owner
There was a problem hiding this comment.
This will introduce a break change.
flask_oauthlib/client.py
Outdated
| type='invalid_response', data=data | ||
| ) | ||
| return data | ||
| return {'accessToken':None,'code':resp.code, 'msg':resp.msg} |
Owner
There was a problem hiding this comment.
This will introduce a break change.
flask_oauthlib/client.py
Outdated
|
|
||
| if strict: | ||
| return content | ||
| else: |
| return json.loads(content) | ||
|
|
||
| except Exception as exception: | ||
| log.debug("The content is not json") |
Owner
There was a problem hiding this comment.
single quote please.
And there are too many blank lines.
1. Fixed the code to handle content_type missing from headers. instead of defaulting it to JSON, now trying to load it to json, xml, or then simply returning the content. Code was failing when the content_type was missing but the content was not of json type. 2. Handled the case where an exception was raised when the token URL responsed in a code other than 200 or 201. Instead of raising OauthException now returning the error code in a dictionary so that it can be handled or displayed.
1. Fixed the code to handle content_type missing from headers. instead of defaulting it to JSON, now trying to load it to json, xml, or then simply returning the content. Code was failing when the content_type was missing but the content was not of json type. 2. Handled the case where an exception was raised when the token URL responsed in a code other than 200 or 201. Instead of raising OauthException now returning the error code in a dictionary so that it can be handled or displayed.
Author
|
Hi,
I have made a new commit without the changes to return type when URI
returns an error. However, below code raises an exception which is not
callable from flask and hence breaks the application. Instead of raising
the exception I am returning blank accesstoken and error code and
description when there is an error. I feel this is better than raising the
exception.
if resp.code not in (200, 201):
raise OAuthException(
'Invalid response from %s' % self.name,
type='invalid_response', data=data
)
return data
Thanks & Regards,
Mayank Beri
Melbourne
Mob +61-432019619 <+61%20432%20019%20619>
On Sun, Nov 26, 2017 at 2:13 PM, Hsiaoming Yang ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In flask_oauthlib/client.py
<#361 (comment)>
:
> 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}
This will introduce a break change.
currently the code returns an exception and instead with return the
dictionary
… ------------------------------
In flask_oauthlib/client.py
<#361 (comment)>
:
> 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}
This will introduce a break change.
------------------------------
In flask_oauthlib/client.py
<#361 (comment)>
:
> +
+ 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:
no need for else.
------------------------------
In flask_oauthlib/client.py
<#361 (comment)>
:
> 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")
single quote please.
And there are too many blank lines.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#361 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Adgh7064P0QkALhLcRAG8Ww69-qcuiocks5s6NdGgaJpZM4QmvZ_>
.
|
Owner
|
You should catch the OAuthException with Flask error handler. Or you can use try catch pattern. |
Author
|
Hi,
yes thanks, I will do that. I hope you have accepted the other change.
Thanks
Mayank Beri
Thanks & Regards,
Mayank Beri
Melbourne
Mob +61-432019619
…On Mon, Nov 27, 2017 at 12:32 AM, Hsiaoming Yang ***@***.***> wrote:
You should catch the OAuthException with Flask error handler. Or you can
use try catch pattern.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#361 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Adgh7z_oE5kRjxTsVfFVXSjP3g7ExFFEks5s6WhcgaJpZM4QmvZ_>
.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed the code to handle content_type missing from headers. instead of defaulting it to JSON, now trying to load it to json, xml, or then simply returning the content. Code was failing when the content_type was missing but the content was not of json type.
Handled the case where an exception was raised when the token URL responsed in a code other than 200 or 201. Instead of raising OauthException now returning the error code in a dictionary so that it can be handled or displayed.