2017-03-04 90 views
0

我成功地使用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

無論如何,我已經修好了。

  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)); 
    
相關問題