From 2de6ca1279a7c359174effc929802bda03d7f8a4 Mon Sep 17 00:00:00 2001 From: Axel Lorreyne Date: Wed, 13 Mar 2024 11:55:46 +0100 Subject: [PATCH 01/13] add msal functionality --- backend/pigeonhole/settings.py | 33 +++++++++++++++++++++++---------- backend/pigeonhole/urls.py | 3 +++ backend/requirements.txt | 5 +++-- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/backend/pigeonhole/settings.py b/backend/pigeonhole/settings.py index f06af906..a120b5e1 100644 --- a/backend/pigeonhole/settings.py +++ b/backend/pigeonhole/settings.py @@ -35,22 +35,34 @@ # Application definition INSTALLED_APPS = [ + "corsheaders", + 'backend.pigeonhole.apps.courses', + 'backend.pigeonhole.apps.groups', + 'backend.pigeonhole.apps.projects', + 'backend.pigeonhole.apps.submissions', + 'backend.pigeonhole.apps.users', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', - 'django.contrib.sessions', 'django.contrib.messages', + 'django.contrib.sessions', + 'django.contrib.sites', 'django.contrib.staticfiles', - 'rest_framework', - "corsheaders", - 'backend.pigeonhole.apps.users', - 'backend.pigeonhole.apps.courses', - 'backend.pigeonhole.apps.projects', - 'backend.pigeonhole.apps.submissions', - 'backend.pigeonhole.apps.groups', 'drf_yasg', + 'microsoft_auth', + 'rest_framework', +] + +AUTHENTICATION_BACKENDS = [ + 'django.contrib.auth.backends.ModelBackend' + 'microsoft_auth.backends.MicrosoftAuthenticationBackend', ] +MICROSOFT_AUTH_CLIENT_ID = os.environ.get("OAUTH_CLIENT_ID") +MICROSOFT_AUTH_CLIENT_SECRET = os.environ.get("OAUTH_CLIENT_SECRET") +MICROSOFT_AUTH_TENANT_ID = os.environ.get("OAUTH_TENANT_ID") +MICROSOFT_AUTH_LOGIN_TYPE = 'ma' + MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -88,10 +100,11 @@ 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'microsoft_auth.context_processors.microsoft', ], }, }, diff --git a/backend/pigeonhole/urls.py b/backend/pigeonhole/urls.py index 2a5503e2..ada5bd51 100644 --- a/backend/pigeonhole/urls.py +++ b/backend/pigeonhole/urls.py @@ -4,6 +4,7 @@ from django.urls import include, path from drf_yasg import openapi from drf_yasg.views import get_schema_view +from microsoft_auth.views import AuthenticateCallbackView from rest_framework import routers, permissions from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView @@ -43,6 +44,8 @@ path("admin/", admin.site.urls), path('auth/login/', TokenObtainPairView.as_view(), name='token_obtain_pair'), path('auth/refresh/', TokenRefreshView.as_view(), name='token_refresh'), + path('auth/callback/', AuthenticateCallbackView.as_view(), name='microsoft_auth_callback'), + path('microsoft/', include('microsoft_auth.urls', namespace='microsoft')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += router.urls diff --git a/backend/requirements.txt b/backend/requirements.txt index 22eb5e0d..ad7ccfa2 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,11 +1,12 @@ -coverage~=6.3 Django~=5.0.2 +coverage~=6.3 django-cors-headers~=3.14.0 djangorestframework-simplejwt~=5.2.2 djangorestframework~=3.14.0 +drf-yasg==1.21.7 flake8==7.0.0 psycopg2-binary~=2.9.5 pytz~=2022.7.1 pyyaml==6.0.1 uritemplate==4.1.1 -drf-yasg==1.21.7 +django_microsoft_auth==3.0.1 From 714b4eb9db49432a01139cff1ba2e58a09bc5f58 Mon Sep 17 00:00:00 2001 From: Axel Lorreyne Date: Wed, 13 Mar 2024 21:38:51 +0100 Subject: [PATCH 02/13] fix auth backends --- backend/pigeonhole/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/pigeonhole/settings.py b/backend/pigeonhole/settings.py index a120b5e1..ca8151e3 100644 --- a/backend/pigeonhole/settings.py +++ b/backend/pigeonhole/settings.py @@ -54,7 +54,7 @@ ] AUTHENTICATION_BACKENDS = [ - 'django.contrib.auth.backends.ModelBackend' + 'django.contrib.auth.backends.ModelBackend', 'microsoft_auth.backends.MicrosoftAuthenticationBackend', ] From dae4804feb0eb549205998c8a3ae53ba45cbec6b Mon Sep 17 00:00:00 2001 From: Axel Lorreyne Date: Wed, 13 Mar 2024 21:40:10 +0100 Subject: [PATCH 03/13] add django extensions --- backend/pigeonhole/settings.py | 1 + backend/requirements.txt | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/pigeonhole/settings.py b/backend/pigeonhole/settings.py index ca8151e3..a0b5daa3 100644 --- a/backend/pigeonhole/settings.py +++ b/backend/pigeonhole/settings.py @@ -48,6 +48,7 @@ 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.staticfiles', + 'django_extensions', 'drf_yasg', 'microsoft_auth', 'rest_framework', diff --git a/backend/requirements.txt b/backend/requirements.txt index ad7ccfa2..bd9356d8 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,6 +1,8 @@ Django~=5.0.2 coverage~=6.3 django-cors-headers~=3.14.0 +django-extensions==3.2.3 +django_microsoft_auth==3.0.1 djangorestframework-simplejwt~=5.2.2 djangorestframework~=3.14.0 drf-yasg==1.21.7 @@ -9,4 +11,3 @@ psycopg2-binary~=2.9.5 pytz~=2022.7.1 pyyaml==6.0.1 uritemplate==4.1.1 -django_microsoft_auth==3.0.1 From 783ff46a4a8a0a3123e3442d0a6172a3bf8cb0fe Mon Sep 17 00:00:00 2001 From: robinpdev Date: Wed, 13 Mar 2024 23:09:38 +0100 Subject: [PATCH 04/13] epic redirect fix --- backend/pigeonhole/settings.py | 2 ++ backend/pigeonhole/urls.py | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/backend/pigeonhole/settings.py b/backend/pigeonhole/settings.py index a0b5daa3..c56d3b1f 100644 --- a/backend/pigeonhole/settings.py +++ b/backend/pigeonhole/settings.py @@ -185,3 +185,5 @@ } } } + +REDIRECT_URI = "https://localhost:8000/auth/callback/" diff --git a/backend/pigeonhole/urls.py b/backend/pigeonhole/urls.py index ada5bd51..5a3fb0fe 100644 --- a/backend/pigeonhole/urls.py +++ b/backend/pigeonhole/urls.py @@ -4,9 +4,10 @@ from django.urls import include, path from drf_yasg import openapi from drf_yasg.views import get_schema_view -from microsoft_auth.views import AuthenticateCallbackView +from microsoft_auth.views import AuthenticateCallbackView, AuthenticateCallbackRedirect, to_ms_redirect from rest_framework import routers, permissions from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView +from rest_framework.urls import urlpatterns as drf_urlpatterns from backend.pigeonhole.apps.courses.views import CourseViewSet from backend.pigeonhole.apps.groups.views import GroupViewSet @@ -34,6 +35,24 @@ router.register(r'courses/(?P[^/.]+)/projects', ProjectViewSet) router.register(r'courses/(?P[^/.]+)/projects/(?P[^/.]+)/groups', GroupViewSet) +owpats = [ + path( + "callback", + AuthenticateCallbackView.as_view(), + name="auth-callback", + ), + path( + "from-auth-redirect", + AuthenticateCallbackRedirect.as_view(), + name="from-auth-redirect", + ), + path( + "to-auth-redirect", + to_ms_redirect, + name="to-auth-redirect", + ), +] + # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API. urlpatterns = [ @@ -44,7 +63,7 @@ path("admin/", admin.site.urls), path('auth/login/', TokenObtainPairView.as_view(), name='token_obtain_pair'), path('auth/refresh/', TokenRefreshView.as_view(), name='token_refresh'), - path('auth/callback/', AuthenticateCallbackView.as_view(), name='microsoft_auth_callback'), + path('auth/', include((owpats, 'microsoft_auth')), name=None), path('microsoft/', include('microsoft_auth.urls', namespace='microsoft')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) From 67620ec28aa3b7b3e9e419dc726681a5e29f6e19 Mon Sep 17 00:00:00 2001 From: robinpdev Date: Wed, 13 Mar 2024 23:11:38 +0100 Subject: [PATCH 05/13] better variable naming --- backend/pigeonhole/urls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/pigeonhole/urls.py b/backend/pigeonhole/urls.py index 5a3fb0fe..f65f3be3 100644 --- a/backend/pigeonhole/urls.py +++ b/backend/pigeonhole/urls.py @@ -35,7 +35,7 @@ router.register(r'courses/(?P[^/.]+)/projects', ProjectViewSet) router.register(r'courses/(?P[^/.]+)/projects/(?P[^/.]+)/groups', GroupViewSet) -owpats = [ +overwritten_auth_patterns = [ path( "callback", AuthenticateCallbackView.as_view(), @@ -63,7 +63,7 @@ path("admin/", admin.site.urls), path('auth/login/', TokenObtainPairView.as_view(), name='token_obtain_pair'), path('auth/refresh/', TokenRefreshView.as_view(), name='token_refresh'), - path('auth/', include((owpats, 'microsoft_auth')), name=None), + path('auth/', include((overwritten_auth_patterns, 'microsoft_auth')), name=None), path('microsoft/', include('microsoft_auth.urls', namespace='microsoft')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) From 628e94381c2be3f16ac138a667254b45cc8ae241 Mon Sep 17 00:00:00 2001 From: robinpdev Date: Wed, 13 Mar 2024 23:48:33 +0100 Subject: [PATCH 06/13] django version change --- backend/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index bd9356d8..6409aa3b 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -1,4 +1,4 @@ -Django~=5.0.2 +Django~=4.2.11 coverage~=6.3 django-cors-headers~=3.14.0 django-extensions==3.2.3 From a48db9208c537a6cc6570becdab322ea135475ef Mon Sep 17 00:00:00 2001 From: Axel Lorreyne Date: Thu, 14 Mar 2024 04:18:40 +0100 Subject: [PATCH 07/13] fix push correct domain to django sites table --- Dockerfile | 3 +++ backend/entrypoint.sh | 2 ++ backend/pigeonhole/settings.py | 2 +- scripts/push_site.py | 10 ++++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 scripts/push_site.py diff --git a/Dockerfile b/Dockerfile index 8443debf..172fc949 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,9 @@ RUN chmod +x /usr/src/app/entrypoint.sh # copy manage.py COPY manage.py . +# copy scripts +COPY scripts ./scripts + # copy project COPY backend ./backend diff --git a/backend/entrypoint.sh b/backend/entrypoint.sh index ce1cafee..8784c67c 100755 --- a/backend/entrypoint.sh +++ b/backend/entrypoint.sh @@ -15,6 +15,8 @@ fi #python manage.py makemigrations python manage.py migrate +python manage.py runscript push_site + python manage.py createsuperuser --noinput --email $DJANGO_SUPERUSER_EMAIL exec "$@" \ No newline at end of file diff --git a/backend/pigeonhole/settings.py b/backend/pigeonhole/settings.py index c56d3b1f..46ead0ad 100644 --- a/backend/pigeonhole/settings.py +++ b/backend/pigeonhole/settings.py @@ -26,7 +26,7 @@ DEBUG = int(os.environ.get("DEBUG", default=0)) -ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", default="127.0.0.1").split(" ") +ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", default="127.0.0.1 example.com").split(" ") if not DEBUG: USE_X_FORWARDED_HOST = True diff --git a/scripts/push_site.py b/scripts/push_site.py new file mode 100644 index 00000000..b4aaaa76 --- /dev/null +++ b/scripts/push_site.py @@ -0,0 +1,10 @@ +import os + +from django.contrib.sites.models import Site + + +def run(): + debug = int(os.environ.get("DEBUG", default=0)) + domain = 'localhost:8000' if debug else 'sel2-1.ugent.be' + Site.objects.filter(pk=1).delete() + Site.objects.create(pk=1, domain=domain, name='localhost') From 42b9bedd215542c69498558a83766b282d202536 Mon Sep 17 00:00:00 2001 From: robinpdev Date: Thu, 14 Mar 2024 10:40:36 +0100 Subject: [PATCH 08/13] production readying --- Dockerfile.prod | 3 +++ backend/entrypoint.prod.sh | 5 +++++ backend/pigeonhole/settings.py | 2 +- scripts/push_site.py | 3 ++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Dockerfile.prod b/Dockerfile.prod index f2ec66bb..bb6452a5 100644 --- a/Dockerfile.prod +++ b/Dockerfile.prod @@ -57,6 +57,9 @@ COPY ./backend/entrypoint.prod.sh . RUN sed -i 's/\r$//g' $APP_HOME/entrypoint.prod.sh RUN chmod +x $APP_HOME/entrypoint.prod.sh +# copy scripts +COPY scripts ./scripts + # copy manage.py COPY manage.py . diff --git a/backend/entrypoint.prod.sh b/backend/entrypoint.prod.sh index 8e82918e..16a6e2c8 100644 --- a/backend/entrypoint.prod.sh +++ b/backend/entrypoint.prod.sh @@ -11,6 +11,11 @@ then echo "PostgreSQL started" fi +python manage.py migrate + +python manage.py runscript push_site + python manage.py collectstatic --noinput + exec "$@" \ No newline at end of file diff --git a/backend/pigeonhole/settings.py b/backend/pigeonhole/settings.py index 46ead0ad..f0f14084 100644 --- a/backend/pigeonhole/settings.py +++ b/backend/pigeonhole/settings.py @@ -186,4 +186,4 @@ } } -REDIRECT_URI = "https://localhost:8000/auth/callback/" +SITE_URL = "http://localhost:8000" diff --git a/scripts/push_site.py b/scripts/push_site.py index b4aaaa76..53f78932 100644 --- a/scripts/push_site.py +++ b/scripts/push_site.py @@ -6,5 +6,6 @@ def run(): debug = int(os.environ.get("DEBUG", default=0)) domain = 'localhost:8000' if debug else 'sel2-1.ugent.be' - Site.objects.filter(pk=1).delete() + print(domain) + Site.objects.all().delete() Site.objects.create(pk=1, domain=domain, name='localhost') From 90aff12650c81bcb063edb1c2a19c9349e2aee5f Mon Sep 17 00:00:00 2001 From: robinpdev Date: Thu, 14 Mar 2024 12:57:05 +0100 Subject: [PATCH 09/13] remove overwritten urls and fix callback template --- backend/pigeonhole/settings.py | 2 +- backend/pigeonhole/urls.py | 19 +------------------ .../templates/microsoft/auth_callback.html | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 19 deletions(-) create mode 100644 backend/templates/microsoft/auth_callback.html diff --git a/backend/pigeonhole/settings.py b/backend/pigeonhole/settings.py index f0f14084..31ef7368 100644 --- a/backend/pigeonhole/settings.py +++ b/backend/pigeonhole/settings.py @@ -97,7 +97,7 @@ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [BASE_DIR / 'templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ diff --git a/backend/pigeonhole/urls.py b/backend/pigeonhole/urls.py index f65f3be3..3212e774 100644 --- a/backend/pigeonhole/urls.py +++ b/backend/pigeonhole/urls.py @@ -35,23 +35,7 @@ router.register(r'courses/(?P[^/.]+)/projects', ProjectViewSet) router.register(r'courses/(?P[^/.]+)/projects/(?P[^/.]+)/groups', GroupViewSet) -overwritten_auth_patterns = [ - path( - "callback", - AuthenticateCallbackView.as_view(), - name="auth-callback", - ), - path( - "from-auth-redirect", - AuthenticateCallbackRedirect.as_view(), - name="from-auth-redirect", - ), - path( - "to-auth-redirect", - to_ms_redirect, - name="to-auth-redirect", - ), -] + # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API. @@ -63,7 +47,6 @@ path("admin/", admin.site.urls), path('auth/login/', TokenObtainPairView.as_view(), name='token_obtain_pair'), path('auth/refresh/', TokenRefreshView.as_view(), name='token_refresh'), - path('auth/', include((overwritten_auth_patterns, 'microsoft_auth')), name=None), path('microsoft/', include('microsoft_auth.urls', namespace='microsoft')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/backend/templates/microsoft/auth_callback.html b/backend/templates/microsoft/auth_callback.html new file mode 100644 index 00000000..fd9dfd68 --- /dev/null +++ b/backend/templates/microsoft/auth_callback.html @@ -0,0 +1,17 @@ +{% load i18n %} + + + +

