【问题标题】: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,
    ]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-24
      • 1970-01-01
      • 2020-01-14
      • 2017-01-16
      • 2021-02-05
      • 2021-03-08
      • 2017-07-27
      • 2020-09-03
      相关资源
      最近更新 更多