2017-01-19 57 views
2

我嘗試在Laravel Passport上創建oauth2服務器並從第三方應用程序對其進行測試。 Oauth服務器使用Laravel,客戶端使用Yii框架。我無法修改客戶端前端和我創建了一個路線/ API/OAuth的/登入,將請求轉發到OAuth服務器:Laravel護照oauth /授權返回基本認證

public function actionOauthLogin() 
{ 
    $query = http_build_query([ 
     'client_id' => '12', 
     'client_secret' => '', 
     'redirect_uri' => 'http://client.loc/api/oauth/callback', 
     'response_type' => 'code', 
     'scope' => '', 
    ]); 
    return $this->redirect('http://oauth-server.loc/oauth/authorize?' . $query); 
} 

這種方法處理/ API/OAuth的/回調路線:

public function actionOauthCallback() 
{ 
    $http = new Client(); 
    $response = $http->post('http://oauth-server.loc/oauth/token', [ 
     'form_params' => [ 
      'grant_type' => 'authorization_code', 
      'client_id' => '3', 
      'client_secret' => 'TJDyfygkuga45rtyfj8&65567Yhhgjjjj', 
      'redirect_uri' => 'http://client.loc/api/oauth/callback', 
      'code' => Yii::app()->request->getParamFromRequest('code'), 
     ], 
    ]); 
    return json_decode((string) $response->getBody(), true); 
} 

所有在文檔中實現。但是當我打開/ api/oauth/login,將重定向轉發到oauth-server.loc/oauth/authorize?{params}並且我看到一個http基本認證窗口。跆拳道? Nginx沒有這樣的設置。有人知道我做錯了什麼?請幫幫我。

+0

昨天我在Yii上安裝了phpleague oauth2客戶端(http://oauth2-client.thephpleague.com/providers/implementing/)。但結果是一樣的。 – epod

+0

我收到了完全相同的問題。你有沒有想出一個解決方案? @epod – kirgy

回答

0

我有同樣的問題,在我的情況下返回的參數告訴我,我的分析範圍無效;一些OAuth2 API需要可能存在此問題的範圍。

解決方案是將您的應用程序允許的範圍數組添加到AuthServiceProvider引導方法中。

// ../app/Providers/AuthServiceProvider.php 
// ... 
    public function boot() 
    { 

     $this->registerPolicies(); 
     Passport::tokensCan([ 
      'manage-devices' => 'Manage devices', 
      'place-orders' => 'Place orders', 
      'check-status' => 'Check order status', 
     ]); 

//.. 
0

確保'redirect_uri' => 'http://client.loc/api/oauth/callback'是一樣的作爲與匹配client_id

0

您需要在「oauth_clients列「personal_access_client」,「password_client」設置0保存在oauth_clients表中的重定向URL 「表爲我們的客戶端,並設置redirect_uri相同的請求。