How to get a new Google access token from a refresh token on Node.js

If you’re creating an app where you need to access Google services from a server, you’ll need to store the refresh token from the Google Oauth process. The access tokens periodically expire, so you need the refresh token to manually get a new access token when you need it.

So if you’re using the Passport auth middleware for Node.js you would have something like this to make sure you get the refresh token. Store this refresh token in a database.

Then when you need an access token to access gmail in this case, you could get a new access token like this

— based on these Google Identity Platform docs

By | 2017-11-12T13:25:53+00:00 November 12th, 2017|gist|0 Comments

About the Author:

Andrew Golightly is the lead web developer here at Golightly+. He is a passionate fullstack JavaScript developer. And creates native apps too using React Native. To balance his love for coding, he also works as a counsellor.

Leave A Comment