The token access expires in a short time, apparently related to security of access. If the same is compromised, the access expires in a short time and with it the threat.
But there is the token update, which can be used to update the session and thus generate another token access, contributing to a larger session.
Concept
// fazer operações de login...
// recolher o token de acesso
$_SESSION['token'] = $client->getAccessToken();
// se temos o token de acesso
if (isset($_SESSION['token']) && $_SESSION['token']!='') {
// definir um novo token de acesso
$client->setAccessToken($_SESSION['token']);
/* Descodificar o JSON que guardamos na variável de sessão
* e passar o mesmo para uma variável na forma de um objecto
*/
$sessionToken = json_decode($_SESSION['token']);
/* guardar o token de actualização num cookie com o nome "token",
* dando-lhe um tempo de vida maior
*/
setcookie("token", $sessionToken->refresh_token, time()+60*60*24*30); /* 1 mês de vida */
}
Update the session if you have to re-login
Where necessary the token access, we can check the cookie:
- Empty, we must request a new token access and a new token by means of authentication;
If it’s not empty, Let’s tell the customer to update the token:
if isset($_COOKIE['token'] && $_COOKIE['token']!='') {
$client->refreshToken($_COOKIE['token']);
}
We’re basically updating the token with the help of token update without we perform login again.
Notes:
This response is an adaptation to an anonymous format of reply given by @hope_industries on SOEN.
Consultation the same for the practical case that is there treated.
The problem there is not in Laravel, if the google API does not give you the option to set the session time, you will not be able to do anything.
– Richard Feliciano
Can you add to your question how you are logging in? Your code will allow you to evaluate the appropriate solution without it is difficult to answer in order to solve your problem.
– Zuul
There are not many ways to log in to google https://github.com/google/google-api-php-client
– Thiago Bueno