MVC 4 oAuth With Facebook does not return email address

混江龙づ霸主 提交于 2019-12-07 16:39:21

问题


I am experimenting witht he MVC 4 oAuth that was released this month. Can anyone point me to where I can add eMail address so that I can store that with user properties?

I need to be able to send a welcome email but don't know where to start with the out of the box MVC 4 oAuth.

Ideally, after successful login, I want to receive the User Info from Facebook in my controller and drop it in a table so an offline process can send the welcome email.

Thanks, Victor


回答1:


In order for Facebook to return an e-mail you must specify it in the scope. For example with the JS SDK you would do something like....

return FB.login(function(response) {
    if (response.authResponse) {
      return window.location = '/auth/facebook/callback';
    }
  }, {scope: 'email,user_likes'}
);



回答2:


It is because Facebook allows its users to specify what data is shared with 3rd party authentication services, such as you website Victor. And by default, I believe the Email addresses (yes, there are multiple you can add to a facebook account) are not shared byd default. A user has to go in and explicitly share their email addresses with 3rd parties - something I don't think anyone ever uses.

The only "mandatory" shared data that Facebook forces shared is the FullName (e.g. "Eric Duncan"). Everything else is optional for the user to share.

For example, I have my Facebook setup to share only my birthdate, but not the birthyear. I also have my Facebook setup to share my interests but not my email.

Therefore, you have to code for what is guaranteed - the display name in Facebook's case (which is called the "UserName" in the MVC 4.0 OAuth). Everything else is not guaranteed.

What I do in my OAuth applications, including Facebook connect, is after a successful authentication with the 3rd party, on the callback url page (e.g. ExternalLoginConfirmation.cshtml in MVC 4.0), I will ask the user to enter their Display Name, email address, birthdate, etc. And make those fields required using standard data annotations on your custom view model.



来源:https://stackoverflow.com/questions/12117167/mvc-4-oauth-with-facebook-does-not-return-email-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!