-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
Currently, when LoginRequiredMiddleware is enabled, Django Rest Framework can no longer use tokens to authenticate, and will always return a 302 status without a chance to login. For the project I'm integrating into, I need both login and tokens to be available.
This is due to the token-based login occurring after all middleware has gone through the process_request() phase, but before the process_response() phase. LoginRequiredMiddleware expects authentication to have already happened thanks to AuthenticationMiddleware, and thus DRF never gets a chance to look at the token before we get redirected.
- Set up a project with
DjangoRestFramework - Set up an endpoint to protect with Django's
login_requireddecorator - Set up the Token system for DRF
- In a browser, without logging in, try to access the endpoint. Access is denied, according to configuration
- Using Postman or any other means to call the endpoint including the
AUTHORIZATIONheader, with valueToken xwhere x is the appropriate token value. The endpoint is accessible thanks to authentication via token - Remove the
login_requireddecorator from the endpoint - Set up
LoginRequiredMiddlewareto redirect all or some paths, including the above endpoint - In a browser, without logging in, try to access the endpoint. A redirect occurs, which is expected
- Using Postman or any other means to call the endpoint including the
AUTHORIZATIONheader, with valueToken xwhere x is the appropriate token value. A redirect occurs, even though a valid token was provided
A PR was submitted to fix this behaviour: #79
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels