关于 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)

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 3

请各位大神解答一下

6年前 评论

已经找到问题:
在表 oauth_clients 中还有两个字段 personal_access、password,对于授权码模式来说这两个字段都要求为 0。

6年前 评论
RyanFeng

检查一下请求的client_id字段的值在数据库oauth_clients表中是否存在哦

6年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!