Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CSRF exempt authentication to the batch_completion api #24

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions completion/api/authentication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
Authentication classes for the API.
"""
from __future__ import absolute_import, unicode_literals

from rest_framework.authentication import SessionAuthentication


class CsrfExemptSessionAuthentication(SessionAuthentication):

def enforce_csrf(self, request):
return # To not perform the csrf check previously happening
3 changes: 3 additions & 0 deletions completion/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.utils.translation import ugettext as _
from django.db import DatabaseError

from rest_framework.authentication import BasicAuthentication
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import permissions
Expand All @@ -26,13 +27,15 @@

from completion import waffle
from completion.api.permissions import IsStaffOrOwner, IsUserInUrl
from completion.api.authentication import CsrfExemptSessionAuthentication
from completion.models import BlockCompletion


class CompletionBatchView(APIView):
"""
Handles API requests to submit batch completions.
"""
authentication_classes = (CsrfExemptSessionAuthentication, BasicAuthentication)
permission_classes = (permissions.IsAuthenticated, IsStaffOrOwner,)
REQUIRED_KEYS = ['username', 'course_key', 'blocks']

Expand Down