feat(pkgs): Add django-allauth and django-allauth-cas

This commit is contained in:
Tom Hubrecht 2024-09-18 22:14:40 +02:00
parent 763c2dfcbb
commit 1732249a2d
Signed by: thubrecht
SSH key fingerprint: SHA256:r+nK/SIcWlJ0zFZJGHtlAoRwq1Rm+WcKAm5ADYMoQPc
8 changed files with 171 additions and 1 deletions

View file

@ -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):
"""

View file

@ -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

View file

@ -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 ];
};
}

View file

@ -37,6 +37,8 @@ INSTALLED_APPS = [
"allauth.account",
"allauth.socialaccount",
"allauth.socialaccount.providers.openid_connect",
"allauth_cas",
"shared.cas",
# Main app
"dgsi",
]

View file

View file

@ -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]

5
src/shared/cas/urls.py Normal file
View file

@ -0,0 +1,5 @@
from allauth_cas.urls import default_urlpatterns
from .provider import CASProvider
urlpatterns = default_urlpatterns(CASProvider)

14
src/shared/cas/views.py Normal file
View file

@ -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)