ASP.NET Identity with Facebook (out of the box)

The following is a walk through of how to deal with authentication using Identity Providers mainly Facebook.

Open https://developers.facebook.com/

Add a New App
Add a New App

Click “Add a New App”

 

Add a New App
Add a New App

Click “WWW”

Create New Facebook App ID
Create New Facebook App ID

Click “Create New Facebook App ID”

Create New app ID/Details
Create New app ID/Details

Select Category and click “Create App ID”

Go to Visual studio 2013

New VS2013 Project
New VS2013 Project

Create new Project name it and select “ASP.NET Web application”

New VS2013 Project Selection
New VS2013 Project Selection

Set  Authentication to “Individual User Accounts” and Click Ok

Build and run your project and copy the local URL go to Facebook Development in your browser where you left off

Website URL
Website URL

Paste the url in “Site URL” and “Mobile site URL” in this case localhost:61617 and click next

 

Application DashBoard
Application DashBoard

Refresh the page click Show button near App Secret

 

Authentication
Authentication

Enter your Facebook Password

Go to visual studio

Startup Authentication
Startup Authentication

Navigate in solution explorer to App_start/start.auth.cs

Facebook App ID and App Secret
Facebook App ID and App Secret

Scroll down Facebook boilerplate authentication code. Paste App Id and App Secret and uncomment the three lines

Rebuild the Project and run

Log In
Log In

Once it opens in the browser click Login

Facebook Login
Facebook Login

On the left of the page there should be a Facebook button click it

Application Authorization
Application Authorization

Click okay to authorize

Associate E-mail address with account
Associate E-mail address with account

Enter E-mail address to associate with that Facebook account on your application

Display E-mail after authentication
Display E-mail after authentication

The e-mail will show every time the user is logged in.

That is how to authenticate a user using Facebook as an Identity Provider. Out of the box.

 

What’s else can we do with Facebook?

There a lot of things one can do with Facebook by using Facebook SDK the user can authorize your Web Site to access several Scopes. At the least one could skip the last two steps by requesting access to the e-mail and use that programmatically without the user having to type it.

The following is how to incorporate Facebook SDK in your project.

NuGet Manager
NuGet Manager
Facebook SDK
Facebook SDK

More info at http://www.nuget.org/packages/Facebook/7.0.5-beta

and https://developers.facebook.com/docs/graph-api

The guideline is do not ask for more data than your application really need, because once you lose trust of the users, your web site is dead.