diff --git a/pkgs/django-allauth-cas/02-registry.patch b/pkgs/django-allauth-cas/02-registry.patch new file mode 100644 index 0000000..cfd905f --- /dev/null +++ b/pkgs/django-allauth-cas/02-registry.patch @@ -0,0 +1,39 @@ +diff --git a/allauth_cas/signals.py b/allauth_cas/signals.py +index 36c9b24..530c26e 100644 +--- a/allauth_cas/signals.py ++++ b/allauth_cas/signals.py +@@ -1,4 +1,4 @@ +-from allauth.account.adapter import get_adapter ++from allauth.socialaccount.adapter import get_adapter + from allauth.account.utils import get_next_redirect_url + from allauth.socialaccount import providers + from django.contrib.auth.signals import user_logged_out +@@ -14,7 +14,7 @@ def cas_account_logout(sender, request, **kwargs): + if not provider_id: + return + +- provider = providers.registry.by_id(provider_id, request) ++ provider = get_adapter(request).get_provider(request, provider_id) + + if not provider.message_suggest_caslogout_on_logout(request): + return +diff --git a/allauth_cas/views.py b/allauth_cas/views.py +index d08e354..9e81e53 100644 +--- a/allauth_cas/views.py ++++ b/allauth_cas/views.py +@@ -1,5 +1,5 @@ + import cas +-from allauth.account.adapter import get_adapter ++from allauth.socialaccount.adapter import get_adapter + from allauth.account.utils import get_next_redirect_url + from allauth.socialaccount import providers + from allauth.socialaccount.helpers import ( +@@ -56,7 +56,7 @@ class CASAdapter: + """ + Returns a provider instance for the current request. + """ +- return providers.registry.by_id(self.provider_id, self.request) ++ return get_adapter(self.request).get_provider(self.request, self.provider_id) + + def complete_login(self, request, response): + """ diff --git a/pkgs/django-allauth-cas/default.nix b/pkgs/django-allauth-cas/default.nix index 8721e21..7914852 100644 --- a/pkgs/django-allauth-cas/default.nix +++ b/pkgs/django-allauth-cas/default.nix @@ -20,7 +20,10 @@ buildPythonPackage rec { hash = "sha256-y/IquXl/4+9MJmsgbWtPun3tBbRJ4kJFzWo5c+5WeHk="; }; - patches = [ ./01-setup.patch ]; + patches = [ + ./01-setup.patch + ./02-registry.patch + ]; build-system = [ setuptools diff --git a/pkgs/django-allauth/default.nix b/pkgs/django-allauth/default.nix new file mode 100644 index 0000000..509c3b1 --- /dev/null +++ b/pkgs/django-allauth/default.nix @@ -0,0 +1,96 @@ +{ + lib, + buildPythonPackage, + fetchFromGitHub, + pythonOlder, + # build-system + setuptools, + # dependencies + django, + python3-openid, + requests, + requests-oauthlib, + pyjwt, + # optional-dependencies + python3-saml, + qrcode, + fido2, + # tests + pillow, + pytestCheckHook, + pytest-django, + # passthru tests + dj-rest-auth, +}: + +buildPythonPackage rec { + pname = "django-allauth"; + version = "64.2.1"; + pyproject = true; + + disabled = pythonOlder "3.7"; + + src = fetchFromGitHub { + owner = "pennersr"; + repo = "django-allauth"; + rev = "refs/tags/${version}"; + hash = "sha256-JKjM+zqrXidxpbi+fo6wbvdXlw2oDYH51EsvQ5yp3R8="; + }; + + nativeBuildInputs = [ + setuptools + ]; + + propagatedBuildInputs = [ + django + ]; + + passthru.optional-dependencies = { + mfa = [ + qrcode + fido2 + ]; + openid = [ + python3-openid + ]; + saml = [ + python3-saml + ]; + socialaccount = [ + pyjwt + requests + requests-oauthlib + ] ++ pyjwt.optional-dependencies.crypto; + steam = [ + python3-openid + ]; + }; + + pythonImportsCheck = [ + "allauth" + ]; + + nativeCheckInputs = [ + pillow + pytestCheckHook + pytest-django + ] ++ lib.flatten (builtins.attrValues passthru.optional-dependencies); + + disabledTests = [ + # Tests require network access + "test_login" + ]; + + passthru.tests = { + inherit dj-rest-auth; + }; + + meta = with lib; { + changelog = "https://github.com/pennersr/django-allauth/blob/${version}/ChangeLog.rst"; + description = "Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication"; + downloadPage = "https://github.com/pennersr/django-allauth"; + homepage = "https://www.intenct.nl/projects/django-allauth"; + license = licenses.mit; + maintainers = with maintainers; [ derdennisop ]; + }; +} diff --git a/src/app/settings.py b/src/app/settings.py index 08e8d03..abca0ea 100644 --- a/src/app/settings.py +++ b/src/app/settings.py @@ -37,6 +37,8 @@ INSTALLED_APPS = [ "allauth.account", "allauth.socialaccount", "allauth.socialaccount.providers.openid_connect", + "allauth_cas", + "shared.cas", # Main app "dgsi", ] diff --git a/src/shared/cas/__init__.py b/src/shared/cas/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/shared/cas/provider.py b/src/shared/cas/provider.py new file mode 100644 index 0000000..fea3fa4 --- /dev/null +++ b/src/shared/cas/provider.py @@ -0,0 +1,11 @@ +from allauth.socialaccount.providers.base import ProviderAccount +from allauth_cas.providers import CASProvider as Provider + + +class CASProvider(Provider): + id = "cas" # Choose an identifier for your provider + name = "CAS ENS" # Verbose name of your provider + account_class = ProviderAccount + + +provider_classes = [CASProvider] diff --git a/src/shared/cas/urls.py b/src/shared/cas/urls.py new file mode 100644 index 0000000..34c1ea1 --- /dev/null +++ b/src/shared/cas/urls.py @@ -0,0 +1,5 @@ +from allauth_cas.urls import default_urlpatterns + +from .provider import CASProvider + +urlpatterns = default_urlpatterns(CASProvider) diff --git a/src/shared/cas/views.py b/src/shared/cas/views.py new file mode 100644 index 0000000..51bfd00 --- /dev/null +++ b/src/shared/cas/views.py @@ -0,0 +1,14 @@ +from allauth_cas.views import CASAdapter as Adapter +from allauth_cas.views import CASCallbackView, CASLoginView + +from .provider import CASProvider + + +class CASAdapter(Adapter): + provider_id = CASProvider.id + url = "https://cas.eleves.ens.fr" + version = 3 + + +login = CASLoginView.adapter_view(CASAdapter) +callback = CASCallbackView.adapter_view(CASAdapter)