1 from allauth.socialaccount.models import SocialAccount

2 from django.conf import settings

3 from django.contrib.auth import logout

4 from django.contrib.auth.mixins import LoginRequiredMixin

5 from django.http import HttpResponseRedirect

6 from django.shortcuts import reverse

7 from django.views import View

8

9

10 class LogoutView(LoginRequiredMixin, View):

11 def get(self, request):

12 try:

13 SocialAccount.objects.get(user=request.user)

14 logout(request)

15 return HttpResponseRedirect(

16 f"{settings.KEYCLOAK_BASE_URL}/realms/{settings.KEYCLOAK_REALM}/protocol/openid-connect/logout?post_logout_redirect_uri={settings.MESH_SERVER_URL}&client_id={settings.KEYCLOAK_REALM}"

17 )

18 except SocialAccount.DoesNotExist:

19 logout(request)

20 return HttpResponseRedirect(reverse("networks:network-list"))