How to make possible to authenticate with some of social network ID (such as Google authentication, facebook login and LinkedIn) to your ASP.NET web form application?
Use Visual Studio 2013 built in functionality
One possibility is to use Visual Studio 2013 built in functionality inside ASP .NET Web Form Site template (it is not only template with built in authentication). You need to configure project to work with social networks logins.
To learn more how to configure Visual Studio 2013 to work with external social sites visit: External authentication services c# and Logging In Using External Sites in an ASP.NET Web Pages.
- Why I do not like VS built in authentication inside templates
- I find it difficult to understand and change to my application needs
- do not know what happens under the hood, for example in ASP .NET Web Form Site template, attached database is created with tables for storing data about users, I do not know when this database is created and do not know how methods exactly work
- connecting to external social networks is relatively new and have bugs
- so if you want to use proposed model go with it, but if you have some specific ideas maybe it is good idea to start from scratch
How Asp.NET logging communicate with Facebook
This is simplified and User agent is not taken into account
- ASP.NET site sends facebook Application ID and URL of ASP.NET application to facebook
- user is redirected to facebook site where he need to login with his facebook login
- facebook authorization page is redirected to ASP.NET authorization page, inside URL is "code" query parameter
- ASP.NET read code parameter and send web request to facebook with ApplicationID, Application secret and code which is received two steps before
- ASP.NET get response from facebook site, now ASP.NET have a token
- Now ASP.NET can send request to facebook site with token to get data about user
There is a code for authentication to your ASP.NET application with Facebook login.
- Facebook button is first clicked
- when facebook page redirect back to ASP.NET page GetAuthToken method is called and then GetUserInfo method is called
- inside GetUserInfo method ASP.NET get id of facebook user and user facebook name
- you must create facebook application to get APP_KEY and APP_SECRET, find more about it here
Simplest way to authenticate using external social network logins
Some good people make various classes to make easier to login using Facebook, Google authenticate, LinkedIn and others. Those classes hides complexity of communicating with LogIn services.
I find ASPSnippets very handy and easy for use. There is simple step by step tutorial for:
- Autheticate User's login account using FaceBook API in ASP.Net Website
- LinkedIn login integration in ASP.NET
Let's try explain code in few lines:
- when btn_FacebookLogin is clicked, FaceBookConnect.Authorize method is called, it redirect user to facebook login page
- if user successfully login to facebook, he is redirected back to ASP.NET application Login page
- then inside Page_Load it is recognized ASP.NET page is loaded after facebook login page
- FaceBookConnect.Fetch method is called and ASP.NET application can get data about user
- with LinkedIn authentication is similar process
Be careful with Google OpenId identifier because it change if you change domain.