简体   繁体   English

passport-linkedin-oauth2没有返回电子邮件地址

[英]passport-linkedin-oauth2 not returning email address

Here is my console.log(profile); 这是我的console.log(个人资料);

{ provider: 'linkedin',
  id: 'LJitOAshpU',
  displayName: 'Monist BD',
  name: { familyName: 'BD', givenName: 'Monist' },
  emails: [ { value: undefined } ],
  _raw: '{\n  "firstName": "Monist",\n  "formattedName": "Monist BD",\n  "id": "
LJitOAshpU",\n  "lastName": "BD"\n}',
  _json:
   { firstName: 'Monist',
     formattedName: 'Monist BD',
     id: 'LJitOAshpU',
     lastName: 'BD' } }

here is my routing code: 这是我的路由代码:

 app.get('/auth/linkedin',passport.authenticate('linkedin', { scope: ['r_emailaddress', 'r_basicprofile', 'rw_nus'],state: 'DCEEFWF45453sdffef424' }));

app.get('/auth/linkedin/callback',passport.authenticate('linkedin', { failureRedirect: '/' }),users.authCallback);

here is passport.js config: 这是passport.js配置:

 passport.use(new LinkedInStrategy({
    clientID: config.linkedIn.clientID,
    clientSecret: config.linkedIn.clientSecret,
    callbackURL: config.linkedIn.callbackURL,
    profileFields: ['id', 'first-name', 'last-name', 'email-address','public-profile-url'],
    passReqToCallback: true
  },
  function(req,token, refreshToken, profile, done) {

    console.log(profile);
}));

Why am I getting undefined in email values? 为什么我在电子邮件值中未定义? It worked when I used passport-linkedin 当我使用passport-linkedin时它起作用了

According to the readme , the scope option must be set in the Strategy object. 根据自述文件 ,必须在Strategy对象中设置scope选项。 You are setting it in passport.authenticate where it is being ignored. 您将在passport.authenticate中将其设置为忽略它。

To fix this change your code to: 要解决此问题,请将您的代码更改为

app.get('/auth/linkedin',passport.authenticate('linkedin', { state: 'DCEEFWF45453sdffef424' }));

app.get('/auth/linkedin/callback',passport.authenticate('linkedin', { failureRedirect: '/' }),users.authCallback);

... ...

passport.use(new LinkedInStrategy({
    clientID: config.linkedIn.clientID,
    clientSecret: config.linkedIn.clientSecret,
    callbackURL: config.linkedIn.callbackURL,
    scope: ['r_emailaddress', 'r_basicprofile', 'rw_nus'],
    profileFields: ['id', 'first-name', 'last-name', 'email-address','public-profile-url'],
    passReqToCallback: true
  },
  function(req,token, refreshToken, profile, done) {

    console.log(profile);
}));

you need to give permission in your LinkedIn APP like below. 你需要在你的LinkedIn APP中给予许可,如下所示。

IN this image you can see i have given many permission like in this emailaddress also check so i will get that 在这张图片中你可以看到我已经给了很多许可,比如在这个电子邮件地址也检查所以我会得到它

在这张图片中你可以看到我已经给了很多许可,比如在这个电子邮件地址也检查所以我会得到它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ExpressJS和通行证-linkedin-oauth2无法验证 - ExpressJS and passport-linkedin-oauth2 cannot authenticate 使用通行证-linkedin-oauth2获取个人资料信息 - getting profile information using passport-linkedin-oauth2 Linkedin Passport Oauth失败重定向 - Linkedin Passport Oauth failureRedirect Google oauth 不返回电子邮件护照身份验证 - Google oauth not returning email passport authentication 使用OAuth 1.0a API向LinkedIn进行身份验证的护照策略在保存用户时返回未定义的电子邮件 - Passport strategy for authenticating with LinkedIn using the OAuth 1.0a API return undefined email on save User 使用OAuth 2.0a API向LinkedIn进行身份验证的护照策略在保存用户时返回未定义的电子邮件 - Passport strategy for authenticating with LinkedIn using the OAuth 2.0a API return undefined email on save User 使用password.js显示Linkedin用户的电子邮件地址 - Displaying email address of Linkedin User using passportjs 护照facebook身份验证不提供电子邮件地址 - passport facebook authentication is not providing email address facebook节点护照未返回电子邮件地址 - facebook node passport does not return email address 护照:允许注册姓名和电子邮件地址? (地方战略) - Passport: Allow sign up with name and email address? (Local Strategy)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM