Skip to content

Commit 8a38044

Browse files
Copilotnijel
andauthored
Add documentation for OAuth2 URL override and backend-specific Django middleware settings (#336)
* Initial plan * Add documentation for OAuth2 URL override and backend-specific Django middleware settings Co-authored-by: nijel <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: nijel <[email protected]>
1 parent 7753aa3 commit 8a38044

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

docs/configuration/django.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,29 @@ available at ``request.strategy.backend`` and ``process_exception()`` will
305305
use it to build a backend-dependent redirect URL but fallback to default if not
306306
defined.
307307

308+
Backend-specific settings
309+
^^^^^^^^^^^^^^^^^^^^^^^^^^
310+
311+
Both the ``LOGIN_ERROR_URL`` and ``RAISE_EXCEPTIONS`` settings can be configured
312+
on a per-backend basis. This allows you to customize error handling behavior for
313+
specific authentication backends.
314+
315+
To define backend-specific error URLs, use the backend name in the setting::
316+
317+
SOCIAL_AUTH_LOGIN_ERROR_URL = '/login-error/' # Default for all backends
318+
SOCIAL_AUTH_FACEBOOK_LOGIN_ERROR_URL = '/facebook-error/' # Specific to Facebook
319+
SOCIAL_AUTH_GOOGLE_OAUTH2_LOGIN_ERROR_URL = '/google-error/' # Specific to Google OAuth2
320+
321+
Similarly, you can control exception raising on a per-backend basis::
322+
323+
SOCIAL_AUTH_RAISE_EXCEPTIONS = False # Default for all backends
324+
SOCIAL_AUTH_FACEBOOK_RAISE_EXCEPTIONS = True # Raise exceptions only for Facebook
325+
326+
This is particularly useful when you want different error handling strategies for
327+
different authentication providers, such as showing a custom error page for certain
328+
providers or raising exceptions for debugging specific backends while keeping
329+
others in production mode.
330+
308331
Exception processing is disabled if any of this settings is defined with a
309332
``True`` value::
310333

docs/configuration/settings.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,42 @@ settings in the same way explained above but with this other suffix::
191191

192192
SOCIAL_AUTH_<uppercase backend name>_REQUEST_TOKEN_EXTRA_ARGUMENTS = {...}
193193

194+
195+
OAuth2 provider URLs override
196+
------------------------------
197+
198+
By default, OAuth2 backends have hardcoded URLs for authorization and access token
199+
endpoints. However, these can be overridden via settings to support custom OAuth2
200+
providers or alternate deployments of the same provider (e.g., OpenHistoricalMap
201+
instead of OpenStreetMap, or self-hosted instances).
202+
203+
``SOCIAL_AUTH_AUTHORIZATION_URL``
204+
Override the authorization URL for OAuth2 backends globally or per-backend.
205+
Example::
206+
207+
SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL = 'https://auth.example.com/auth/realms/myrealm/protocol/openid-connect/auth'
208+
209+
``SOCIAL_AUTH_ACCESS_TOKEN_URL``
210+
Override the access token URL for OAuth2 backends globally or per-backend.
211+
Example::
212+
213+
SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL = 'https://auth.example.com/auth/realms/myrealm/protocol/openid-connect/token'
214+
215+
``SOCIAL_AUTH_REVOKE_TOKEN_URL``
216+
Override the token revocation URL for OAuth2 backends globally or per-backend.
217+
Example::
218+
219+
SOCIAL_AUTH_GITHUB_REVOKE_TOKEN_URL = 'https://github.example.com/api/revoke'
220+
221+
These settings allow you to use backends with custom deployments. For example,
222+
to use the OpenStreetMap backend with OpenHistoricalMap::
223+
224+
SOCIAL_AUTH_OPENSTREETMAP_AUTHORIZATION_URL = 'https://www.openhistoricalmap.org/oauth/authorize'
225+
SOCIAL_AUTH_OPENSTREETMAP_ACCESS_TOKEN_URL = 'https://www.openhistoricalmap.org/oauth/access_token'
226+
227+
Note that backend-specific settings (with the backend name) take precedence over
228+
generic settings, following the same pattern as other settings in this library.
229+
194230
Basic information is requested to the different providers in order to create
195231
a coherent user instance (with first and last name, email and full name), this
196232
could be too intrusive for some sites that want to ask users the minimum data

0 commit comments

Comments
 (0)