Thursday, March 22, 2012

Integration of Third party login's(like Google, Facebook, Yahoo, Twitter) in Asp.net

Few years back,I wrote an article on Facebook login Button integration in asp.net.Now i would like to explain the Integration of all type of Third party API's like Google,Facebook,Twitter,Yahoo and so on.. in Asp.net.
A Question raises immediately : Why we need to integrate these third party API's in our applications.why because for every New visitor or old visitor(those who are not registered in your site) it takes so much time to register in site.So many members (Including me !) have no time or interest to fill the complete registration and waiting for login information.its better to integrate Third party Login controls in application.it looks gr8 and save so much of time of the visitor because Almost Everybody Have Google or facebook or yahoo accounts.So by using their accounts they can easily access your site..
So Lets start the procedure of Integrating

First we will go with Google Login.


Google :


First We need to download
DotNetOpenAuth to use
Google Authetication.After downloading the DotNetOpenAuth zip file extract that file.

Next,Create a New Asp.net website and add the reference(dll) to your website which you downloaded before.


Procedure to add Reference to your application:


1. Right Click on the solution explorer and select add Reference


2. Next Click on the browse button and find the DotNetOpenAuth.dll file from zip file which you downloded before

and click ok..thats it..Now its successfully added to your application

Procedure for coding :


1.Open the Default.aspx page and drag and drop one button from Toolbox


2.Next add the following properties to that button


Id=
"btnGL"

CommandArgument="https://www.google.com/accounts/o8/id"


OnCommand=
"btnGL_Click"

Text=
"Login with Google"

So Finally it Look like this



 

3.Open the Defaulf.aspx.cs Page and follow the procedure

4.First,Add the following Namespaces

using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty;


5.Next,Add the following code in the button click event

protected void btnGoogleLogin_Click(object sender, CommandEventArgs e)
{
    string GLUri = e.CommandArgument.ToString();
    OpenIdRelyingParty oid = new OpenIdRelyingParty();
    var Uribuilder = new UriBuilder(Request.Url) { Query = "" };
    var request = oid.CreateRequest(GLUri, Uribuilder.Uri, Uribuilder.Uri);
    request.RedirectToProvider();
}


Thats it..Now run the page and click on the button .it will redirect to Google Login page

Next,Enter the Username and Password and accept the application by clicking the allow button

Once you have successfully logged in and accepted the application it will redirect to your custom page(Ex : Mainapge.aspx)

For this you need to create one more page that is MainPage.aspx

Next,Write One Message Like "You are successfully Logged in"

Next,Add one Text box in MainPage.aspx page and change the name as LogOut

Next,Write the following code for Logout button Click Event

protected void btnlogout_Click(object sender, EventArgs e)
    {
        Response.Redirect("http://accounts.google.com/logout");
    }


Thats it...I hope it will usefull to you

Next,Facebook integration

Facebook Login button integration in asp.net article i am already explained please check this post

Later,I will posts the articles on Twitter,Yahoo,OpenId

I hope this article is usefull to you..if you any queries pls just drop a comment...!!!

Labels: , , , , , ,

3 Comments:

At December 17, 2013 at 6:39 PM , Anonymous Anonymous said...

when I integrate Twitter and LinkedIn Button in my application same error occur that is error-401(Unauthorized) ......
plssss give me any solution.....

 
At December 17, 2013 at 10:25 PM , Blogger Developers Code said...

Hi

Did you changed the APP key in config file...? please check it . let me know if you have any issues

 
At September 30, 2014 at 5:52 PM , Anonymous Anonymous said...

Hi,
Can you please tell the procedure for yahoo login integration in asp.net

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home