Commit a1ba77d6 by Clinton Blackburn

Diabled CSRF protection for Credit Course API endpoints

CSRF protection needs to be disabled so that requests made using OAuth and other non-session-based authentication mechanisms can be properly processed. If session authentication is used, DRF will enforce CSRF protection.

XCOM-524
parent 3c8dbe77
...@@ -12,6 +12,7 @@ from django.http import ( ...@@ -12,6 +12,7 @@ from django.http import (
HttpResponseForbidden, HttpResponseForbidden,
Http404 Http404
) )
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST, require_GET from django.views.decorators.http import require_POST, require_GET
from opaque_keys import InvalidKeyError from opaque_keys import InvalidKeyError
...@@ -379,6 +380,9 @@ class CreditCourseViewSet(mixins.CreateModelMixin, mixins.UpdateModelMixin, view ...@@ -379,6 +380,9 @@ class CreditCourseViewSet(mixins.CreateModelMixin, mixins.UpdateModelMixin, view
authentication_classes = (authentication.OAuth2Authentication, authentication.SessionAuthentication,) authentication_classes = (authentication.OAuth2Authentication, authentication.SessionAuthentication,)
permission_classes = (permissions.IsAuthenticated, permissions.IsAdminUser) permission_classes = (permissions.IsAuthenticated, permissions.IsAdminUser)
# This CSRF exemption only applies when authenticating without SessionAuthentication.
# SessionAuthentication will enforce CSRF protection.
@method_decorator(csrf_exempt)
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
# Convert the course ID/key from a string to an actual CourseKey object. # Convert the course ID/key from a string to an actual CourseKey object.
course_id = kwargs.get(self.lookup_field, None) course_id = kwargs.get(self.lookup_field, None)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment