-
-
Notifications
You must be signed in to change notification settings - Fork 787
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
Error uploading a raw file with the DRF #1406
Comments
I'm confused. Shouldn't only OAuth2-related stuff be hitting this endpoint, not arbitrary binary streams? |
@n2ygk actually this endpoint |
@nnseva it would help if you were to submit a PR to address this issue, starting with a failing test case. See https://django-oauth-toolkit.readthedocs.io/en/latest/contributing.html I still don't understand why it's looking for a token in the POST body if there's an |
Hi @n2ygk, I've found some extra time to investigate the issue. Actually, this is not an issue of the django-oauth-toolkit. The problem is that the DRF has stronger rules to receive the POST body, requiring explicit parsers for allowed Such a behaviour of the DRF is not clean enough, because it changes native Django request behaviour which silently returns empty Now I've found a proper solution and will resolve the issue in my code without a patch above. Sorry for disturb. |
Closing the issue |
Describe the bug
When using the DRF and creating an action view to upload a raw file in a POST body, the OAuth2 authenticator messes up this request raising either
rest_framework.exceptions.UnsupportedMediaType
, ordjango.core.exceptions.TooManyFieldsSent
.It happens because of the unconditional call of the
request.POST.items()
in theOAuthLibCore.extract_body()
method.To Reproduce
Create some raw upload URL using the DRF. My code was approximately:
Register this view in the DRF as usual
Setup the OAuth2 DRF authorization provided by the toolkit:
Start the server.
Authorize yourself somehow (using OAuth2, f.e.)
Try to upload some binary file:
The result is failed, with a response code=415 like
Try to upload a big binary file ignoring a
Content Type
header:curl http://127.0.0.1:8000/api/base_maps/some_id/upload/ --data-binary @some-file-for-upload.bin -H "Authorization: ...."
The result is failed, with a response 400 Bad Request (the
django.core.exceptions.TooManyFieldsSent
is reported in the console).Expected behavior
Success processing and response as minimum in the first case.
Version
django-oauth-toolkit==2.3.0
Additional context
The change like the following fixes the issue:
The text was updated successfully, but these errors were encountered: