关于 passport code 授权总是报错?
Route::get('/redirect', function (\Illuminate\Http\Request $request) {
$input = $request->all();
$query = http_build_query([
'client_id' => $input['client_id'],
'redirect_uri' => 'http://47.100.101.163/callback',
// 'redirect_uri' => $input['redirect_uri'],
'response_type' => 'code',
'scope' => '',
]);
return redirect('http://47.100.101.163/oauth/authorize?'.$query);
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/callback', function (Request $request){
$http= new GuzzleHttp\Client;
$response = $http->post('http://47.100.101.163/oauth/token',[
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 1 ,
'client_secret' => 'So44lwn8bDXvoy4eTTzqfQFltQnBMzblyUaEO9Gm' ,
'redirect_uri' => 'http://47.100.101.163/callback',
'code' => $request->code,
],
]);
return json_decode((string) $response->getBody(), true);
});
数据种子的数据是这样的
1 2 Laravel Personal Access Client So44lwn8bDXvoy4eTTzqfQFltQnBMzblyUaEO9Gm http://47.100.101.163/callback 1 0 0 2018-01-17 10:35:13 2018-01-17 10:35:13
但是还是会报错
{"error":"invalid_client","message":"Client authentication failed"}
日志报错如下:
[2018-01-17 10:23:56] local.ERROR: The authorization grant type is not supported by the authorization server. {"userId":2,"exception":"[object] (League\OAuth2\Server\Exception\OAuthServerException(code: 2): The authorization grant type is not supported by the authorization server. at /Users/hantian/Desktop/jushi_laravel/vendor/league/oauth2-server/src/Exception/OAuthServerException.php:65)
请各位大神解答一下
已经找到问题:
在表 oauth_clients 中还有两个字段 personal_access、password,对于授权码模式来说这两个字段都要求为 0。
检查一下请求的
client_id
字段的值在数据库oauth_clients
表中是否存在哦