{% trans "This window should automatically close BUT ITs in microsoft. If it does not, it should be save to close after a few seconds." %}

+
{{ message }}
+ + + \ No newline at end of file From fe9fc1c77b47b768c6bc28394c725628829b307a Mon Sep 17 00:00:00 2001 From: Axel Lorreyne Date: Thu, 14 Mar 2024 13:09:40 +0100 Subject: [PATCH 10/13] add course and role to user admin view --- backend/pigeonhole/apps/users/admin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/pigeonhole/apps/users/admin.py b/backend/pigeonhole/apps/users/admin.py index ec1d1884..711156d3 100644 --- a/backend/pigeonhole/apps/users/admin.py +++ b/backend/pigeonhole/apps/users/admin.py @@ -16,6 +16,8 @@ class UserAdmin(BaseUserAdmin): 'password', 'first_name', 'last_name', + 'course', + 'role', )}), ) From 684ec2e080e30456244a3981024c06edce14b24c Mon Sep 17 00:00:00 2001 From: Axel Lorreyne Date: Thu, 14 Mar 2024 13:10:58 +0100 Subject: [PATCH 11/13] cleanup --- backend/pigeonhole/urls.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/pigeonhole/urls.py b/backend/pigeonhole/urls.py index 3212e774..bc1c5ac0 100644 --- a/backend/pigeonhole/urls.py +++ b/backend/pigeonhole/urls.py @@ -4,10 +4,8 @@ from django.urls import include, path from drf_yasg import openapi from drf_yasg.views import get_schema_view -from microsoft_auth.views import AuthenticateCallbackView, AuthenticateCallbackRedirect, to_ms_redirect from rest_framework import routers, permissions from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView -from rest_framework.urls import urlpatterns as drf_urlpatterns from backend.pigeonhole.apps.courses.views import CourseViewSet from backend.pigeonhole.apps.groups.views import GroupViewSet From 1565a362dfabf5217b7892333177b57701de8928 Mon Sep 17 00:00:00 2001 From: robinpdev Date: Thu, 14 Mar 2024 13:25:41 +0100 Subject: [PATCH 12/13] add redirect route to frontend --- backend/pigeonhole/settings.py | 1 + backend/pigeonhole/urls.py | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/backend/pigeonhole/settings.py b/backend/pigeonhole/settings.py index 31ef7368..12b395d7 100644 --- a/backend/pigeonhole/settings.py +++ b/backend/pigeonhole/settings.py @@ -25,6 +25,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = int(os.environ.get("DEBUG", default=0)) +FRONTEND_URL = os.environ.get("FRONTEND_URL", default="http://localhost:3000") ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", default="127.0.0.1 example.com").split(" ") diff --git a/backend/pigeonhole/urls.py b/backend/pigeonhole/urls.py index 3212e774..c09c23f6 100644 --- a/backend/pigeonhole/urls.py +++ b/backend/pigeonhole/urls.py @@ -1,7 +1,8 @@ from django.conf import settings from django.conf.urls.static import static from django.contrib import admin -from django.urls import include, path +from django.urls import include, path as urlpath +from django.shortcuts import redirect from drf_yasg import openapi from drf_yasg.views import get_schema_view from microsoft_auth.views import AuthenticateCallbackView, AuthenticateCallbackRedirect, to_ms_redirect @@ -35,19 +36,23 @@ router.register(r'courses/(?P[^/.]+)/projects', ProjectViewSet) router.register(r'courses/(?P[^/.]+)/projects/(?P[^/.]+)/groups', GroupViewSet) - +def to_frontend(request, path): + return redirect(f"{settings.FRONTEND_URL}/{path}") # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API. urlpatterns = [ - path('', include(router.urls)), - path('api-auth/', include('rest_framework.urls', namespace='rest_framework')), - path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), - path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), - path("admin/", admin.site.urls), - path('auth/login/', TokenObtainPairView.as_view(), name='token_obtain_pair'), - path('auth/refresh/', TokenRefreshView.as_view(), name='token_refresh'), - path('microsoft/', include('microsoft_auth.urls', namespace='microsoft')), + urlpath('', include(router.urls)), + urlpath('api-auth/', include('rest_framework.urls', namespace='rest_framework')), + urlpath('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), + urlpath('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), + urlpath("admin/", admin.site.urls), + urlpath('auth/login/', TokenObtainPairView.as_view(), name='token_obtain_pair'), + urlpath('auth/refresh/', TokenRefreshView.as_view(), name='token_refresh'), + urlpath('microsoft/', include('microsoft_auth.urls', namespace='microsoft')), + urlpath('redirect/', to_frontend, name='redirect'), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + + urlpatterns += router.urls From 8708c4fea9ffde8fa55bb4fc69324f2f825ac9e0 Mon Sep 17 00:00:00 2001 From: robinpdev Date: Thu, 14 Mar 2024 13:45:11 +0100 Subject: [PATCH 13/13] proof of concept CAS login in dev environment --- frontend/src/app/components/CASButton.tsx | 1 + frontend/src/auth/auth-agent.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/components/CASButton.tsx b/frontend/src/app/components/CASButton.tsx index 6af7e5c7..079ae9e8 100644 --- a/frontend/src/app/components/CASButton.tsx +++ b/frontend/src/app/components/CASButton.tsx @@ -7,6 +7,7 @@ const CASButton = () => { const handleCASLogin = (): void => { // Implement CAS login logic here console.log('Login with CAS'); + window.location.href = "http://localhost:8000/microsoft/to-auth-redirect?next=/redirect/homepage" }; return ( diff --git a/frontend/src/auth/auth-agent.js b/frontend/src/auth/auth-agent.js index 279b33a2..a9c0a2e5 100644 --- a/frontend/src/auth/auth-agent.js +++ b/frontend/src/auth/auth-agent.js @@ -4,7 +4,7 @@ class AuthAgent { login(username, password) { return axios - .post("http://127.0.0.1:8000/auth/login/", { + .post("http://localhost:8000/auth/login/", { username, password })