Integrate HWIOAuthBundle and Google Api Client - How to set correct token

531 Views Asked by At

I have symfony2 page where i use HWIOAuthBundle integrated with FOSUserBundle. HWIOAuth using my own user provider which extend through base FOSUBUserProvider (HWI\Bundle\OAuthBundle\Security\Core\User\FOSUBUserProvider). With this class i am able to retrieve information about AccessToken. My question is - how to set correct access token in Google Api Client, example code:

$client = new \Google_Client();
$client->setApplicationName("XXX");
$client->setClientId($this->container->getParameter('google_client_id'));
$client->setClientSecret($this->container->getParameter('google_client_secret'));

var_dump($user->getGoogleAccessToken()); // 83 characters string with google access token

$client->setAccessToken($user->getGoogleAccessToken());

Last line throws error "Could not json decode the token", when i trying to set json_encode then it throws "Invalid token format" error

1

There are 1 best solutions below

0
On

If you are using the v2 of Google PHP SDK, you should do the following

$client->setAccessToken([
    'access_token' => $accessToken,
    'expires_in'   => $expiresIn,
]);

Regards