1

All of configuration is right, but does not work.

My controller code is:

 $appUser = User::create([
                'name' => $user->name,
                'email' => $user->email,
                'password' => Hash::make(Str::random(8)),
            ]);

return $passportToken = $appUser->createToken('Token Name')->accessToken;

and response code from this URL (http://localhost:8000/api/authorize/github/callback?code=6ba82d59f00fdb1ad5c9) is:

{
  "name": "Token Name",
  "abilities": [
    "*"
  ],
  "tokenable_id": 1,
  "tokenable_type": "App\\Models\\User",
  "updated_at": "2021-09-19T05:10:00.000000Z",
  "created_at": "2021-09-19T05:10:00.000000Z",
  "id": 3
}
Geoffrey
  • 5,407
  • 10
  • 43
  • 78
Eahiya
  • 931
  • 1
  • 6
  • 12

2 Answers2

2

By Default User Model use HasApiToken provided by Laravel\Sanctum\HasApiTokens trait, please check User Model and if it point to Sanctum update it to use Laravel\Passport\HasApiTokens;

0

Laravel Passport uses its own database migration directory, so you should migrate your database after installing the Laravel Passport package. The Passport migrations will create the tables your application needs to store clients and access tokens:

php artisan migrate

If you have any problems, tell me.

Thân LƯƠNG Đình
  • 3,082
  • 2
  • 11
  • 21