大家好,我也在这几个地方找过
134 尝试验证用户身份时未返回电子邮件密钥 https://github.com/jaredhanson/passport-facebook/issues/134
我将粘贴标准护照 Facebook 代码。我还指定了配置文件字段。问题是对 FB 的请求没有获取用户的电子邮件地址,这对我的应用程序至关重要。
// 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(profile) 输出:
{ id: '894894191844',
username: undefined,
displayName: undefined,
name: { familyName: 'Something', givenName: 'Karl', middleName: undefined },
gender: 'male',
profileUrl: undefined,
provider: 'facebook',
_raw: '{"id":"1197051993654521","first_name":"Karl","gender":"male","last_name":"Something"}',
_json:
{ id: '1197051993654521',
first_name: 'Karl',
gender: 'male',
last_name: 'Koks',
accessToken: 'XYZ',
refreshToken: undefined } }
任何具体的想法,希望尽快解决这个问题:-)