Reputation: 95
I'm trying to enlarge value of 'expires_in' (from credential object, now it is 3600 seconds), because I want to allow user to use my app for a long time. I'm using refreshing token, but it refreshed only if user uses app quite often.
If you know how to change token_expiry date - I'm interested of that solution too.
Thank you for any tips.
Upvotes: 5
Views: 5469
Reputation: 2987
For security reason, expiration time is short and it cannot be changed. However, you can extend user's authorization without interacting with user using refresh_token. Basically, as a response to auth code exchange, the server provides refresh_token which looks like this:
{
"access_token" : "ya29.AHES6ZTtm7SuokEB-RGtbBty9IIlNiP9-eNMMQKtXdMP3sfjL1Fc",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "1/HKSmLFXzqP0leUihZp2xUt3-5wkU7Gmu2Os_eBnzw74"
}
When token expires, all you have to do is to use refresh_token to reauthorize, without user interaction. Like this:
POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded
client_id=21302922996.apps.googleusercontent.com&
client_secret=XTHhXh1SlUNgvyWGwDk1EjXB&
refresh_token=1/HKSmLFXzqP0leUihZp2xUt3-5wkU7Gmu2Os_eBnzw74
grant_type=refresh_token
To make things more simple, when you are using Python, you don't even have to care about refresh_token if you are using Credentials class from google-api-python-client. Just use Credentials.authorize() and it will automatically authorize or refresh token based on your status.
Upvotes: 8