ansible / django-ansible-base

Apache License 2.0
12 stars 43 forks source link

Handle unsupported media type in django-oauth-toolkit #537

Closed cutwater closed 1 month ago

cutwater commented 1 month ago

When ansible_base.oauth2_provider is used, any POST request that contains content type not supported by the rest framework will end up with HTTP 415 Unsupported Media Type.

This happens because in the oauth2_provider.contrib.rest_framework.OAuth2Authentication authentication class oauth2_provider library unconditionally makes an attempt to access requsest.POST. When DRF fails to parse incoming request body, an exception is raised, which prevents further request handling.

Normally OAuth2Authentication will only work with access token passed in request Authorization header. This patch handles this situation and prevents request processing failure when request body contains data that cannot be parsed by DRF.

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud