I have a React frontend running at frontend.example.com
and a Django backend with DRF running at backend.example.com
. I am using Django Session Authentication and I want to properly implement CSRF protection.
Taking the React login page frontend.example.com/login
as an example. It's the first time for a user to visit the page. There is a form with a user and password and on submit a new POST request is created to the Django backend. To the best of my knowledge, the CSRF token cookie should already be included in this request, right?
How to obtain that CSRF token from the Django backend? I am thinking of doing a GET request to the Django backend on loading the login-page to obtain that CSRF token cookie. Is that the way to do it or is there any other best practice?