在使用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。




















