Laravel护照“转换授权代码访问令牌”代码为codeigniter

时间:2017-03-04 05:06:22

标签: php laravel codeigniter api guzzlehttp

我使用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?

由于

1 个答案:

答案 0 :(得分:1)

无论如何,我已经修好了。

  1. 在composer.json
  2. 中添加“guzzlehttp / guzzle”:“〜6.0”
  3. 正在运行作曲家更新
  4. 回调方法代码

    $ 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));