Logout next url can be local or absolute

This commit is contained in:
Martin Pépin 2020-06-10 23:23:33 +02:00
parent 8e95a01647
commit 352fedb8b2
No known key found for this signature in database
GPG key ID: E7520278B1774448

View file

@ -1,4 +1,4 @@
from urllib.parse import urlunparse from urllib.parse import urlparse, urlunparse
from django.conf import settings from django.conf import settings
from django.contrib import auth from django.contrib import auth
@ -98,8 +98,14 @@ class LogoutView(auth_views.LogoutView):
next_page = super().get_next_page() next_page = super().get_next_page()
if self.cas_connected: if self.cas_connected:
cas_client = get_cas_client(self.request) cas_client = get_cas_client(self.request)
redirect_url = urlunparse(
(self.request.scheme, self.request.get_host(), next_page, "", "", "") # If the next_url is local (no hostname), make it absolute so that the user
) # is correctly redirected from CAS.
next_page = cas_client.get_logout_url(redirect_url=redirect_url) if not urlparse(next_page).netloc:
request = self.request
next_page = urlunparse(
(request.scheme, request.get_host(), next_page, "", "", "")
)
next_page = cas_client.get_logout_url(redirect_url=next_page)
return next_page return next_page