Error configuring Passport in Laravel

Asked

Viewed 216 times

0

I have an API in Laravel and in it, I need to authenticate the access requests. So, I used Passport Laravel, only according to the return of the API, there is some definition that I did not inform in my code.

On my route, I inform the middleware guy:

Route::get('/members', 'PessoaController@index')->middleware('auth:api');

In config/app.php I informed the class

 Laravel\Passport\PassportServiceProvider::class,
    Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,

But when I make any request on my API, I get the following feedback:

(1/1) Fatalthrowableerror Type error: Argument 1 passed to Laravel Passport Http Middleware Createfreshapitoken::__Construct() must be an instance of Laravel Passport Apitokencookiefactory, instance of Illuminate Foundation Application Given, called in /home/secbase.com.br/vendor/Laravel/framework/src/Illuminate/Foundation/Providerrepository.php on line 208

2 answers

0

You injected the trait Laravel\Passport\HasApiTokens in your class User?

use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasApiTokens, Notifiable;
}

Registered the Passport routes on AuthServiceProvider ?

public function boot()
{
  $this->registerPolicies();

  Passport::routes();
}

https://laravel.com/docs/5.6/passport

  • Yes, I applied those definitions.

0

Not missing the Construct?

public function __construct()
{
    $this->middleware('guest', ['except' => 'getLogout']);
}
  • It has the constructor, I just forgot to expose here in the code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.