Saturday, 1 June 2013

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


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 


  1. <span style="font-size: small;"> <asp:button commandargument="https://www.google.com/accounts/o8/id" id="btnGL" oncommand="btnGL_Click" runat="server" text="Login with Google">  
  2.   
  3. </asp:button></span>  
3.Open the Defaulf.aspx.cs Page and follow the procedure

4.First,Add the following Namespaces

  1. <span style="font-size: small;">using DotNetOpenAuth.OpenId;  
  2. using DotNetOpenAuth.OpenId.RelyingParty;  
  3.   
  4. </span>  

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

  1. <span style="font-size: small;">protected void btnGoogleLogin_Click(object sender, CommandEventArgs e)  
  2. {  
  3.     string GLUri = e.CommandArgument.ToString();  
  4.     OpenIdRelyingParty oid = new OpenIdRelyingParty();  
  5.     var Uribuilder = new UriBuilder(Request.Url) { Query = "" };  
  6.     var request = oid.CreateRequest(GLUri, Uribuilder.Uri, Uribuilder.Uri);  
  7.     request.RedirectToProvider();  
  8. }  
  9.   
  10. </span>  

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

  1. <span style="font-size: small;">protected void btnlogout_Click(object sender, EventArgs e)  
  2.     {  
  3.         Response.Redirect("http://accounts.google.com/logout");  
  4.     }  
  5.   
  6. </span>  

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


Read more: http://www.developerscode.com/2012/03/integration-of-third-party-loginslike.html#ixzz2UxcsZsZp


No comments:

Post a Comment