authlib
authlib copied to clipboard
fetch_access_token() no longer raises OAuthError but HTTPError instead.
Describe the bug
A change introduced in 1.0.0 makes fetch_access_token()
return a requests.exceptions.HTTPError
instead of an OAuthError
.
Tested in Flask integration.
To Reproduce
Run code equivalent to this in a working Flask config.
try:
token = oauth.myOauth2.fetch_access_token(
username=request.form.get('username'),
password=request.form.get('password')
)
except OAuthError as e:
if e.description:
flash(e.description)
return render_template('login.html')
raise
Both valid and invalid user/pwd works as expected in 0.15.5. Valid login works in 1.0.0, but invalid raises an HTTPError.
The error response contains what looks like the expected json: {'error': 'invalid_grant', 'error_description': 'INVALID_CREDENTIALS'}
Expected behavior
An OAuthError exception is raised on invalid login.
Environment:
- OS: Windows Server 2016
- Python Version: 3.8.1
- Authlib Version: 0.15.5 / 1.0.0
Additional context
All other packages are up to date pt. I was advised that this is the correct way to do password grant flow.
Got it, it is raised by resp.raise_for_status()
.
Thanks for the report.
For what it's worth, the change in oauth2/client.py
solved the issue for me.