【问题标题】:Laravel passport creating a oauth_client with userid not with php artisan passport:client --passwordLaravel 护照使用用户 ID 创建 oauth_client,而不是使用 php artisan 护照:client --password
【发布时间】:2020-04-17 21:48:49
【问题描述】:
我是新的 Laravel Passport,我想创建一个带有 user_id 的 oauth_client,现在表 oauth_clients 中的 user_id 为空。
我想通过 user_id 登录并获取 oauth_clients 凭据。
我怎样才能创建一个基于user_id 的oauth 客户端,所以不是 使用php artisan passport:client --password 而是使用端点。
我希望有人可以帮助我如何实现。
【问题讨论】:
标签:
laravel
laravel-passport
【解决方案1】:
您可以使用ClientRepository::class。
个人访问客户端
use Laravel\Passport\ClientRepository;
(new ClientRepository)->createPersonalAccessClient($userId, $name, $redirect);
密码授予客户端
use Laravel\Passport\ClientRepository;
(new ClientRepository)->createPasswordGrantClient($userId, $name, $redirect);
或来自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,
]);