2013-11-14 13 views
6

Sto usando HybridAuth2 con CakePHP e la mia funzione di controllo è comeHybirdAuth richiesta di profilo utente non è riuscita

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

La Biblioteca HybridAuth si trova nella cartella webroot nella cartella app

però, sto ottenendo l'errore che è in caso 6 cioè

caso 6: $ error = ". richiesta di profilo utente non è riuscita Molto probabilmente l'utente non è connesso al provider e lui dovrebbe per l'autenticazione di nuovo";

Il messaggio di errore esatto è Undefined variable: adapter [APP\Controller\UsersController.php, line 177] che punta a CASE 6

chiunque può suggerire quello che sta succedendo. Non riesco a eseguire il debug di questo.

P.S. Questo accade solo con Google Entra

saluti, Guns

+0

So che questo è abbastanza vecchio ora ma ho appena ottenuto anche questo e non ho idea di come l'ho creato. Dovevo andare su https://security.google.com/settings/security/permissions?pli=1 e revocare la mia app Web da Google e accedere di nuovo. Mi piacerebbe davvero sapere cosa ha causato questo. – ST0N3

risposta

7

La tua domanda è più della metà di un anno, ma qui si va la soluzione:

Vai a https://console.developers.google.com/ e attivare Google+ accesso API.

Mi sono imbattuto in questo problema all'inizio di oggi e questo ha funzionato!

+0

Grazie per la risposta! –

+3

Nessun prob. Di solito sono il ragazzo con tutte le domande e senza risposte: D –

Problemi correlati