google-oauth

How do I request a access token that expires longer than 3599 seconds?


I am playing with GIS and the token I request only lasts for 3599 seconds, it looks like this:

{"access_token":"ya29.****","token_type":"Bearer","expires_in":3599,...

The token only lasts for 3599 seconds.

Is there any way that I can make it last longer?

I'm using the Javascript client to request the token in a browser like this:

tokenClient.requestAccessToken();

Thanks


Solution

  • This is an integral part of Oauth2. Access tokens are bearer tokens which means that they are valid to who ever has it but only for a limited amount of time.

    The most common expiration is one hour. There are two ways to get a new one.

    1. Ask the user to authorize the application again after the access token has expired.
    2. Request offline access, in which case you will get a refresh token back. A refresh token can be used to request a new access token. (this can not be done with client side JavaScript only with server sided programming languages.)