Last active
November 12, 2017 13:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| passport.authenticate('google', { | |
| scope: ['profile', 'email', 'https://mail.google.com/'], | |
| accessType: 'offline', | |
| prompt: 'consent' | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Details on this here: https://golightlyplus.com/how-to-get-a-new-google-access-token-from-a-refresh-token-on-node-js/