Search code examples
node.jsoauthgoogle-oauthgoogle-analytics-apigoogle-api-nodejs-client

How long is the refresh token valid?


On my localhost, I have authenticated my user and goten a Refresh Token and Access Token using Passportjs.

I am using Google's Official Node.js library to get the Google Analytics data and it all seems to work fine.

On this GitHub issue, Justin clearly mentions that the expiry is set by Google's APIs.

How long is the refresh_token valid and at what time do i have to authorize myself again?


Solution

  • This is more of an Oauth2 question then a Google Analytics question.

    Access tokens on google servers are good for one hour.

    The refresh token does not expire and you can use it as many times as you want to request a new access token.

    You should still handle invalid refresh tokens in your code. The user can revoke your access via there Google account. You can have max 50 out standing refresh tokens before the first one starts working. If i authenticate your application you will be given a refresh token if i do it again you get another refresh token there can be max 50 of them outstanding.

    If the refresh token does become invalid you should just request authentication from your user again. The library you are using should be handling refreshing the access token for you.