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:00November 12th, 2017|gist|1 Comment

About the Author:

Andrew Golightly is the lead web developer here at Golightly+. He is a passionate fullstack JavaScript developer. He also runs an Empath Community.

One Comment

  1. Anu Mishra September 14, 2018 at 9:51 am - Reply

    ReferenceError: getAccessToken is not define

Leave A Comment