Dragon
主机之家测评主机之家测评  2020-07-07 06:21 主机之家测评 隐藏边栏 |   抢沙发  81 
文章评分 0 次,平均分 0.0

在使用Laravel Passport 过程中,请求 oauth/token 时遇到如下错误:

  {      "error": "invalid_client",      "error_description": "Client authentication failed",      "message": "Client authentication failed"  }

产生这个错误的原因是你的参数配置错误,请仔细检查参数配置与数据库中的设置。

官方文档的示例代码:

  $http = new GuzzleHttpClient;    $response = $http->post('http://your-app.com/oauth/token', [      'form_params' => [          'grant_type' => 'password',          'client_id' => 'client-id',          'client_secret' => 'client-secret',          'username' => 'taylor@laravel.com',          'password' => 'my-password',          'scope' => '',      ],  ]);    return json_decode((string) $response->getBody(), true);

请逐个检查上述 form_params 中的参数名及参数值,仔细对比,这里很容易出错,比如‘grant_type’没配置,那么还会报:Laravel Passport unsupported_grant_type 的错误,如果都对,那么请往下看。

如果你的项目不需要 password 认证,也就是你的 form_params 中没有

'password' => 'my-password',

这一项,那么你的‘grant_type’应该设置为:client_credentials。

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

发表评论

扫一扫二维码分享