Skip to content

Commit c4d60db

Browse files
authored
Merge pull request #77 from akatsoulas/minor-fixes
Simplify the logout view.
2 parents 5c0585c + 6be05a3 commit c4d60db

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

mozilla_django_oidc/contrib/auth0/utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
except ImportError:
55
from urllib.parse import urlencode
66

7-
from django.http import HttpResponseRedirect
8-
97
from mozilla_django_oidc.utils import import_from_settings
108

119

@@ -26,11 +24,11 @@ def refresh_id_token(id_token):
2624
return None
2725

2826

29-
def logout(request):
27+
def logout_url():
3028
"""Log out the user from Auth0."""
3129
url = 'https//' + import_from_settings('OIDC_OP_DOMAIN') + '/v2/logout'
3230
url += '?' + urlencode({
33-
'returnTo': import_from_settings('OIDC_OP_LOGOUT_URL', '/'),
31+
'returnTo': import_from_settings('LOGOUT_REDIRECT_URL', '/'),
3432
'client_id': import_from_settings('OIDC_RP_CLIENT_ID')
3533
})
36-
return HttpResponseRedirect(url)
34+
return url

mozilla_django_oidc/views.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,13 @@ def dispatch(self, request, *args, **kwargs):
116116
"""Log out the user."""
117117

118118
if request.user.is_authenticated():
119-
auth.logout(request)
119+
logout_url = self.redirect_url
120+
121+
# Check if a method exists to build the url to logout the user from the OP
122+
logout_from_op = import_from_settings('OIDC_OP_LOGOUT_URL_METHOD', '')
123+
if logout_from_op:
124+
logout_url = import_string(logout_from_op)
120125

121-
logout_view_path = import_from_settings('OIDC_OP_LOGOUT_VIEW', '')
122-
if logout_view_path:
123-
logout_view = import_string(logout_view_path)
124-
return logout_view(request)
125-
return HttpResponseRedirect(self.redirect_url)
126+
# Log out the Django user.
127+
auth.logout(request)
128+
return HttpResponseRedirect(logout_url)

0 commit comments

Comments
 (0)