python-social-auth / social-core

Python Social Auth - Core
BSD 3-Clause "New" or "Revised" License
847 stars 544 forks source link

Provide a specific error for connection related issue #916

Open sevdog opened 4 months ago

sevdog commented 4 months ago

Expected behaviour

Whenever a network/connection problem it could be useful to distinguish it directly from a logic authentication error. This could improve filtering based on exception type (ie: to handle logging in django integration).

Actual behaviour

Currently the wrapper on remote requests intercepts connection-related exceptions and transforms them into generic AuthFailed exceptions, masking the underlaying exception.

https://github.com/python-social-auth/social-core/blob/95316b0914386af59d8649917c373a594f1766de/social_core/backends/base.py#L244-L245

Currently the only method to distinguish this case by using the __cause__ attribute which involves more code than a try-except.

What are the steps to reproduce this issue?

  1. be offline
  2. try to connect to a provider which is not hosted on your host

OR

  1. create a self-signed SSL cert for a local provider
  2. configure provider to be used without bypassing cert verification
  3. try to connect to that provider

In both cases we are going to receive a simple AuthFailed exception and we need to parse the message to identify what happened.