Skip to main content

Authentication using Social Networking portals(Facebook, Gmail, and Yahoo)

There are tons of sites, which offer sign on using the social networking site credentials (Facebook, gtalk, twitter and the list continues).It can be termed a “SINGLE SIGNON” and offers a lot of benefits compared to traditional database authentication approach.


However, not storing user credentials in the DB imposes an additional risk. How to track who all logged into the system. Now the question is, which approach to follow.

The best approach is to use inbuilt asp.net users for storing the logging info about user activities and using single signon technique for authentication.

This article will explore the approach and provide the details of implementation using some third party libraries and customizing it to the requirements. The Authentication will be done using the following networking portals
  • Yahoo 
  • Gmail
  • Facebook
  
Special thanks to my friend Sumit Khandelwal, for implementation of Facebook part (in fact he did it all!!)

Except Facebook, all other can be authenticates using the “dotnet OpenAuth” library

(Download it from here:)

Why to get authenticated with Social Networking Sites?

This works great and is beneficial both for users and the site owners.

Users: No need to register on every site and remember hell lot of usernames and passwords

Site Owners: No hassle for maintaining user database

There are a lot of options available in the market to get this functionality, however our requirement was to make it so independent that a few entries in config files and it’s ready to go.

Following components work together to achieve the functionality


• User Control

• Http Module

• USerEntity library

User Control contains the code for the authentication and the http module will aid in site navigation and authorization of the user’s request.

Figure  demonstrates how the Login control looks on GUI


The Jquery code brings up the appropriate login screen after clicking the links shown here.

To get the Facebook authentication, following are the pre-requisites


1. The portal (called application in Facebook lingo) needs to be registered with Facebook.

2. Step1 will provide APPKey and APPSecret that will be required by the UserControl in authentication.

3. For successful authentication, the user needs to share the information as depicted in the figure Auth-2.0




Similar to Facebook, while authenticating with Google or Yahoo ID the same kind of screens are encountered.



Once the sites are authorized to share the information, the concerned site will redirect to the application where the userControl traps the response and fills the appropriate USerEntity details and fills the SESSION ENTITY.


This SESSION ENTITY is used in every request to check if the user is authenticated.


The Web.config file needs to register the LoginModule (http module that we have developed) in http module section as shown in the figure below








Additionally, the entries shown in Figure Auth-6.0 need to be present in APPSettings section in Web.config.
Details of above settings are as follows:


• The LoginPage and LoginPageName should be same (customize it as per your portal).

APPKey and APPSecret, as obtained in step 2), have been named as FacebookApiKey and FacebookApiSecret respectively.

LandingPage is the Default Page of the application.

ApplicationRedirectUrl is the Facebook redirect URL(once the Facebook authenticates the user, it will redirect the user to this page)

Although I initially planned to releaset the source code with this article, however the source code is only available by sending a mail to me at pradeeppatel05@gmail.com.

Hope this was helpful,

Till next we connect……

Happy coding



Comments

  1. Thanks for great article

    I have asp.net website using native .net sql membership provider to
    authenticate website visitors. As moving this website to smartphone
    aplications, current implementation is not enough as it won't be
    possible authenticate existing users inside application.

    To solve this, I want to move users data to new DB and create separate
    oAuth authorization service which could be used by my current website
    and other clients (e.g. smartphone applications).
    Also I want to add authentication support through Facebook and Gmail
    both in website and in smartphone applications.

    As you have implemented something similar, could you give me some
    steps how this could be achieved the best way?

    Also I want to add support for users authentication using Facebook and Google.


    Best regards,
    Andrius

    ReplyDelete
  2. Initiallly I had implementation for the ASP.net membership provider, so that the user details would have been saved to database.

    Later I changed the code and currently it relies on token sent by the sites(facebook, gmail etc) and authenticates the user.

    The goodd part: it is simple http handler, so your existing auth system can be clubbed with this one(details are attached in a doc with the mail)

    At the application request begin, I chek the token for auth, if it's not present, the user is redirected to login page.

    One word of caution,the code has not been tested beyond simple Unit testing.

    I have sent the Code in reply to the mail that u sent along with the details in a separate doc.
    Hope this helps

    ReplyDelete

Post a Comment

Popular posts from this blog

Asp.Net 4.0: An Overview-Part-III

This is the last post in the series which will explore the following new features of ASP.Net 4.0  Performance Monitoring for Individual Applications in a Single Worker Process Web.config File Refactoring Permanently Redirecting a Page Expanding the Range of Allowable URLs Performance Monitoring for Individual Applications in a Single Worker Process It is a common practice to host multiple ASP.NET applications in a single worker process, In order to increase the number of Web sites that can be hosted on a single server. This practice results in difficulties for server administrators to identify an individual application that is experiencing problems. ASP.NET 4 introduces new resource-monitoring functionality introduced by the CLR. To enable this functionality, following XML configuration snippet is added to the aspnet.config configuration file.(This file is located in the directory where the .NET Framework is installed ) <?xml version="1.0" encoding="UTF-8...

Covariance and Contravariance-General Discussion

If you have just started the exploration of .Net Framework 4.0, two terms namely Covariance and Contravariance might have been heard. The concept that these terms encapsulate are used by most developer almost daily, however there has never been any botheration about the terminologies. Now, what actually these terms mean and how are these going to affect us as a developer, if we dive in to the details. The simple answer is it’s always good to know your tools before actually using them. Enough philosophy, let’s get to the business. Starting the discussion let me reiterate that in addition to Covariance and Contravariance, there is another terminology, Invariance. I’ll by start here by diving into the details of Invariance and then proceed further. Invariance: Invariance can be better understood by considering the types in .Net.>net has basically two type, value-types and reference-types. Value types (int, double etc) are invariant i.e. the types can’t be interchanged either ...

Advanced WCF

In this post, I am sharing the link of articles about  advanced topics in WCF. The List of articles is exhaustive and can serve as your repository for all WCF queries. Concurrency,Throttling & Callbacks  WCF Concurrency (Single, Multiple and Re entrant) and Throttling   WCF-Interop and BinarySecurityToken  WCF Callbacks  Creating Web Services From WSDL Link1 Link2 Link3 Link4 WCF-Security WCF over HTTPS   Transport Security(basic)/HTTPS UserNamePasswordValidator ServerCertificateValidationCallback 9 simple steps to enable X.509 certificates on WCF - CodeProject http://www.codeproject.com/KB/WCF/9StepsWCF.aspx?display=Print Message Security(Certificate)/PeerTrust Securing WCF Services with Certificates. - CodeProject http://www.codeproject.com/KB/WCF/wcf_certificates.aspx Message Security(Certificate)/ChainTrust How To Configure WCF Security Using Only X.509 Certificates - CodePr...