Sanctum always return Unauthenticated while using API auth #48930
Unanswered
pierremedard
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I think it should be |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone !
I've been trying to use Sanctum to authenticate my client for a Laravel API but it seems like i'm always unable to authenticate myself using postman. I've browsed the web for a while in search of an answer but it seems like i can't find a fix.
On my backend side, i've followed the docs, my login method looks like this:
In the api.php routing file:
Route::post('/logout', 'logout')->middleware('auth:sanctum');
The kernel:
For the config, in auth.php i have:
In sanctum.php at the end of the file:
'guard' => 'api'
And for the .htaccess:
According to my research, this should be enough for sanctum to be correctly configured on the back side. Now for Postman, I add the Accept: application/json, the Referer: http://localhost:8000, and in the Authorization tab, i select Bearer with the value 10|mO1ISY4Yy9ionnulfndxTIDslcH4naVP8R5Yvuj5daf08f51 (a token that my register API returns). And it doesn't seem to work. Also, when i remove the middleware for my logout route and try to return the header values, the Authorization token is not there, it seems like it has been removed at some point, even $request->bearerToken(); returns null. I tried using the Authorization tab of Postman but also setting it directly in the Header, can't get it to work.
Laravel: 10.x
Sanctum: ^3.3
PHP: 8.2
Apache2
Did i miss something during my configuration or in Postman ? Has anyone ever experienced that ?
Thanks !
Beta Was this translation helpful? Give feedback.
All reactions