I'm getting a fatal error when trying to use getSessionData() in hybridAuth v3.1

305 Views Asked by At

Update:

I found out that the documentation I was using as a basis was in fact for the old 2.x version... (https://hybridauth.github.io/hybridauth/userguide/HybridAuth_Sessions.html)

So, my question is different: How can I obtain the session data?

I would like to store it in the database, to enable "persistent sessions", not forcing the users to authorize each time.

I'm getting a fatal error when trying to use getSessionData()

Fatal error: Call to undefined method Hybridauth\Hybridauth::getSessionData()

I'm using version HybridAuth 3.1

include $_SERVER['DOCUMENT_ROOT'].'/_makeitwork/hybridauth/src/autoload.php';
include $_SERVER['DOCUMENT_ROOT'].'/hybridauth_config.php';

use Hybridauth\Exception\Exception;
use Hybridauth\Hybridauth;
use Hybridauth\HttpClient;
use Hybridauth\Storage\Session;

try
{
$hybridauth = new Hybridauth($config);
$adapter = $hybridauth->authenticate("Google");
}
catch(Exception $ex){
var_dump($ex);
return;
}
$hybridauth_session_data = $hybridauth->getSessionData(); -------------------------> error line
2

There are 2 best solutions below

0
Stef Andries On

No, the actual login seems to work.

0
Rob Reynolds On

If you look in the HybridAuth src folder there's a Google.php file that manages the login. Gives a few examples there as to how to get access to the vales.

The documentation is more of an example than an explicit code snippet. I got access to the Google Session Data by looking in that file and using the variable: $tokens = $adapter->getAccessToken();

Depending on how you're invoking the HybridAuth your variables might be different. But the Google.php should help translate it into your code.