facebook节点护照不返回电子邮件地址
Posted
技术标签:
【中文标题】facebook节点护照不返回电子邮件地址【英文标题】:facebook node passport does not return email address 【发布时间】:2015-12-12 01:07:20 【问题描述】:大家好,我也在这几个地方找过
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
任何具体的想法,希望尽快解决这个问题:-)
【问题讨论】:
可能不是唯一的解决方案,但以下解决方案对我有用:passport.authenticate('facebook', scope: 'email'));
然后将填充字段电子邮件
【参考方案1】:
可能不是唯一的解决方案,但以下对我有用:
来自
passport.authenticate('facebook');
到
passport.authenticate('facebook', scope: 'email'));
然后将填充字段电子邮件
在这里找到答案: passport-facebook - cant get about_me and email profile fields
【讨论】:
【参考方案2】:我的配置是相同的,除了在 profileFields 中我使用 emails(复数)而不是 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);
【讨论】:
以上是关于facebook节点护照不返回电子邮件地址的主要内容,如果未能解决你的问题,请参考以下文章
使用带护照本地的护照Facebook策略时无法将用户序列化到会话中
iOS登录与Facebook不返回电子邮件甚至参数和权限给出
使用电子邮件进行身份验证时,NestJS 护照身份验证返回 401