Google OAuth2 API Refresh Tokens

天大地大妈咪最大 提交于 2019-12-01 00:05:16

Okay, so I have discovered the getAccessToken method, which will check the access_token, and use it, unless it has expired, in which case it will use the refresh_token to generate a new access_token.

Here is the updated solution to get Access Token with Refresh Token:

const { google } = require("googleapis");
const OAuth2 = google.auth.OAuth2;

const oauth2Client = new OAuth2(
  "xxxxxxxxx.apps.googleusercontent.com", // ClientID
  "xxxxxxx", // Client Secret
  "https://developers.google.com/oauthplayground" // Redirect URL
);

oauth2Client.setCredentials({
  refresh_token:
    "xxxxxxxx"
});

const accessToken = oauth2Client.getAccessToken();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!