2013-11-14 72 views
6

我使用HybridAuth2使用CakePHP和我的控制器的功能是作为HybirdAuth用户配置文件请求失败

public function loginwith($provider) { 
     //  $this->autoRender = false; 
     require_once(WWW_ROOT . 'hybridauth/Hybrid/Auth.php'); 

     $hybridauth_config = array(
      "base_url" => 'http://' . $_SERVER['HTTP_HOST'] . $this->base . "/hybridauth/", // set hybridauth path 
      "providers" => array(
       "Google" => array(
        "enabled" => true, 
        "keys" => array("id" => "clientID", "secret" => "clientSecret") 
       ) 
      ) 
     ); 

     try { 
      // create an instance for Hybridauth with the configuration file path as parameter 
      $hybridauth = new Hybrid_Auth($hybridauth_config); 

      // try to authenticate the selected $provider 
      $adapter = $hybridauth->authenticate($provider); 

      // grab the user profile 
      $user_profile = $adapter->getUserProfile(); 

      debug($user_profile); 
     } catch (Exception $e) { 
      // Display the recived error 
      switch ($e->getCode()) { 
       case 0 : $error = "Unspecified error."; 
        break; 
       case 1 : $error = "Hybriauth configuration error."; 
        break; 
       case 2 : $error = "Provider not properly configured."; 
        break; 
       case 3 : $error = "Unknown or disabled provider."; 
        break; 
       case 4 : $error = "Missing provider application credentials."; 
        break; 
       case 5 : $error = "Authentification failed. The user has canceled the authentication or the provider refused the connection."; 
        break; 
       case 6 : $error = "User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again."; 
        $adapter->logout(); 
        break; 
       case 7 : $error = "User not connected to the provider."; 
        $adapter->logout(); 
        break; 
      } 

      // well, basically you should not display this to the end user, just give him a hint and move on.. 
      $error .= "Original error message: " . $e->getMessage(); 
      $error .= "Trace: " . $e->getTraceAsString(); 
      $this->set('error', $error); 
     } 
    } 

的HybridAuth库是在应用程序文件夹下的根目录文件夹

但是,我得到的错误,在情况下6

情况下6:$错误=。“用户配置文件请求失败最有可能的用户没有连接到提供者,他应该再次进行身份验证”;

确切的错误信息是Undefined variable: adapter [APP\Controller\UsersController.php, line 177]指向案例6

任何人都可以提出这是怎么回事。我无法调试这个。

P.S.这种情况仅与谷歌登录

问候, 枪

+0

我知道现在已经很老了,但我也是这样,不知道我是如何创建它的。我必须访问https://security.google.com/settings/security/permissions?pli=1并从Google撤销我的网络应用并重新登录。我真的很想知道是什么导致了这种情况。 – ST0N3

回答

7

你的问题是半个多岁,但在这里你去解决方案:

转到https://console.developers.google.com/和激活Google+ API访问权限。

我今天早些时候遇到了这个问题,结果出来了!

+0

感谢您的回答! –

+3

没有问题。通常我是所有问题都没有答案的人:D –