2013-09-29 74 views
0

這已被問了很多次,但它似乎沒有已知的解決辦法,所以我發佈這個問題,希望有人確實有一個解決它的辦法。Facebook OAuth2不提供用戶電子郵件

我正在使用NodeJS,PassportJS-Facebook。

app.get("/auth/facebook", 
      passport.authenticate("facebook", { 
       scope : [ "email" ] 
      }), 
      function (req, res) { 
      }); 

起初我以爲這是一個PassportJS問題,但我當然取消了這個選項。
我使用顯然是Facebook的用戶帳戶指出:

This app needs: 
Your basic info 
Your email address ([email protected]) 

一些鏈接到這個已知的問題(還沒有解決!): https://developers.facebook.com/bugs/298946933534016 https://developers.facebook.com/bugs/429653750464521 https://developers.facebook.com/bugs/482815835078469

那麼,你使用Facebook的OAuth服務?如果是這樣,你是否收到用戶的電子郵件?怎麼樣? 「直」的方式?解決方法?

回答

6

passportjs中的Facebook策略,期望在選項中有profileFields字段。嘗試在選項中傳遞「電子郵件」。

strategyOptions.profileFields = ['emails', 'first_name', 'last_name'];

或者,您可以覆蓋optionsprofileUrl併發送:

Facebook將會忽略你沒有權限(如電子郵件)領域。

這應該在這裏:

passport.use(new FacebookStrategy({ 
    clientID: FACEBOOK_APP_ID, 
    clientSecret: FACEBOOK_APP_SECRET, 
    callbackURL: "http://localhost:3000/auth/facebook/callback", 
    profileUrl: " ..... ", 
    //or 
    profileFields: [ ... ]; 
    }, 
    function(accessToken, refreshToken, profile, done) { 
    // asynchronous verification, for effect... 
    process.nextTick(function() { 

     // To keep the example simple, the user's Facebook profile is returned to 
     // represent the logged-in user. In a typical application, you would want 
     // to associate the Facebook account with a user record in your database, 
     // and return that user instead. 
     return done(null, profile); 
    }); 
    } 
)); 

```

+1

Not working,have already have:'profileFields:[「id」,「name」,「first_name」,「last_name」,「link」,「username」,「gender」,「locale」,「age_range」, 「displayName」,「photos」,「email」]' – Poni

+0

覆蓋profileUrl選項看起來像是一個嚴重的黑客攻擊,這也意味着Passport本身存在錯誤。 – Poni

+1

我確認使用profileUrl工作,它確實給了我電子郵件。我想我會在Passport-Facebook項目中打開一個錯誤。謝謝Eugenio! – Poni

0

您必須提供領域 '範圍' 中設置對象:

new FacebookStrategy({ 
    clientID: FACEBOOK_APP_ID, 
    clientSecret: FACEBOOK_APP_SECRET, 
    callbackURL: "http://localhost:3000/auth/facebook/callback", 
    profileUrl: " ..... ", 
    scope: "email", 
    //or 
    profileFields: [ ... ]; 
    } 

嘗試尋找來源。

+0

沒有奏效,也沒有幫助 –

相關問題