Skip to content

Commit

Permalink
Merge pull request #77 from akatsoulas/minor-fixes
Browse files Browse the repository at this point in the history
Simplify the logout view.
  • Loading branch information
akatsoulas committed Jan 12, 2017
2 parents 5c0585c + 6be05a3 commit c4d60db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
8 changes: 3 additions & 5 deletions mozilla_django_oidc/contrib/auth0/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
except ImportError:
from urllib.parse import urlencode

from django.http import HttpResponseRedirect

from mozilla_django_oidc.utils import import_from_settings


Expand All @@ -26,11 +24,11 @@ def refresh_id_token(id_token):
return None


def logout(request):
def logout_url():
"""Log out the user from Auth0."""
url = 'https//' + import_from_settings('OIDC_OP_DOMAIN') + '/v2/logout'
url += '?' + urlencode({
'returnTo': import_from_settings('OIDC_OP_LOGOUT_URL', '/'),
'returnTo': import_from_settings('LOGOUT_REDIRECT_URL', '/'),
'client_id': import_from_settings('OIDC_RP_CLIENT_ID')
})
return HttpResponseRedirect(url)
return url
15 changes: 9 additions & 6 deletions mozilla_django_oidc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,13 @@ def dispatch(self, request, *args, **kwargs):
"""Log out the user."""

if request.user.is_authenticated():
auth.logout(request)
logout_url = self.redirect_url

# Check if a method exists to build the url to logout the user from the OP
logout_from_op = import_from_settings('OIDC_OP_LOGOUT_URL_METHOD', '')
if logout_from_op:
logout_url = import_string(logout_from_op)

logout_view_path = import_from_settings('OIDC_OP_LOGOUT_VIEW', '')
if logout_view_path:
logout_view = import_string(logout_view_path)
return logout_view(request)
return HttpResponseRedirect(self.redirect_url)
# Log out the Django user.
auth.logout(request)
return HttpResponseRedirect(logout_url)

0 comments on commit c4d60db

Please sign in to comment.