Walkthrough: Login with Twitter Account in ASP.NET MVC 5 APP using ASP.NET Identity 2.0

ASP.NET Identity 2.0 simplifies task of social authentication in an ASP.NET MVC App at the great extent. There are lot to learn about ASP.NET Identity 2.0 and in further posts I will cover that. However In mean time if you are curious you can find the resources for ASP.NET Identity 2.0 here

To start with I created an ASP.NET MVC Application in Visual Studio 2013 y choosing MVC project template as follows:

clip_image002

Great, once the project is created next you need to configure Twitter for the application. To start with navigate to https://apps.twitter.com and select Create New App as shown below:

clip_image004

To create the Twitter application fill the form as follows. Off course you should provide Name, Description and Website information as of your application. Callback URL filed is worth discussing here, for development environment use 127.0.0.1 instead of localhost as the server for Callback URL. For any other server give fully qualified server name. To create the new Twitter application form can be filled as follows:

clip_image006

That’s it. Now click on API Keys and copy the API Key and API Secret, you will need them in the application.

 clip_image008

At the last step you need to open the project and browse to the App_Start folder. In this folder you will find a file Startup.Auth.cs. Open this file and uncomment the code app.UseTwitterAuthentication. You should also provide the consumerKey and consumerSecret key from Twitter here. (we created these keys in previous steps)

Startup.Auth.cs

clip_image010

This is it Press F5 to run the application. And click on Login, you should see the Twitter option in Use another Service to log in.

clip_image012

Click on the Twitter option and you will be asked to authorize the app.

clip_image014

Once authorization is done, you can register with the Twitter username.

clip_image016

Now you are logged in to the application using Twitter account. So as you see ASP.NET Identity 2.0 makes it super easy to work with social authentication in the ASP.NET MVC or the ASP.NET application.

In further posts, I will share more on ASP.NET Identity 2.0 learning. Happy Coding.

2 responses to “Walkthrough: Login with Twitter Account in ASP.NET MVC 5 APP using ASP.NET Identity 2.0”

  1. […] Walkthrough: Login with Twitter Account in ASP.NET MVC 5 APP using ASP.NET Identity 2.0 (Dhananjay Kumar) […]

  2. What is the difference between what you’ve done and what the author of this post has done? I’m trying to understand the high level concepts at play between these two approaches..
    http://magnusmartensson.com/mvc-application-using-owin-to-achieve-federated-authentication

    Thanks!

Leave a comment

Create a website or blog at WordPress.com