Skip to content

Commit c52480b

Browse files
authored
Merge pull request #2359 from unicef/11956-auth-errors-hotfix
Add SocialAuthException middleware
2 parents c15c59c + 3a0ec86 commit c52480b

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/etools/config/settings/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def get_from_secrets_or_env(var_name, default=None):
124124
'corsheaders.middleware.CorsMiddleware',
125125
'etools.applications.core.middleware.EToolsTenantMiddleware',
126126
'waffle.middleware.WaffleMiddleware', # needs request.tenant from EToolsTenantMiddleware
127+
'etools.libraries.social_django.middleware.SocialAuthExceptionMiddleware',
127128
)
128129
WSGI_APPLICATION = 'etools.config.wsgi.application'
129130

src/etools/libraries/social_django/__init__.py

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django.shortcuts import HttpResponseRedirect
2+
from django.urls import reverse
3+
from django.conf import settings
4+
5+
from social_core import exceptions as social_exceptions
6+
from social_django.middleware import SocialAuthExceptionMiddleware
7+
8+
9+
class SocialAuthExceptionMiddleware(SocialAuthExceptionMiddleware):
10+
def process_exception(self, request, exception):
11+
if hasattr(social_exceptions, 'AuthCanceled'):
12+
return HttpResponseRedirect(reverse(settings.LOGIN_URL))
13+
else:
14+
raise exception

0 commit comments

Comments
 (0)