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

BrowsableAPI doesn't render for user with no permission with Django #2488

Closed
rvanlaar opened this issue Jan 29, 2015 · 4 comments
Closed

BrowsableAPI doesn't render for user with no permission with Django #2488

rvanlaar opened this issue Jan 29, 2015 · 4 comments

Comments

@rvanlaar
Copy link

What happens: The BrowsableAPI throws "'WSGIRequest' object has no attribute 'successful_authenticator'"
What I expect: The BrowsableAPI shows the list view without a post form.

The BrowsableAPI doesn't render for an authenticated user with no permissions on a viewset with: DangoModelPermissions.

The permissions of a user are checked twice, once with a request.method = GET and once with a request.method = POST. During the request.method = POST the permissions need to {app}.{add_object}, which the user doesn't have.

@rvanlaar
Copy link
Author

Also: when an unauthorized user without any permissions does a POST to a viewset which is protected with DjangoModelPermissions, the error: "'WSGIRequest' object has no attribute 'successful_authenticator'" is thrown.

What I expect: A 403 Forbidden response.

@tomchristie
Copy link
Member

I couldn't get this to replicate.
What I did was:

  • Set up a project as described in the quickstart.
  • Added permissions_classes = [DjangoModelPermissions] to the UserViewSet.
  • Created a regular user.
  • Logged in as that user and navigated to the /users/ endpoint.

Result - displayed the browsable API with a 403.

screen shot 2015-01-29 at 22 23 59

May be able to reopen and look at this further but would require some replicable instructions, or an example test with failing pull request.

This line:

"'WSGIRequest' object has no attribute 'successful_authenticator'"

Looks to me like it's the same as #2108

Perhaps you have a custom permission that's causing an attribute error or similar.

Worth double checking which auth and permission classes you have installed and try to narrow down any configuration issues there.

@tomchristie
Copy link
Member

One possibility would be to take this empty project: https://github.com/tomchristie/basic-rest-framework and see what steps you need to make against it in order to replicate - I'd then be able to follow the same steps.

@rvanlaar
Copy link
Author

Thank you.

I had an error in my AuthenticationClass.

The reason I have an AuthenticationClass is that the original AuthenticationClass in DRF does an explicit enforce_csrf. This breaks havoc with HTTPS where the referer header is not the same as the serving host for DRF.

See also this issue: adamchainz/django-cors-headers#55

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

No branches or pull requests

2 participants