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

问题描述:

我成功地使用laravel创建服务器和客户端应用程序,我也可以从服务器应用程序访问数据到客户端应用程序。但是现在我想用codeigniter创建另一个客户端应用程序。除了回调方法,授权工作。那么如何将此代码转换成CodeIgniter 2?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); 
}); 

谢谢

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

  1. 加入 “guzzlehttp /狂饮”: “〜6.0” 在composer.json
  2. 运行作曲家更新
  3. 回调方法代码

    $ HTTP =新\ GuzzleHttp \客户端;

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