Search code examples
hybridauth

hybridauth - can not restore google login


I have made login script with HybridAuth. I'm loged in my website with "providers" Facebook, Google, Twitter. When PHP sessions time out, I want to restore my connected "providers".

I use this code :

    $connected_adapters_list = $hybridauth->getConnectedProviders(); 
          if( count( $connected_adapters_list ) ){
                foreach( $connected_adapters_list as $adapter_id ){
                    echo  $adapter_id . "<br>";
          }
    }

HybridAuth can restore my Facebook and Twitter connection, but not Google. This is code error output. How to solve it ?

Ooophs, we got an error: User profile request failed! Google returned an invalid response:stdClass::__set_state(array( 'error' => stdClass::__set_state(array( 'errors' => array ( 0 => stdClass::__set_state(array( 'domain' => 'global', 'reason' => 'authError', 'message' => 'Invalid Credentials', 'locationType' => 'header', 'location' => 'Authorization', )), ), 'code' => 401, 'message' => 'Invalid Credentials', )), )) Error code: 6

Solution

  • I also has this problem,

    it could be sloved by using "logoutAllProviders()" function

    there is code :

       try{
           $hybridauth = new Hybrid_Auth( $config );
    
            $adapter = $hybridauth->authenticate( "Google" );
            $user_profile = $adapter->getUserProfile();
    
       }
       catch( Exception $e ){
            $hybridauth->logoutAllProviders();
            $hybridauth = new Hybrid_Auth( $config );          
            $adapter = $hybridauth->authenticate( "Google" );
            $user_profile = $adapter->getUserProfile();
       }
    }
    

    good luck for you !