最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

NodeJS中的Gmail身份验证

运维笔记admin11浏览0评论

NodeJS中的Gmail身份验证

NodeJS中的Gmail身份验证

我想使用访问令牌进行Gmail身份验证。我正在传递价值,

const options = {
    method: 'GET',
    uri: '.me',
    qs: {
        access_token: req.body.gmailToken,
        fields: 'id,name,first_name,last_name,email,picture'
    }
};

但是我无法从gmail获取auth数据。

还有其他方法可以通过传递accessToken从Gmail获取身份验证数据吗?

回答如下:

:'https://www.googleapis/auth/plus.me',

Google+ api的终点是否是gmail api。 Gmail端点如下所示

https://www.googleapis/gmail/v1/

以下教程邮件帮助Node.js Quickstart - Gmail

Gmail身份验证

/**
 * Create an OAuth2 client with the given credentials, and then execute the
 * given callback function.
 *
 * @param {Object} credentials The authorization client credentials.
 * @param {function} callback The callback to call with the authorized client.
 */
function authorize(credentials, callback) {
  var clientSecret = credentials.installed.client_secret;
  var clientId = credentials.installed.client_id;
  var redirectUrl = credentials.installed.redirect_uris[0];
  var auth = new googleAuth();
  var oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);

  // Check if we have previously stored a token.
  fs.readFile(TOKEN_PATH, function(err, token) {
    if (err) {
      getNewToken(oauth2Client, callback);
    } else {
      oauth2Client.credentials = JSON.parse(token);
      callback(oauth2Client);
    }
  });
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论