在使用Laravel Passport过程中,请求oauth/token时遇到如下错误:
{
"error": "unsupported_grant_type",
"message": "The authorization grant type is not supported by the authorization server.",
"hint": "Check the `grant_type` parameter"
}
其实这个错误写的非常详细了,就是grant_type错误,解决方法也写上了,就是检查你的grant_type配置。
官方文档的示例代码:
$http = new GuzzleHttpClient;
$response = $http->post('https://www.codesou.cn/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);
请注意上面的grant_type
,如果没写这个参数或者参数的值不正确,那么就会报unsupported_grant_type,一般开发中这个位置的值应该是password
或者client_credentials
。