Skip to content

Commit

Permalink
Fix logout redirect url
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysyngsun committed Jul 9, 2024
1 parent bf9e851 commit 9fff581
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from django.conf import settings
from django.contrib.auth import views
from django.http import Http404
from django.shortcuts import redirect
from social_django.utils import load_strategy

Expand Down Expand Up @@ -37,25 +36,30 @@ def _keycloak_logout_url(self, user):
qs = urlencode(
{
"id_token_hint": id_token,
"post_logout_redirect_uri": settings.LOGOUT_REDIRECT_URL,
"post_logout_redirect_uri": self.request.build_absolute_uri(
settings.LOGOUT_REDIRECT_URL
),
}
)
return f"{settings.KEYCLOAK_BASE_URL}/realms/{settings.KEYCLOAK_REALM_NAME}/protocol/openid-connect/logout?{qs}" # noqa: E501

return (
f"{settings.KEYCLOAK_BASE_URL}/realms/"
f"{settings.KEYCLOAK_REALM_NAME}/protocol/openid-connect/logout"
f"?{qs}"
)

def get(
self,
request,
*args, # noqa: ARG002
**kwargs, # noqa: ARG002
): # pylint:disable=unused-argument
):
"""
GET endpoint for loggin a user out.
Raises 404 if the user is not included in the request.
POST endpoint for loggin a user out.
"""
user = getattr(request, "user", None)
if user and user.is_authenticated:
super().get(request)
super().post(request)
return redirect(self._keycloak_logout_url(user))
else:
msg = "Not currently logged in."
raise Http404(msg)
return redirect("/app")

0 comments on commit 9fff581

Please sign in to comment.