From bb0530fe6e346168cc5bdd7eae43916ac78aecec Mon Sep 17 00:00:00 2001 From: MJedr Date: Tue, 7 Nov 2023 15:38:14 +0100 Subject: [PATCH] add social django --- config/settings/base.py | 12 ++++++++++-- config/urls.py | 2 ++ poetry.lock | 43 ++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/config/settings/base.py b/config/settings/base.py index 7f939426..584b8b0e 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -97,6 +97,7 @@ "corsheaders", "drf_spectacular", "oauth2_provider", + "social_django", ] LOCAL_APPS = ["backoffice.users", "backoffice.workflows", "backoffice.management"] @@ -201,6 +202,8 @@ "django.template.context_processors.tz", "django.contrib.messages.context_processors.messages", "backoffice.users.context_processors.allauth_settings", + "social_django.context_processors.backends", + "social_django.context_processors.login_redirect", ], }, } @@ -352,5 +355,10 @@ "VERSION": "1.0.0", "SERVE_PERMISSIONS": ["rest_framework.permissions.IsAdminUser"], } -# Your stuff... -# ------------------------------------------------------------------------------ +# OAuth +SOCIAL_AUTH_JSONFIELD_ENABLED = True +SOCIAL_AUTH_AUTHENTICATION_BACKENDS = ( + "social_core.backends.orcid.OrcidOAuth2", + "django.contrib.auth.backends.ModelBackend", +) +SOCIAL_AUTH_USER_MODEL = "users.User" diff --git a/config/urls.py b/config/urls.py index 19654adc..dd57ea5a 100644 --- a/config/urls.py +++ b/config/urls.py @@ -7,6 +7,7 @@ from django.views.generic import TemplateView from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView from rest_framework.authtoken.views import obtain_auth_token +from social_django.urls import urlpatterns as social_django_urls urlpatterns = [ path("", TemplateView.as_view(template_name="pages/home.html"), name="home"), @@ -14,6 +15,7 @@ # Django Admin, use {% url 'admin:index' %} path(settings.ADMIN_URL, admin.site.urls), path("oauth2/", include("oauth2_provider.urls", namespace="oauth2_provider")), + path("auth/", include(social_django_urls, namespace="social")), # User management path("users/", include("backoffice.users.urls", namespace="users")), path("accounts/", include("allauth.urls")), diff --git a/poetry.lock b/poetry.lock index b0b0aabf..e1a9e8b7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -3029,6 +3029,47 @@ files = [ {file = "sniffio-1.3.0.tar.gz", hash = "sha256:e60305c5e5d314f5389259b7f22aaa33d8f7dee49763119234af3755c55b9101"}, ] +[[package]] +name = "social-auth-app-django" +version = "5.4.0" +description = "Python Social Authentication, Django integration." +optional = false +python-versions = ">=3.8" +files = [ + {file = "social-auth-app-django-5.4.0.tar.gz", hash = "sha256:09ac02a063cb313eed5e9ef2f9ac4477c8bf5bbd685925ff3aba43f9072f1bbb"}, + {file = "social_auth_app_django-5.4.0-py3-none-any.whl", hash = "sha256:28c65b2e2092f30cdb3cf912eeaa6988b49fdf4001b29bd89e683673d700a38e"}, +] + +[package.dependencies] +Django = ">=3.2" +social-auth-core = ">=4.4.1" + +[[package]] +name = "social-auth-core" +version = "4.5.0" +description = "Python social authentication made simple." +optional = false +python-versions = ">=3.8" +files = [ + {file = "social-auth-core-4.5.0.tar.gz", hash = "sha256:3d4154f45c0bacffe54ccf4361bce7e66cf5f5cd1bb0ebb7507ad09a1b07d9d9"}, + {file = "social_auth_core-4.5.0-py3-none-any.whl", hash = "sha256:f4ae5d8e503a401f319498bcad59fd1f6c473517eeae89c22299250f63c33365"}, +] + +[package.dependencies] +cryptography = ">=1.4" +defusedxml = ">=0.5.0rc1" +oauthlib = ">=1.0.3" +PyJWT = ">=2.7.0" +python3-openid = ">=3.0.10" +requests = ">=2.9.1" +requests-oauthlib = ">=0.6.1" + +[package.extras] +all = ["cryptography (>=2.1.1)", "python3-saml (>=1.5.0)"] +allpy3 = ["cryptography (>=2.1.1)", "python3-saml (>=1.5.0)"] +azuread = ["cryptography (>=2.1.1)"] +saml = ["python3-saml (>=1.5.0)"] + [[package]] name = "sqlparse" version = "0.4.4" @@ -3623,4 +3664,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "~3.11" -content-hash = "27abbf1873f2acdd06ae43b014c1e1410992dbddd0bc6a07cfef87e6cd801d9f" +content-hash = "b694852d4c48536ea9edb0685a1bbdc8975e5b34edf34d44e54a6c40d0b26bc2" diff --git a/pyproject.toml b/pyproject.toml index 8a7ebfe5..0cc3b91e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -143,6 +143,7 @@ django-anymail = "10.1" dj-database-url = "^2.1.0" django-oauth-toolkit = "2.3.0" whitenoise = "^6.6.0" +social-auth-app-django = "^5.4.0" [tool.poetry.dev-dependencies] factory-boy = "3.3.0"