Your official information source from the .NET Web Development and Tools group at Microsoft.
When you create a New ASP.NET Project in VS 2013 and choose Individual Accounts, the template shows how you can login with Social providers such as Microsoft Account, Facebook, Google and Twitter. When you login with these Social Providers such as Facebook, you can request more information about the user such as the User’s picture, friends etc. and if the user allows your app to access this data then you can get this information and provide a rich experience in your site.
In the following post I am going to show you how you can request more data (or scopes) when a user logs in via Facebook provider. This post assumes that you have enabled Facebook login and are familiar with the basic walkthrough of Facebook Login. You can visit http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on to see a basic walkthrough on how to enable Facebook Login in the template.
[Update]: You can find the completed sample at https://github.com/rustd/FBLogin
Add a link in _LoginPartial.cshtml to display pictures of all friends
This stores the FacebookAccessToken as a User Claim in the ASP.NET Identity database
Conclusion This was an easy way to extend the Social providers and get more information about the logged in user so you can provide a rich experience for the web site users. You can do this with the other Social Providers as well. If you have any questions, please visit the asp.net/forums or reach me via twitter (@rustd)
This was an easy way to extend the Social providers and get more information about the logged in user so you can provide a rich experience for the web site users. You can do this with the other Social Providers as well. If you have any questions, please visit the asp.net/forums or reach me via twitter (@rustd)
Interesting Finds: October 18, 2013
ClaimsIdentity on the controller never has the claims generated from within OnAuthenticated.
Same issue as NP. Claims data seems to get lost somewhere along the way and is not available in the controller.
Hi, I have fixed some issues with the sample and I have updated the steps.
Great example, thanks! What about other providers? E.g. to get email (and maybe first/last name) from Facebook, Twitter, Microsoft, and Google?
How do we do this:
OnAuthenticated = async context =>
OK I have managed to convert all of this to VB except the last part with the new view (facebookinfo).
Except I am new to MVC also so have no idea what is going on with that code, and therefore have no idea how to convert it to VB. Any clues anyone?
Never mind, done it, if anybody wants this code in VB let me know...
Would be nice if Microsoft themselves would provide some support for this stuff in VB AND Web Forms.
Wasted two days on getting this converted..
Question whats the app meaning?
At ExternalLoginCallback beginning: var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
my result type is Microsoft.AspNet.Identity.Owin.ExternalLoginInfo which only contains a fixed DefaultUserName and the Login property. How do I get email address and other info (like full name) from loginInfo? There isn't any Email or other properties.
I think the e-mail address for all of the social logins should be returned. There's really no other way to merge identities. If someone logs into FB once, then logs in with Twitter, we should be able to know they first logged in with FB (if those accounts use the same e-mail). Same for GPlus and MS and Open.
It's fine to have this extra coding for getting app-specific information like 'friends', but basic user information should automatically be requested and placed into the loginInfo response.
I totally agree with ChicagoDave about the email.
How to to this with GoogleAuthenticationOptions? That class does not have the x.Scope() property!
2 ChicagoDave & woot : it's not that simple re. retrieving email. The default MVC5 code returns email for Google only! The code above helps you with Facebook email. Similar you can do with Microsoft. But as for Twitter - no way. I'd love if someone share the code how to do it.
Hello thx a lot; but i have the same issue as Péter Novák.
loginInfo only contains DefaultUserName and Login as properties.
You have any ideas ? I'm pretty stuck with it right now.