首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用LinkedIn进行身份验证的护照策略使用OAuth 1.0AAPI在保存用户上返回未定义的电子邮件

用LinkedIn进行身份验证的护照策略使用OAuth 1.0AAPI在保存用户上返回未定义的电子邮件
EN

Stack Overflow用户
提问于 2017-07-25 12:12:05
回答 1查看 599关注 0票数 0

我是node.js开发的初学者,并试图构建一个基于Express框架的应用程序。我实现了护照-本地护照-脸书和护照-领英,让用户注册和登录应用程序,以及链接多个社会帐户到一个用户帐户在mongoDb (从这个教程)。

我的问题是,我总是得到未定义的电子邮件字段时,使用护照-领英,即使我可以得到一个正确的身份验证用户的名字和姓氏。

passport.js

代码语言:javascript
复制
passport.use(new LinkedinStrategy({
consumerKey     : configAuth.linkedinAuth.consumerKey,
consumerSecret  : configAuth.linkedinAuth.consumerSecret,
callbackURL     : configAuth.linkedinAuth.callbackURL,
passReqToCallback : true // allows us to pass in the req from our route (lets us check if a user is logged in or not)
},
  function(req, token, tokenSecret, profile, done) {
  // asynchronous
  process.nextTick(function() {
   // check if the user is already logged in
   if (!req.user) {
    User.findOne({ 'linkedin.id' : profile.id }, function(err, user) {
    if (err)
        return done(err);
      if (user) {
        // if there is a user id already but no token (user was linked at one point and then removed)
        if (!user.linkedin.token) {
        [...]
        } else {
         // if there is no user, create them
         var newUser                  = new User();
         newUser.linkedin.id          = profile.id;
         newUser.linkedin.token       = token;
         newUser.linkedin.firstname   = profile.name.givenName;
         newUser.linkedin.lastname    = profile.name.familyName;
         newUser.linkedin.email       = profile.emails;
         newUser.save(function(err) {
            if (err)
                return done(err);
            return done(null, newUser);
         });
        }
      });
    } else {
    // user already exists and is logged in, we have to link accounts
    [...]
  }
 });
}));

路线/帐户

代码语言:javascript
复制
// linkedin --------------------------------
// send to linkedin to do the authentication
app.get('/auth/linkedin', passport.authenticate('linkedin', { scope: ['r_basicprofile', 'r_emailaddress'] }));

// handle the callback after linkedin has authenticated the user
app.get('/auth/linkedin/callback',
  passport.authenticate('linkedin', {
    successRedirect : '/profile', // redirect to the secure profile section
    failureRedirect : '/signup', // redirect back to the signup page if there is an error
    failureFlash : true // allow flash messages
}));

通过查看Passport-LinkedIn/lib/strategy.js,我可以找到名字和姓氏保存到我的用户数据库中,然后我对profile.emails位做了同样的操作,在对用户进行身份验证后仍然没有“定义”。

提前谢谢你的帮助。

编辑:来自LinkedIn Developer FAQ

虽然我们还没有宣布官方反对将OAuth 1.0a与LinkedIn的API结合起来,但我们不再积极鼓励或支持它的使用。 使用OAuth 1.0a构建的现有应用程序将继续正常工作,直到我们正式宣布其日落。 强烈鼓励所有应用程序使用或转换到OAuth 2.0。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-26 13:00:01

之前也有同样的问题,现在已经开始运作了。你和oauth2试过吗?如果你已经实现了护照-linkedin,那么这应该是对你的passport.js文件的小改动。Linkedin 1.0遭到了OAuth的反对,因此它可能会导致一些问题来检索一些信息。我猜你也面临着同样的情况。试试这个,你就可以走了!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45302928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档