Refresh token and invalid_grant error confusion
See original GitHub issueI have successfully implement the whole OAuth process using googleapis in my app and it works but I still get the invalid_grant
error every now and then. I searched for a solution to this and it seems there is a lot of confusion as to how the tokens should work.
When I want to make a call to one of the APIs I set the credentials like so:
oauth2Client.setCredentials({
access_token: "ACCESSTOKEN",
refresh_token: "REFRESHTOKEN"
})
and set an event listener for .on('tokens')
to get the new set of tokens in case the current ones are expired and when that happens I save them to the db but the invalid_grant
error is still thrown on that call. Only the next call with updated tokens eventually works (or sometimes doesn’t and the whole integration needs to be reauthenticated).
Should I send the refresh_token
with every API call in case the tokens are expired and new ones will be issued? Some people suggested this issues a new token on every call and eventually exceeds the token quota for the user.
How do I get a new working token before making the API call so that there’s no invalid_grant
error?
There seems to be a widespread confusion about how those tokens work. It would be nice if it was explained in the documentation.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
@bcoe thanks, I think I’ve resolved my problem here.
When I put access_token and refresh_token to setCredentials, it works and automatically replaces the previous access token.
And I can obtain new access token after refreshing with this function
@parkerproject Is this still a problem? If it is, please open a new issue describing the environment you’re in, the specific API you’re calling, and providing as much details as possible. Also, we updated the documentation for refresh tokens here.
Since this issue is originally about a different problem, I’ll close it now.