我使用laravel成功创建服务器和客户端应用程序,我也可以从服务器应用程序访问数据到客户端应用程序。但现在我想使用codeigniter创建另一个客户端应用程序。授权工作除了回调方法。那我怎么能转换这段代码
Route::get('/callback', function (Request $request) {
$http = new GuzzleHttp\Client;
$response = $http->post('http://your-app.com/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 'client-id',
'client_secret' => 'client-secret',
'redirect_uri' => 'http://example.com/callback',
'code' => $request->code,
],
]);
return json_decode((string) $response->getBody(), true);
});
进入CodeIgniter 2?
由于
答案 0 :(得分:1)
无论如何,我已经修好了。
回调方法代码
$ http = new \ GuzzleHttp \ Client;
$response = $http->post('http://localhost:8000/oauth/token', [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => '3',
'client_secret' => 'client-secret-from-db',
'redirect_uri' => 'ci-client-app/callback',
'code' => $this->input->get('code', TRUE)
],
]);
echo '<pre>', print_r(json_decode((string) $response->getBody(), true));