-
Notifications
You must be signed in to change notification settings - Fork 453
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?
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.
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. |
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.
lepture/authlib#2 <lepture/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_>
.
|
flask_oauthlib/client.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
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} |
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.
This will introduce a break change.
flask_oauthlib/client.py
Outdated
|
||
if strict: | ||
return content | ||
else: |
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.
no need for else.
flask_oauthlib/client.py
Outdated
return json.loads(content) | ||
|
||
except Exception as exception: | ||
log.debug("The content is not json") |
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.
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.
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_>
.
|
You should catch the OAuthException with Flask error handler. Or you can use try catch pattern. |
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_>
.
|
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.