[英]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.