2013-11-14 19 views
6

ich HybridAuth2 mit CakePHP verwenden und meine Controller-Funktion ist alsHybirdAuth Benutzerprofil Anfrage fehlgeschlagen

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

Die HybridAuth Bibliothek ist im Webroot-Ordnern unter App-Ordner

aber ich bin immer den Fehler, in Fall ist 6 dh

Fall 6: $ error = „. Anfrage Benutzerprofil fehlgeschlagen wahrscheinlich wird der Benutzer nicht an den Provider verbunden und er sollte wieder authentifizieren“;

Die genaue Fehlermeldung ist Undefined variable: adapter [APP\Controller\UsersController.php, line 177] die 6 CASE Punkte

Kann jemand empfehlen, was los ist. Ich kann das nicht debuggen.

P.S. Dies geschieht nur mit Google Anmeldung

Grüße, Guns

+0

Ich weiß, das ist jetzt ziemlich alt, aber ich habe es auch und habe keine Ahnung, wie ich es erstellt habe. Ich musste https://security.google.com/settings/security/permissions?pli=1 aufrufen und meine Web-App von Google widerrufen und mich erneut anmelden. Ich würde gerne wissen, was das verursacht hat. – ST0N3

Antwort

7

Ihre Frage ist mehr als ein halbes Jahr alt, aber hier gehen Sie die Lösung:

Zum https://console.developers.google.com/ und Google+ API-Zugriff aktivieren.

Ich lief dieses Problem früher heute und das hat geklappt!

+0

Danke für die Antwort! –

+3

Kein Problem. Normalerweise bin ich der Typ mit allen Fragen und ohne Antworten: D –

Verwandte Themen