Skip to content
Advertisement

Laravel Passport Grant Token — Set custom username and password fields

I am working on project which has separate model for users — AppModelsCustomer. And also it has own authorisation fields — Email and cust_password. And also password is hashed by password_hash function.

In my config/auth.php in providers section I set up my custom model:

'providers' => [
    'customers' => [
        'driver' => 'eloquent',
        'model' => AppModelsCustomer::class,
    ],
],

So I am trying to implement Laravel Grand Tokens. I need to make request to /oauth/token/ with client (which was previously created with custom provider field) and customer credentials as like this:

/** @var LaravelPassportClient $client */

$response = Http::asForm
    ->post('https://localhost/oauth/token/', [
        'grant_type' => 'password',
        'client_id' => $client->id,
        'client_secret' => $client->secret,
        'username' => 'example@example.com',
        'password' => password_hash('my-password'),
    ]);

But I am receiving error: invalid_grant — The user credentials were incorrect.

I assume that Passport doesn’t know where to find my Email and cust_password fields. Is there any way to set custom login and password fiends?

Thanks you any advice!

Advertisement

Answer

Well, I wasn’t attentive enough, there is special topics for this situations:

Customizing The Username Field https://laravel.com/docs/9.x/passport#customizing-the-username-field

Customizing The Password Validation https://laravel.com/docs/9.x/passport#customizing-the-password-validation

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement