Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel Passport cannot find a personal access client

ErrorPersonal access client not found

Short answer

createToken needs a personal access client, and the database you are connected to does not have one. Create it with php artisan passport:client --personal. If your app has several user providers, pass --provider so the client matches the model that calls createToken. Run it once on each environment.

  • Applies to Laravel 12, PHP 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Confirm you are looking at the right database, then see whether any client exists. The error means the oauth_clients table has no personal access client for this app.

    php artisan tinker
    >>> DB::table('oauth_clients')->get(['id','name','grant_types'])
  2. 2Match what you see, then jump to its fix

    1. 1The oauth_clients table is empty, or it has no row with the personal_access grant.No personal access client was ever created on this databaseFix
    2. 2A client exists, but the app has more than one provider in config/auth.php and createToken is called on the model of the other one.The client belongs to a different user provider than the model you callFix
    3. 3createToken is not defined on the model at all, and the model has no Passport trait.The user model does not use Passport's HasApiTokens traitFix

What does the error look like?

  • Personal access client not found
  • createToken fails for a user, and no token is returned

Cause 1 of 3

No personal access client was ever created on this database

1Check

Passport does not make this client during migration. It is made by a command. A new server, a fresh database or a restored dump that skipped the table all lack it.

php artisan tinker
>>> DB::table('oauth_clients')->count()

2Fix

Create the client with the Passport command. If you already ran passport:install, this step is not needed.

php artisan passport:client --personal

3Verify

Issue a token again for a real user.

php artisan tinker
>>> App\Models\User::first()->createToken('My Token')->accessToken

Confirmed by laravel.com

Did this fix it?

Cause 2 of 3

The client belongs to a different user provider than the model you call

1Check

Passport ties a personal access client to one user provider. Compare the providers in config/auth.php with the model whose createToken you call.

grep -n -A4 "'providers'" config/auth.php

2Fix

Create a personal access client for the provider that matches your model, using the provider name from config/auth.php.

php artisan passport:client --personal --provider=admins

3Verify

createToken on the second model now returns a token.

php artisan tinker
>>> App\Models\Admin::first()->createToken('My Token')->accessToken

Confirmed by laravel.com

Did this fix it?

Cause 3 of 3

The user model does not use Passport's HasApiTokens trait

1Check

createToken is a method of the Laravel\Passport\HasApiTokens trait. The Passport docs ask you to add this trait and the OAuthenticatable interface to your user model.

grep -n "HasApiTokens" app/Models/User.php

2Fix

Import the trait from Passport, and add the OAuthenticatable interface shown in the docs.

use Laravel\Passport\Contracts\OAuthenticatable;
use Laravel\Passport\HasApiTokens;

class User extends Authenticatable implements OAuthenticatable
{
    use HasApiTokens, HasFactory, Notifiable;
}

3Verify

Run createToken again from tinker.

php artisan tinker
>>> App\Models\User::first()->createToken('My Token')->accessToken

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Add php artisan passport:client --personal to your server setup notes next to passport:keys.
  • After restoring a database dump, check that the oauth_clients table came with it.
  • If you only need personal tokens for your own API, read the Passport docs' note about Laravel Sanctum, which is lighter.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.