Closed payalord closed 4 months ago
Hey there, thanks for reporting this issue.
We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?
Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.
laravel new bug-report --github="--public"
Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.
Thanks!
Hey there,
Unfortunately we don't support this version anymore. Please check out our support policy on which versions we are currently supporting. Can you please try to upgrade to the latest version and see if your problem persists? If so, please open up a new issue and we'll help you out.
Thanks!
Hi, I wanted to say sorry. I checked again and this was completely my mistake. First time, when I reported this issue here, I was using the token's hash directly from DB as token, instead of token returned by $user->createToken('API_TOKEN')->plainTextToken;
I missed the point that in DB sanctum doesn't store the plain token, but stores it's hash instead.
So I think there is no problem with Sanctum. And thanks for your support guys anyway!
Sanctum Version
v3.3.3
Laravel Version
v10.48.12
PHP Version
8.1.2-1ubuntu2.17
Database Driver & Version
MySQL 8.0.36-0ubuntu0.22.04.1
Description
I was following this page installation instructions: https://laravel.com/docs/10.x/sanctum
And I have problem even if bearer token is present sanctum doesn't authenticate the user by it and i'm getting 401. With message:
Steps To Reproduce
Steps that I did:
composer require laravel/sanctum
- which installed sanctum v3.3.3php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
php artisan migrate
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class
to my api route middleware.routes/api.php
to test it:config/auth.php
anapi
guard:I set in
config/sanctum.php
:Then I have created 1 token with sanctum createToken function
$token = $user->createToken('API_TOKEN')->plainTextToken;
. So the token exists in the tablepersonal_access_token
. My user model have traitHasApiToken
by default from Laravel, i didn't touch it.Then I made a request from postman to
api/data
endpoint and got 401 unauthorized error. In that request before I did it, I set Authorization Bearer to my created token and I set Accept application/json. I also tried to set Origin to localhost and to localhost:3000 (<-- where the site is served). In all cases I've got:If I will set in
config/sanctum.php
guard to['web','api']
i will get XDebug inifinite loop error. While in sanctum version 3.0.2 setting guard to['web','api']
on laravel 9 in another project didn't had any inifinite loop errors and sanctum was working fine there. But with laravel 10 I can't downgrade to v3.0.2 since support of laravel 10 has been added in v3.2.0