gpt4 book ai didi

node.js - passport-linkedin-oauth2 不返回电子邮件地址

转载 作者:搜寻专家 更新时间:2023-11-01 00:02:31 25 4
gpt4 key购买 nike

这是我的 console.log(profile);

{ 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' } }

这是我的路由代码:

 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);

这是 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);
}));

为什么我的电子邮件值未定义?当我使用 passport-linkedin 时它起作用了

最佳答案

根据readme , scope 选项必须在 Strategy 对象中设置。您在 passport.authenticate 中将其设置为被忽略。

要解决此问题,请将您的代码更改为:

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);
}));

关于node.js - passport-linkedin-oauth2 不返回电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19722344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com