Twitter Authentication in MVC5

Rama Sagar
Posted by in ASP.NET MVC category on for Beginner level | Points: 250 | Views : 3864 red flag

There are Various Types of Authentication which we can use to login in our Asp.net Applications...This Article Provides a brief Explanation on Twitter Authentication in Asp.net MVC5 Application

Introduction


In this Article we will learn how to Authenticate  MVC Application with Twitter Credentials...you can check my Previous article on Facebook Authentication here...


Let's start to authenticate the MVC Application with Twitter :


  • Step 1  Register yourself as a App Developer in Twitter by opening https://dev.twitter.com/apps from your Browser and sign in with your Credentials...
        Note:- Your Email must be confirmed with twitter before you sign in 
  • Step 2  Now Click on Create a new Application as shown Below...
       

  •  Step 3  Enter all the Necessary Details you can provide a call back URl as www.dummy.com and click on Create your Twitter Application
  • Step 4 Copy the consumer key and consumer Secret Values as shown below
        


Now lets Create a MVC Application 

  • Step 1 Create an Asp.net  MVC Application 
  • Step 2 After Creation you will find Startup.Auth.cs class file in App_Start Folder 

Using the code


  • Step 3 Open Startup.Auth class file Here you can watch  UseTwitterAuthentication code is Commented..
  • Step 4 uncomment the Code and Provide the Consumer key and consumer Secret key which we had copied Earlier
using Owin;

namespace MVCStudents
{
    public partial class Startup
    {
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            // Enable the application to use a cookie to store information for the signed in user
            // and to use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseSignInCookies();

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            app.UseTwitterAuthentication(
               consumerKey: "",
               consumerSecret: "");

            //app.UseFacebookAuthentication(
            //   appId: "",
            //   appSecret: "");

            //app.UseGoogleAuthentication();
        }
    }
}

  • Step 5 Debug the Application and click on Login we will find the Twitter Button as shown below


  •  Step 6 Click on the Twitter Button and you will be ask to Authorize app ..Click on Authorize app

 

 

  •  Step 7 it will Redirect to our Application  as shown 
  

  •     Step 8  Now register to Associate with Twitter Account 
   

Conclusion


This Article Help us to Authenticate our MVC Application with Twitter 

Reference

Write reference, http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on

Page copy protected against web site content infringement by Copyscape

About the Author

Rama Sagar
Full Name: RamaSagar Pulidindi
Member Level: Silver
Member Status: Member,MVP
Member Since: 12/30/2012 1:51:40 AM
Country: India
ramasagar
http://www.ramasagar.com
A Software Profesional working in Microsoft .NET technologies since year 2008, and I work for Dake ACE. I am passionate about .NET technology and love to contribute to the .NET community at Dot Net Funda

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)