2017-01-19 58 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相同的请求。