Bas
Bas

Reputation: 2400

Laravel passport creating a oauth_client with userid not with php artisan passport:client --password

I am new Laravel Passport and i want to create a oauth_client with a user_id, now in the table oauth_clients is the user_id null.

I want to login and get the oauth_clients credentials by user_id.

How can i create a oauth client based on a user_id so not with php artisan passport:client --password but with a endpoint.

I hope someone can help me how to achieve.

Upvotes: 1

Views: 1585

Answers (1)

W Kristianto
W Kristianto

Reputation: 9313

You can use ClientRepository::class.

Personal access client

use Laravel\Passport\ClientRepository;

(new ClientRepository)->createPersonalAccessClient($userId, $name, $redirect);

Password grant client

use Laravel\Passport\ClientRepository;

(new ClientRepository)->createPasswordGrantClient($userId, $name, $redirect);

Or from Passport::class

Passport::client()->forceFill([
    'user_id'                => $userId,
    'name'                   => $name,
    'secret'                 => ($confidential || $personalAccess) ? Str::random(40) : null,
    'redirect'               => $redirect,
    'personal_access_client' => $personalAccess,
    'password_client'        => $password,
    'revoked'                => false,
]);

Upvotes: 2

Related Questions