Social media authentication is the one of the major authentication technique in modern websites. Most of the visitors to our website would not like to register on our website. However, they will use their existing social media account to create an account in our website. In this article I will explain the Facebook authentication in ASP.NET MVC.
How to integrate Facebook Authentication in ASP.NET MVC ?
First open the visual studio and create an ASP.NET MVC application . Here I am using Windows Azure to deploy my application. If you are not familiar with Azure deployment, then please read this article Hosting ASP.NET in Azure
After Azure deployment, go to https://developers.facebook.com/apps/?action=create and click on add a new app button .
Once we click on add a new app, it will show a pop up and we need to select the type (iOS , Android , Facebook canvas, website) of app. Choose website from here.
Enter the website name and select category (Education , Entertainment etc)
Then enter your website URL and click on next button. Now you have created the website on Facebook. Scroll down the page, then you can see the dashboard URL there.
Click on dashboard URL, then you will get the following screen with the App ID, App Version and App secret. When we click on the show button on App secret, it will ask your Facebook password. After entering the correct Facebook password you can see your App Secret.
Go to your website’s (which is published in Azure) login page . On the right side you can see a section for other login.
Go to Startup.Auth.cs class and ether following code inside ConfigureAuth method.
app.UseFacebookAuthentication( appId: "875923389195611", appSecret: "<Enter your app secret here>");
Publish your app in to Azure. Then check the login page. You can see a Facebook button on right side.
Click on the Facebook button. It will redirect to Facebook.com.
If you are already logged in, It would not ask the login credentials again. You will get the preceding screen and click Okay . Now the user is authentic and it will redirect to your website.