2013-11-01 40 views
3

這裏是我的console.log(profile);passport-linkedin-oauth2不返回電子郵件地址

{ 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

回答

0

時,它就起作用了,您需要在您的LinkedIn APP中授予權限,如下所示。

在此圖像中,你可以看到我已經給許多權限想在這個EMAILADDRESS同時檢查,所以我會得到

IN this image you can see i have given many permission like in this emailaddress also check so i will get that

0

按照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); 
})); 
相關問題