authlib icon indicating copy to clipboard operation
authlib copied to clipboard

fetch_access_token() no longer raises OAuthError but HTTPError instead.

Open Fnordbert opened this issue 2 years ago • 1 comments

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.

Fnordbert avatar May 04 '22 17:05 Fnordbert

Got it, it is raised by resp.raise_for_status().

Thanks for the report.

lepture avatar May 05 '22 11:05 lepture

For what it's worth, the change in oauth2/client.py solved the issue for me.

Fnordbert avatar Aug 22 '22 13:08 Fnordbert