Adding External Logins to your ASP.NET application in Visual Studio 2013

pranav rastogi

The project templates showcase a way of logging in with external login providers, along with the normal way of logging in by creating a local account

This post highlights how you can turn on support for logging through these services in the ASP.NET project templates that shipped with Visual Studio 2013 Preview. To learn more about how authentication via external providers works, please read the following article. http://www.asp.net/web-api/overview/security/external-authentication-services#USING

Enable OAuth login using Facebook, Twitter

Steps to get keys for Facebook

  • Go to the Facebook developers site (log in if you’re not already logged in).
  • Choose the Create New App button, and then follow the prompts to name and create the new application.
  • In the section Select how your app will integrate with Facebook, choose the Website section.
  • Fill in the Site URL field with the URL of your site (for example, http://www.example.com). The Domain field is optional; you can use this to provide authentication for an entire domain (such as example.com).
    Note   If you are running a site on your local computer with a URL like http://localhost:12345 (where the number is a local port number), you can add this value to the Site URL field for testing your site. However, any time the port number of your local site changes, you will need to update the Site URL field of your application.
  • Choose the Save Changes button.
  • Choose the Apps tab again, and then view the start page for your application.
  • Copy the App ID and App Secret values for your application and paste them into a temporary text file. You will pass these values to the Facebook provider in your website code.
  • Exit the Facebook developer site.

Steps to get keys for Twitter

  • Browse to the Twitter developers site.
  • Choose the Create an App link and then log into the site.
  • On the Create an Application form, fill in the Name and Description fields.
  • In the WebSite field, enter the URL of your site (for example, http://www.example.com).
    Note   If you’re testing your site locally (using a URL like http://localhost:12345), Twitter might not accept the URL. However, you might be able to use the local loopback IP address (for example http://127.0.0.1:12345). This simplifies the process of testing your application locally. However, every time the port number of your local site changes, you’ll need to update the WebSite field of your application.
  • In the Callback URL field, enter a URL for the page in your website that you want users to return to after logging into Twitter. For example, to send users to the home page of the Starter Site (which will recognize their logged-in status), enter the same URL that you entered in the WebSite field.
  • Accept the terms and choose the Create your Twitter application button.
  • On the My Applications landing page, choose the application you created.
  • On the Details tab, scroll to the bottom and choose the Create My Access Token button.
  • On the Details tab, copy the Consumer Key and Consumer Secret values for your application and paste them into a temporary text file. You’ll pass these values to the Twitter provider in your website code.
  • Exit the Twitter site.

Steps to enable OAuth/OpenID support in

    • Create a new ASP.NET Application
    • Goto App_Start\Startup.Auth.cs and uncomment the following lines of code
//app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); 
//app.UseFacebookAuthentication( // appId: "", // appSecret: "");
//app.UseGoogleAuthentication();
Have fun integrating this into your application!!!

0 comments

Discussion is closed.

Feedback usabilla icon