yunojuno / django-request-token

Django app that uses JWT to manage one-time and expiring tokens to protected URLs. Not related to DRF.
MIT License
47 stars 23 forks source link

JSON array payload #50

Closed asiffer closed 3 years ago

asiffer commented 3 years ago

[Middleware code, middleware.py] I had an error while posting an array to an endpoint (see the comment). The code expects a dictionary while [I guess] it is ok to post a raw array (like a batch of records). Maybe the type of json.loads(request.body) can be checked, otherwise the code can be wrapped in a try... except.... Maybe the erros can also occur at the line token = request.GET.get(JWT_QUERYSTRING_ARG)

if request.method == "GET" or request.method == "POST":
    token = request.GET.get(JWT_QUERYSTRING_ARG)
    if not token and request.method == "POST":
        if request.META.get("CONTENT_TYPE") == "application/json":
            # error: AttributeError: 'list' object has no attribute 'get'
            token = json.loads(request.body).get(JWT_QUERYSTRING_ARG)
        if not token:
            token = request.POST.get(JWT_QUERYSTRING_ARG)
else:
    token = None
hugorodgerbrown commented 3 years ago

Good spot - I'll patch this in due course.

hugorodgerbrown commented 3 years ago

Published as v0.14.1