Node.js facebook节点passport不返回电子邮件地址
大家好,我一直在寻找几个地方也在这里 134尝试验证用户身份时不返回电子邮件密钥 我将粘贴标准passport Facebook代码。 我还指定了配置文件字段。问题是,对FB的请求没有获取用户的电子邮件地址,这对于我的应用程序是至关重要的Node.js facebook节点passport不返回电子邮件地址,node.js,email,passport.js,facebook-login,passport-facebook,Node.js,Email,Passport.js,Facebook Login,Passport Facebook,大家好,我一直在寻找几个地方也在这里 134尝试验证用户身份时不返回电子邮件密钥 我将粘贴标准passport Facebook代码。 我还指定了配置文件字段。问题是,对FB的请求没有获取用户的电子邮件地址,这对于我的应用程序是至关重要的 // Load the module dependencies var passport = require('passport'), url = require('url'), FacebookStrategy = require('pas
// Load the module dependencies
var passport = require('passport'),
url = require('url'),
FacebookStrategy = require('passport-facebook').Strategy,
config = require('../config'),
users = require('../../app/controllers/users.server.controller');
// Create the Facebook strategy configuration method
module.exports = function() {
// Use the Passport's Facebook strategy
passport.use(new FacebookStrategy({
clientID: config.facebook.clientID,
clientSecret: config.facebook.clientSecret,
callbackURL: config.facebook.callbackURL,
profileFields: ["id", "birthday", "email", "first_name", "gender", "last_name"],
passReqToCallback: true
},
function(req, accessToken, refreshToken, profile, done) {
// Set the user's provider data and include tokens
var providerData = profile._json;
providerData.accessToken = accessToken;
providerData.refreshToken = refreshToken;
console.log(profile);
var email = profile.emails ? profile.emails[0].value : 'karl.something@something.com';
// Create the user OAuth profile
var providerUserProfile = {
firstName: profile.name.givenName,
lastName: profile.name.familyName,
fullName: this.firstName + ' ' + this.lastName,
email: email,
username: profile.username,
provider: 'facebook',
providerId: profile.id,
providerData: providerData
};
// Save the user OAuth profile
users.saveOAuthUserProfile(req, providerUserProfile, done);
}
));
};
在这里您可以看到console.log(概要文件)输出:
如果有任何具体的想法,我想尽快解决这个问题:-)可能不是唯一的解决方案,但以下方法对我有效: 来自
passport.authenticate('facebook')代码>
至
passport.authenticate('facebook',{scope:'email'}))代码>
然后将填充字段电子邮件
答案如下:
我的配置是相同的,除了在profileFields中我使用电子邮件而不是电子邮件
// configure route
app.get('/auth/facebook', passport.authenticate('facebook', {
scope: [ "email" ]
}));
// configure passport
passport.use(facebook(callback));
// configure strategy
export default (callback) => new FacebookStrategy({
clientID: config.auth.facebook.clientID,
clientSecret: config.auth.facebook.clientSecret,
callbackURL: config.auth.facebook.callbackURL,
passReqToCallback: true,
enableProof: true,
profileFields: ['id', 'emails', 'name', 'gender', 'displayName']
}, callback);
可能不是唯一的解决方案,但以下方法对我有效:passport.authenticate('facebook',{scope:'email')代码>然后将填充字段电子邮件
// configure route
app.get('/auth/facebook', passport.authenticate('facebook', {
scope: [ "email" ]
}));
// configure passport
passport.use(facebook(callback));
// configure strategy
export default (callback) => new FacebookStrategy({
clientID: config.auth.facebook.clientID,
clientSecret: config.auth.facebook.clientSecret,
callbackURL: config.auth.facebook.callbackURL,
passReqToCallback: true,
enableProof: true,
profileFields: ['id', 'emails', 'name', 'gender', 'displayName']
}, callback);