最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

NodeJS中的Gmail身份验证

IT培训 admin 6浏览 0评论

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);
    }
  });
}

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. 暂无评论