Skip to content

Commit

Permalink
Update logout() to use django's LOGOUT_REDIRECT_URL setting, and to l…
Browse files Browse the repository at this point in the history
…ogout on GET
  • Loading branch information
ababic committed Jul 1, 2022
1 parent 26fc10c commit 32e9410
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
2 changes: 2 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
AUTH_URLS = "allauth.urls"
LOGIN_URL = "/accounts/login"
LOGIN_REDIRECT_URL = "/"
LOGOUT_URL = "/accounts/logout"
LOGOUT_REDIRECT_URL = "/"
WAGTAIL_FRONTEND_LOGIN_URL = LOGIN_URL
# View access control
IMAGE_VIEWER_REQUIRE_LOGIN = strtobool(os.getenv("IMAGE_VIEWER_REQUIRE_LOGIN", "True"))
Expand Down
29 changes: 12 additions & 17 deletions etna/auth0/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.contrib.auth import login as auth_login
from django.contrib.auth import logout as auth_logout
from django.http import HttpResponseRedirect
from django.shortcuts import redirect, render
from django.shortcuts import redirect
from django.urls import reverse
from django.utils import timezone

Expand Down Expand Up @@ -124,20 +124,15 @@ def authorize(request):


def logout(request):
if request.method != "POST":
return render(request, "account/logout.html")
success_url = settings.LOGOUT_REDIRECT_URL
auth_logout(request)
redirect_to = "/"
if settings.TERMINATE_SSO_SESSION_ON_LOGOUT:
return redirect(
f"https://{settings.AUTH0_DOMAIN}/v2/logout?"
+ urlencode(
{
"returnTo": request.build_absolute_uri(redirect_to),
"client_id": settings.AUTH0_CLIENT_ID,
},
quote_via=quote_plus,
),
)
else:
return HttpResponseRedirect(redirect_to)
return redirect(
f"https://{settings.AUTH0_DOMAIN}/v2/logout?"
+ urlencode(
{
"returnTo": request.build_absolute_uri(success_url),
"client_id": settings.AUTH0_CLIENT_ID,
},
quote_via=quote_plus,
),
)

0 comments on commit 32e9410

Please sign in to comment.