我想使用访问令牌进行Gmail身份验证。我正在传递像
这样的价值观const options = {
method: 'GET',
uri: 'https://www.googleapis.com/auth/plus.me',
qs: {
access_token: req.body.gmailToken,
fields: 'id,name,first_name,last_name,email,picture'
}
};
但是我无法从gmail获取auth数据。
是否有另一种方法可以从Gmail获取身份验证数据仅通过传递accessToken?
答案 0 :(得分:2)
uri:' https://www.googleapis.com/auth/plus.me',
Google+ api的结束点是否是gmail api。 Gmail端点看起来像这样
以下教程邮件帮助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);
}
});
}
答案 1 :(得分:0)
答案 2 :(得分:-1)