3
votes

I am using Laravel 7.5.2 with Vuejs. I am using passport for api authentication. 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');
}

Api/Ajax Response

{
"message": "Undefined index: aud",
"exception": "ErrorException",
"file": "E:\\laravel\\vendor\\laravel\\passport\\src\\Guards\\TokenGuard.php",
"line": 140,
"trace": [
    {
...
}
]

I have also tried: composer dump-autoload

My Setup

  • Laravel: 7.5.2
  • Passport: 9.0
  • PHP : 7.4.0
  • Vuejs: 2.5.17

The issue is not only related to vuejs. It's related to ajax requests from simple javascript or could be from any framework.

2

2 Answers

2
votes

There was some problem in laravel/passport version 9.0. Upgrading to version 9.0.1 fixed the issue.

composer update laravel/passport:9.0.1

The details of the issue can be found here: Issue Detail on Github

Thanks to those who fixed the issue.

0
votes

Did you run php artisan passport:install?

It's needed to install keys in your storage directory.