Django token authentication without rest framework

Question:

I am required to make an API endpoint that receives XML in post request body. The XML format is given by a third party and can not be changed. I can’t use the rest framework because the format of the XML is not in the form which rest framework expects. I decided to use the traditional Django requests with xmltodict library for parsing the XML. My code will be something like this:

In views.py:

def newOrderStatus(request):
    if request.method == 'POST':
        obj = readXML(request.body)
        obj.save() 

Now what I want is to authenticate the request using a bearer token. Is there a way to do this or do I need to write my own middleware?

Asked By: Amr Barghouthi

||

Answers:

you can use @permission_classes decorator :

from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated

@api_view(['POST'])
@permission_classes([IsAuthenticated])
def newOrderStatus(request):
    obj = readXML(request.body)
    obj.save() 
Answered By: shrestha rohit
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.