Refresh oauth2 token google api and HWIOAuthBundle Refresh oauth2 token google api and HWIOAuthBundle symfony symfony

Refresh oauth2 token google api and HWIOAuthBundle


In oauth2.0 to refresh an expired access token you need to send to the endpoint :

  • a grant type equals to 'refresh_token'
  • a valid refreshToken
  • your clientId
  • and your clientSecret

You can't send an expired accessToken to get a new refreshed accessToken.

public function refreshAccessToken($refreshToken, array $extraParameters = array()){    $parameters = array_merge(array(        'refresh_token' => $refreshToken,        'grant_type' => 'refresh_token',        'client_id' => $this->options['client_id'],        'client_secret' => $this->options['client_secret'],    ), $extraParameters);    $response = $this->doGetTokenRequest($this->options['access_token_url'], $parameters);    $response = $this->getResponseContent($response);    $this->validateResponseContent($response);    return $response;}

function refreshAccessToken($refreshToken, ...

and not $accessToken

I think you need to call after construct your client with your credentials

$client = new Google_Client();$client->setAuthConfig('client_secrets.json');$client->refreshToken($client->getRefreshToken());

https://developers.google.com/api-client-library/php/auth/web-app#creatingcred

Are you sure of your $client->setClientId($this->user->getGoogleId()); ?What is getGoogleId() ? I think you need also to create a oauth client id : https://developers.google.com/identity/sign-in/web/devconsole-project

In oauth client_id is not the user id but the app id


Sorry to upset you amigo, but it looks like that package doesn't implement any Refresh Token functionality. Or it's left up to you.

Here's the open issue in their GitHub, have a look: https://github.com/hwi/HWIOAuthBundle/issues/457

Here's a comment from the issue:

This feature exists, yet there is no easy use for it as you need to do everything on your own (dealing with storing more details about token, detecting the expiration, calling Google to get new token, and replacing old), only help from this bundle for now, it's code that allows you to ask Google for new fresh token: GenericOAuth2ResourceOwner::refreshToken(), it should work as expected, but I have not used this bundle for long time =)

People in there are waiting on a Gist (snippet of code) to show them how to do this, but so far nothing.