2013-11-14 19 views
6

Tôi đang sử dụng HybridAuth2 với CakePHP và chức năng điều khiển của tôi là nhưHybirdAuth Yêu cầu hồ sơ tài thất bại

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

Các HybridAuth Thư viện là trong thư mục webroot trong thư mục ứng dụng

Tuy nhiên, tôi đang nhận lỗi mà là trong trường hợp tức

trường hợp 6: $ lỗi = ". yêu cầu hồ sơ tài thất bại Nhiều khả năng người sử dụng không được kết nối với nhà cung cấp và ông nên để xác thực một lần nữa";

Các thông báo lỗi chính xác là Undefined variable: adapter [APP\Controller\UsersController.php, line 177] mà chỉ cho trường hợp 6

bất cứ ai có thể đề xuất những gì đang xảy ra. Tôi không thể gỡ lỗi này.

P.S. Điều này xảy ra chỉ với Google Đăng nhập

Kính trọng, Guns

+0

Tôi biết điều này là khá cũ bây giờ nhưng tôi chỉ có điều này quá và không có ý tưởng làm thế nào tôi tạo ra nó. Tôi phải truy cập https://security.google.com/settings/security/permissions?pli=1 và thu hồi ứng dụng web của tôi từ Google và đăng nhập lại. Tôi thực sự muốn biết điều gì đã gây ra điều này. – ST0N3

Trả lời

7

Câu hỏi của bạn là hơn nửa năm cũ nhưng ở đây bạn đi là giải pháp:

Đến https://console.developers.google.com/ và kích hoạt Google+ truy cập API.

Tôi đã gặp phải vấn đề này sớm hơn hôm nay và điều đó đã xảy ra!

+0

Cảm ơn bạn đã trả lời! –

+3

Không có prob. Thông thường tôi là chàng trai với tất cả các câu hỏi và không có câu trả lời: D –

Các vấn đề liên quan