Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HybirdAuth User profile request failed

I am using HybridAuth2 with CakePHP and my controller function is as

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

The HybridAuth Library is in the webroot folder under app folder

however, i am getting the error which is in case 6 i.e.

case 6 : $error = "User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again.";

The exact error message is Undefined variable: adapter [APP\Controller\UsersController.php, line 177] which points to CASE 6

Can anyone suggest what's going on. I am unable to debug this.

P.S. This happens only with Google Login

Regards, Guns

like image 411
Guns Avatar asked Nov 14 '13 12:11

Guns


1 Answers

Your question is more than half an year old but here you go the solution:

Go to https://console.developers.google.com/ and activate Google+ API access.

I ran into this problem earlier today and that worked out!

like image 70
Afonso Gomes Avatar answered Sep 23 '22 23:09

Afonso Gomes