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