Skip to content

Instantly share code, notes, and snippets.

@magician11
Last active November 12, 2017 13:29
Show Gist options
  • Save magician11/205764591ba3e7a8be6725d9ddc6f519 to your computer and use it in GitHub Desktop.
Save magician11/205764591ba3e7a8be6725d9ddc6f519 to your computer and use it in GitHub Desktop.
How to get a new Google access token from a refresh token on Node.js
const axios = require('axios');
const querystring = require('querystring');
const keys = require('../config/keys');
const getAccessToken = async refreshToken => {
try {
const accessTokenObj = await axios.post(
'https://www.googleapis.com/oauth2/v4/token',
querystring.stringify({
refresh_token: refreshToken,
client_id: keys.googleClientID,
client_secret: keys.googleClientSecret,
grant_type: 'refresh_token'
})
);
return accessTokenObj.data.access_token;
} catch (err) {
console.log(err);
}
};
passport.authenticate('google', {
scope: ['profile', 'email', 'https://mail.google.com/'],
accessType: 'offline',
prompt: 'consent'
});
@magician11
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment