passport: Laravel 7.5.2 (Passport Api) + Vuejs Error : Undefined index: aud , \vendor\laravel\passport\src\Guards\TokenGuard.php
- Passport Version: 9.0
- Laravel Version: 7.5.2
- PHP Version: 7.4.0
- Database Driver & Version:
- Database client version: libmysql - mysqlnd 7.4.0
Description:
I am using Laravel 7.5.2 with Vuejs. I am using passport for api authentication. I am getting the following error when sending ajax request to api
{
"message": "Undefined index: aud",
"exception": "ErrorException",
"file": "E:\\laravel\\vendor\\laravel\\passport\\src\\Guards\\TokenGuard.php",
"line": 140,
"trace": [
{
...
}
]
Steps To Reproduce:
I have followed passport installation instruction on laravel website.
- Has run composer require laravel/passport, php artisan migrate and php artisan passport:install
- Has added HasApiTokens in user model
- Has added Passport::routes() in AuthServiceProvider
- Has added \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class in App\Http\Kernel web middlewareGroups
- Has changed Api driver to passport in config/auth.php
The cookie named “laravel_token” is getting generated and sent with ajax request as I can see in developer tool.
In my controller I have included api middleware as
public function __construct(){
$this->middleware('auth:api');
}
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 26 (15 by maintainers)
Released v9.0.1 which should fix this.
In my instance I’m using React.
laravel new test --authcd testcomposer require laravel/passportphp artisan migratephp artisan passport:installHasApiTokenstoUsermodelapiguard topassportinconfig/auth.phpPassport::routes()toAuthServiceProvider\Laravel\Passport\Http\Middleware\CreateFreshApiToken::classtowebmiddleware group inapp/Http/Kernel.phpphp artisan ui react --authhome.blade.phpadd<div id="example"></div>resources/js/components/Example.jswith the following code:npm install && npm run devThanks to everyone who reported this!
Thanks everyone, the fix works nicely 👍
I suspect it might be due to the removal of old
php-jwtversions in this merged PR? #1236Reverting to 8.x branch resolved the issue for me.
composer require laravel/passport:^8.0I think I might have found the issue.
Looks like
/vendor/laravel/passport/src/ApiTokenCookieFactory.php:77sets the indexsubinto the JWT tokenBut when decoding the cookie and trying to find the corresponding user
\Laravel\Passport\Guards\TokenGuard::$clientstries to use the indexaudto find the user.However, the indexes have been like that for a LONG time now, so I’m not sure why this is suddenly a problem?