Skip to content

JSONOAuthLibCore breaks multipart form-data request for django-rest-framework #296

@sacgup

Description

@sacgup

I used JSONOAuthLibCore to accept JSON data for getting tokens.
But after using it gives error for multipart form-data request calls to my api's which are made using django-rest-framework. I need to use multipart-form data to upload files only and json for all other requests.

I used below class for authentication in settings.py

'DEFAULT_AUTHENTICATION_CLASSES': (
    'oauth2_provider.ext.rest_framework.OAuth2Authentication',
),

Error given is "You cannot access body after reading from request's data stream".

On investigation i found django doesn't support to read from request body twice. Once it is read in JSONOAuthLibCore so when django reads data again in "django/http/request.py" it gives error at that time.

I used JSONOAuthLibCore so that my all api call to my view and oauth2 to get token are similar and accepts only json.

1.) Why oauth2 need to read body data only to authenticate request ? It should only read Authorization header and check the token to validate the user. It should read body data only when granting tokens.

2.) Any workaround for this problem ?

I can make my oauth2 call to send "x-www-form-urlencoded" data from client apps and json for rest of my views but i really don't want to do that.

PS: I am new to django-rest-framework, oauth2 and token authentication. So if i am missing something obvious please bear with me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions