diff --git a/apps/authentication/backends/base.py b/apps/authentication/backends/base.py index 5e8ac7556..9fb83df58 100644 --- a/apps/authentication/backends/base.py +++ b/apps/authentication/backends/base.py @@ -1,9 +1,10 @@ -from django.contrib.auth.backends import ModelBackend from django.contrib.auth import get_user_model +from django.contrib.auth.backends import ModelBackend +from django.views import View -from users.models import User +from authentication.views.utils import redirect_to_guard_view from common.utils import get_logger - +from users.models import User UserModel = get_user_model() logger = get_logger(__file__) @@ -62,3 +63,10 @@ class JMSBaseAuthBackend: class JMSModelBackend(JMSBaseAuthBackend, ModelBackend): pass + + +class BaseAuthCallbackClientView(View): + http_method_names = ['get'] + + def get(self, request): + return redirect_to_guard_view(query_string='next=client') diff --git a/apps/authentication/backends/cas/views.py b/apps/authentication/backends/cas/views.py index 0e150008a..ffa676ea6 100644 --- a/apps/authentication/backends/cas/views.py +++ b/apps/authentication/backends/cas/views.py @@ -1,11 +1,10 @@ from django.core.exceptions import PermissionDenied from django.http import HttpResponseRedirect -from django.views.generic import View from django_cas_ng.views import LoginView -__all__ = ['LoginView'] +from authentication.backends.base import BaseAuthCallbackClientView -from authentication.views.utils import redirect_to_guard_view +__all__ = ['LoginView'] class CASLoginView(LoginView): @@ -16,8 +15,5 @@ class CASLoginView(LoginView): return HttpResponseRedirect('/') -class CASCallbackClientView(View): - http_method_names = ['get', ] - - def get(self, request): - return redirect_to_guard_view(query_string='next=client') +class CASCallbackClientView(BaseAuthCallbackClientView): + pass diff --git a/apps/authentication/backends/oauth2/views.py b/apps/authentication/backends/oauth2/views.py index 6eb324863..899bdcb34 100644 --- a/apps/authentication/backends/oauth2/views.py +++ b/apps/authentication/backends/oauth2/views.py @@ -5,10 +5,10 @@ from django.urls import reverse from django.utils.http import urlencode from django.views import View +from authentication.backends.base import BaseAuthCallbackClientView from authentication.mixins import authenticate from authentication.utils import build_absolute_uri from authentication.views.mixins import FlashMessageMixin -from authentication.views.utils import redirect_to_guard_view from common.utils import get_logger logger = get_logger(__file__) @@ -67,11 +67,8 @@ class OAuth2AuthCallbackView(View, FlashMessageMixin): return HttpResponseRedirect(redirect_url) -class OAuth2AuthCallbackClientView(View): - http_method_names = ['get', ] - - def get(self, request): - return redirect_to_guard_view(query_string='next=client') +class OAuth2AuthCallbackClientView(BaseAuthCallbackClientView): + pass class OAuth2EndSessionView(View): diff --git a/apps/authentication/backends/oidc/views.py b/apps/authentication/backends/oidc/views.py index e108e8d69..844c3a4c1 100644 --- a/apps/authentication/backends/oidc/views.py +++ b/apps/authentication/backends/oidc/views.py @@ -29,7 +29,7 @@ from authentication.utils import build_absolute_uri_for_oidc from authentication.views.mixins import FlashMessageMixin from common.utils import safe_next_url from .utils import get_logger -from ...views.utils import redirect_to_guard_view +from ..base import BaseAuthCallbackClientView logger = get_logger(__file__) @@ -210,11 +210,8 @@ class OIDCAuthCallbackView(View, FlashMessageMixin): return HttpResponseRedirect(settings.AUTH_OPENID_AUTHENTICATION_FAILURE_REDIRECT_URI) -class OIDCAuthCallbackClientView(View): - http_method_names = ['get', ] - - def get(self, request): - return redirect_to_guard_view(query_string='next=client') +class OIDCAuthCallbackClientView(BaseAuthCallbackClientView): + pass class OIDCEndSessionView(View): diff --git a/apps/authentication/backends/saml2/views.py b/apps/authentication/backends/saml2/views.py index 2ea39efd3..b423460cc 100644 --- a/apps/authentication/backends/saml2/views.py +++ b/apps/authentication/backends/saml2/views.py @@ -19,7 +19,7 @@ from onelogin.saml2.idp_metadata_parser import ( from authentication.views.mixins import FlashMessageMixin from common.utils import get_logger from .settings import JmsSaml2Settings -from ...views.utils import redirect_to_guard_view +from ..base import BaseAuthCallbackClientView logger = get_logger(__file__) @@ -300,11 +300,8 @@ class Saml2AuthCallbackView(View, PrepareRequestMixin, FlashMessageMixin): return super().dispatch(*args, **kwargs) -class Saml2AuthCallbackClientView(View): - http_method_names = ['get', ] - - def get(self, request): - return redirect_to_guard_view(query_string='next=client') +class Saml2AuthCallbackClientView(BaseAuthCallbackClientView): + pass class Saml2AuthMetadataView(View, PrepareRequestMixin):