So I am trying to configure Sanctum so that I would have CSRF protection for my API routes so that only my SPA’s frontend would be able to make requests to it.
After following the documentation and doing the instructions in in this part of the documentation. I still don’t thing that I have the CSRF protection properly set up.
I know this since I was able to make a request to routes under the auth:sanctum
middleware such as the following route.
use IlluminateHttpRequest;
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
I am able to make a request using Post Man to my login
route without the XSRF-Token
and it is returning a response which concerns me as I expect to encounter a CSRF Token Mismatch
exception or anything similar to that but I am receiving no such errors.
Am I misunderstanding something or just haven’t configured Sanctum properly?
2
Answers
Turns out I had my sanctum misconfigured and had to reconfigure it and place the authorization routes to web.php.
Use it in your
appHttp|Kernal.php
file,I hope this will help.