You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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_required decorator
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 AUTHORIZATION header, with value Token x where x is the appropriate token value. The endpoint is accessible thanks to authentication via token
Remove the login_required decorator from the endpoint
Set up LoginRequiredMiddleware to 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 AUTHORIZATION header, with value Token x where x is the appropriate token value. A redirect occurs, even though a valid token was provided
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.
DjangoRestFramework
login_required
decoratorAUTHORIZATION
header, with valueToken x
where x is the appropriate token value. The endpoint is accessible thanks to authentication via tokenlogin_required
decorator from the endpointLoginRequiredMiddleware
to redirect all or some paths, including the above endpointAUTHORIZATION
header, with valueToken x
where x is the appropriate token value. A redirect occurs, even though a valid token was providedA PR was submitted to fix this behaviour: #79
The text was updated successfully, but these errors were encountered: