401使用laravel护照创建密码授予令牌时未经授权

时间:2020-01-16 17:35:48

标签: laravel api oauth laravel-passport laravel-api

我用护照创建了一个api,并希望使用密码授予令牌,因为它更多地是应用程序与应用程序之间的交互。但是当我尝试访问它时,我遇到了错误。

GuzzleHttp\Exception\ClientException
Client error: `POST http://127.0.0.1:8000/oauth/token` resulted in a `401 Unauthorized` response: {"error":"invalid_client","error_description":"Client authentication failed","message":"Client authentication failed"}

我的路线

Route::get('/get_token_by_password', function (Request $request) {

    $http = new GuzzleHttp\Client;

    $response = $http->post('http://192.168.0.103:8000/oauth/token', [
    'form_params' => [
        'grant_type' => 'password',
        'client_id' => 13,
        'client_secret' => 'f37AwQGsVMiZDVu786KiRdbpn4MXYSBWCvqNcqiC',
        'username' => 'developer@ymail.com',
        'password' => '123456789',
        'scope' => '*',
    ],
]);

return json_decode((string) $response->getBody(), true);

})->name('get_token_by_password');
  1. 我可能在做错什么?

  2. 另外,我如何使用邮递员来获取令牌?

  3. 我如何获得要在要使用我的api的其他应用程序中使用的链接

1 个答案:

答案 0 :(得分:0)

该请求似乎正确。检查您是否具有正确的密钥和客户端。之后,在数据库中检入client_secret的新值。

php artisan passport:keys

php artisan passport:client --password