Skip to content

Commit

Permalink
Dit lost het probleem op dat we zogezegd de csrf token niet meegaven …
Browse files Browse the repository at this point in the history
…aan onze post requests
  • Loading branch information
ticoucke committed Mar 14, 2024
1 parent d244e99 commit 7fdf875
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.conf import settings
from django.shortcuts import redirect
from rest_framework.authentication import SessionAuthentication


class RedirectAnonymousUserMiddleware:
Expand Down Expand Up @@ -30,3 +31,10 @@ def __call__(self, request):
return redirect(settings.LOGIN_URL)

return self.get_response(request)


class CsrfExemptSessionAuthentication(SessionAuthentication):

def enforce_csrf(self, request):
return # To not perform the csrf check previously happening

7 changes: 7 additions & 0 deletions api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,10 @@

LOGIN_URL = "django_auth_adfs:login"
LOGIN_REDIRECT_URL = "/login_redirect"

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.BasicAuthentication',
'api.middleware.CsrfExemptSessionAuthentication'
]
}

0 comments on commit 7fdf875

Please sign in to comment.