Reader Level:

Getting Started With Twitter Authentication in MVC 5

By Nimit Joshi on Sep 10, 2013
This article describes how to authenticate your MVC Application with Twitter.


This article explains Twitter Authentication for logging into your ASP.NET Web Application developed in MVC Project Templates. I will use Visual Studio 2013 Preview and MVC 5 in my ASP.NET Web Application. As I had described in my earlier article there are various login options with which you can login your MVC Application. Here, I am describing for you how to authenticate your MVC Application with Twitter.

In that context, you will see in the following image that there are three login options available in my application with which you can login:


As you can see, the following are the login options available in my MVC Application and I am using Twitter Authentication in my application:

  • Facebook
  • Google
  • Twitter

Twitter Authentication for MVC Application

So, let's start to authenticate the MVC Application with Twitter using the following sections:

  • Twitter App Creation
  • MVC App Creation

Twitter App Creation

Register yourself as a App Developer in Twitter.


Let's start to create an Twitter app with the following procedure.

Step 1: At first, create an app in Twitter as a developer by


Step 2: After login, create an app by clicking on "Create a New Application".


Step 3: Enter your unique App name and other necessary details.

Note: You need to enter the CallBack URL and choose Read and Write options to authorize . If you do not have any domain then you can enter an URL like 

Step 4: After accepting the license agreement, click on "Create your Twitter Application".


Step 5: Copy your Consumer Key and Consumer Secret values from the next window.


That's it. Now, move to the next session.

MVC App Creation

Let's start to create an MVC app with the following procedure.

Step 1: Create an ASP.NET MVC Application.


Step 2: In your Solution Explorer, open the "Startup.Auth.cs" file .


Step 3: As you can see in the following figure, my Twitter authentication is disabled:


Please un-comment it and paste your Consumer Key value and Consumer Secret value in the file as I mentioned below:


Save the changes.

Step 4: Debug your application and move to the Login link.


Step 5: Click on the Twitter Login option.


Step 6: After clicking the "Twitter" link, it'll automatically move to authenticate your app from Twitter.


Step 7: Click on "Authorize App" and it'll redirect you back to your application.


Step 8: Register yourself to associate with a Twitter account.


Step 9: Now, you will see your User Name in your MVC Application.


Step 10: Log yourself out.



So far this article will help you to login your MVC Application by Twitter. In this article I have provided all necessary information related to Twitter. So just apply it in your MVC Application.

Thanks for reading my article.

Nimit Joshi
Nimit Joshi

Nimit Joshi is a .NET techie, author and software developer. Nimit's background includes Master's in Computer Application and Bachelor's in Computer Application. Nimit is a one time Microsoft MVP and C# Corner MVP. Nimit... Read more