How i can refresh token ? I use Google api with this token - it work but can't find how to refresh it, in this example we dont save expired time. I require
`access_type: offline `
then
$client = new Google_Client();
//$client->setClientId($GoogleClientId);
$client->setApplicationName($GoogleAppName);
$client->setClientId($this->user->getGoogleId());
$client->setAccessType('offline');
if token is valid i can work but when is expired i try
$token = [
'access_token' => $this->user->getGoogleAccessToken(),
'expires_in' => (new \DateTime())->modify('-1 year')->getTimestamp(),
];
i put this any date because in this example we don't save expired time
https://gist.github.com/danvbe/4476697
$client->setAccessToken($token);
if($client->isAccessTokenExpired()){
$refreshedToken = $client->refreshToken($client->getAccessToken());
here i have error
array:2 [▼
"error" => "invalid_request"
"error_description" => "Could not determine client ID from request."
]
There is HwiAuthBundle method to refresh token ? Why this not work with Google_Client refresh ?
In oauth2.0 to refresh an expired access token you need to send to the endpoint :
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With