I have configured Laravel API with Passport (Password Grant) for Nuxt a long time ago, I have no problem to log users, but now I need to create an access token manually for specific purpose.
However, when I try to create a token for a user as below, I'm getting an error:
$user = MyCompany\MyPackage\Models\User::find(123);
$user->createToken('my token')
RuntimeException Personal access client not found. Please create one.
What's missing in my configuration?
Below is my User model:
<?php
namespace MyCompany\MyPackage\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Hash;
use Laravel\Passport\HasApiTokens;
class User extends Authenticatable implements MustVerifyEmail
{
use HasApiTokens;
use Notifiable;
...
}
In order to use createTokens()
, you need to have personal access
token on DB, and you can use the command php artisan passport:client --personal
.
You can have on you DB many client IDS for password, client grant.
On your.env
put the personal id/secret on:
PASSPORT_PERSONAL_ACCESS_CLIENT_ID=client-id-value
PASSPORT_PERSONAL_ACCESS_CLIENT_SECRET=unhashed-client-secret-value