Google-api-nodejs-client: Invalid Credentials - Issue

Created on 20 Jul 2016  路  4Comments  路  Source: googleapis/google-api-nodejs-client

0
down vote
favorite
I have an issue with Google plus access token. It is giving me "Invalid Credentials" error message sometimes, sometimes the same token show as active.

Following are the steps

The user confirms permission to access Google account with selected scopes.

The refresh token and access token is retrieved and saved to long time storage.

Used to refresh the token when ever needed by using stored refresh token

But sometimes I've experienced strange behaviour: Requests to Google APIs return Invalid Credentials (401) error. Refreshing the access token (using the stored refresh token) does not work.

Access token refresh method Using
googleapis npm module to refresh token https://www.npmjs.com/package/googleapis

 oauth2Client.refreshAccessToken(function (err, tokens) {
            if (err) {
              console.log('error', err);
            }
            console.log('access tokens', tokens.access_token); // Access token 
            console.log('refresh tokens', tokens.refresh_token); // Refresh token       
        });

Questions: What can be the reason for this behaviour?

Does this behaviour related to with any google api rate limit? because the same token works sometimes and not other-times.

Is there a way to validate the refresh token?

All 4 comments

Hey @dibeesh,

Not sure if this will help, but had a similar Invalid Credentials problem and noticed that setting the expiry_date solved it.

oauth2Client.setCredentials({
  access_token: 'ACCESS TOKEN HERE',
  refresh_token: 'REFRESH TOKEN HERE'
  expiry_date: '1469787756005' // unix timestamp more than an hour in the past (access tokens expire after an hour)
});
plus.people.get({ userId: 'me', auth: oauth2Client }, function(err, response) {
  // handle err and response 
});

See: http://stackoverflow.com/questions/37392819/google-auth-library-refresh-token-not-replaying-request/38657674#38657674

The API returns an expiry_date, store it along with the tokens and use it in the following requests and everything should play nicely. See https://github.com/google/google-api-nodejs-client/issues/261#issuecomment-233215639

Hi @dibeesh - is this still an issue for you? If not, mind if I close this?

Greetings! If this is still an issue, let us know!

Was this page helpful?
0 / 5 - 0 ratings