Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Credentials - Issue #606

Closed
dibeesh opened this issue Jul 20, 2016 · 5 comments
Closed

Invalid Credentials - Issue #606

dibeesh opened this issue Jul 20, 2016 · 5 comments
Assignees

Comments

@dibeesh
Copy link

dibeesh commented Jul 20, 2016

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?

@sunknudsen
Copy link

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

@lirbank
Copy link

lirbank commented Jul 30, 2016

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 #261 (comment)

@ace-n
Copy link
Contributor

ace-n commented Apr 14, 2017

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

@JustinBeckwith
Copy link
Contributor

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

@JustinBeckwith JustinBeckwith self-assigned this Feb 1, 2021
@gyan-js
Copy link

gyan-js commented Apr 8, 2024

If you guys are using Firebase, then I advice y'all to switch to MongoDB since idToken can be a problem while implementing Google Authentication in your react native android project. Anyways idToken doesn't hold any significance other than verifying the user's identity, which can be done through other methods(accessTokens and sessions) too. We basically use googleapis in our project, which only requires the accessToken(it can be obtained in though simple google sign in, no matter what third-party platforms we use).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants