Skip to content
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

Do not insert WebtestAuthentication to the head of DEFAULT_AUTHENTICATION_CLASSES. #128

Merged
merged 1 commit into from
Aug 21, 2023

Conversation

tell-k
Copy link
Contributor

@tell-k tell-k commented Aug 21, 2023

Hello. authors. Thanks for awsome tool.

I have found a problem using restframwork and django-webtest together.

The following code expects to return an HTTP 401 on an authentication error.

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',.
    ]
}

But django-webtest returns HTTP 403.

The reason for this is described in the restframework documentation.

HTTP 401 responses must always include a WWW-Authenticate header, that instructs the client how to authenticate. HTTP 403 responses do not include the WWW-Authenticate header.

The kind of response that will be used depends on the authentication scheme. Although multiple authentication schemes may be in use, only one scheme may be The first authentication class set on the view is used when determining > the type of response.
https://www.django-rest-framework.org/api-guide/authentication/#unauthorized-and-forbidden-response

In other words, restframework determines whether to return HTTP 401 or HTTP 403 depending on the head of the DEFAULT_AUTHENTICATION_CLASSES.

Since django-webtest adds WebtestAuthentication to the head of DEFAULT_AUTHENTICATION_CLASSES, it may return an HTTP status code that is not what the user expects.

To avoid breaking the user's expected results, i fix codes.
Please feel free to merge it.

Thanks.

@gawel gawel merged commit 0bfd420 into django-webtest:master Aug 21, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants