ARTICLE

How to use Google OpenID Authentication using DotNetOpenAuth in ASP.NET

Posted by Raj Kumar Articles | ASP.NET Programming October 15, 2010
This article describes for you how to use the Google OpenID Authentication using DotNetOpenAuth in asp.net.
Reader Level:
Download Files:
 


This article describes for you how to use the Google OpenID Authentication using DotNetOpenAuth in ASP.Net.

Download the DotNetOpenAuth from here. First of all make a new website and add a reference to DotNetOpenAuth.dll.

Drag and drop a button on page.

<asp:Button ID="btnLoginToGoogle" Runat="server" Text="Google Login" OnCommand="OpenLogin_Click" 
                    CommandArgument="https://www.google.com/accounts/o8/id"
                Font-Bold="True" Font-Italic="True" Width="162px" /> 

using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty; 
 
protected void Page_Load(object sender, EventArgs e)
    {
        OpenIdRelyingParty OIDRP = new OpenIdRelyingParty();
        var str = OIDRP.GetResponse();
        if (str != null)
        {
            switch (str.Status)
            {
                case AuthenticationStatus.Authenticated:
                    NotLoggedIn.Visible = false;
                    Session["GoogleIdentifier"] = str.ClaimedIdentifier.ToString();
                    Response.Redirect("Home.aspx");
                    break;
                case AuthenticationStatus.Canceled:
                    lblMessage.Text = "Cancelled.";
                    break;
                case AuthenticationStatus.Failed:
                    lblMessage.Text = "Login Failed.";
                    break;
            }
        } 
    }

  protected void OpenLogin_Click(object src, CommandEventArgs e)
    {
        string str = e.CommandArgument.ToString();
        OpenIdRelyingParty openid = new OpenIdRelyingParty();
        var b = new UriBuilder(Request.Url) { Query = "" };
        var req = openid.CreateRequest(str, b.Uri, b.Uri);
        req.RedirectToProvider();
    } 

Now run the website.
1.JPG

Image 1

When you click on Login button.

2.JPG

Image2.

Insert google email and password.

3.JPG

Image3.
 

Login to add your contents and source code to this article
post comment
     

thank you! this is helpful for me http://phattrienweb.com

Posted by duc nguyen Nov 29, 2012

but when i login login and password then the status come login failed why my email id is sunnybindr.bhupender@gmail.com please help me

Posted by aaaaa aaaaa Nov 25, 2011

You can fetch openif attributes. But if you want to fetch profile and friends contact you may try SocialAuth.NET (http://code.google.com/p/socialauth-net/)

Posted by deepak aggarwal Jun 07, 2011

Hi this is Nice Article. Additionally i need to get the information from google account to my application.

Posted by chamika fernando Mar 11, 2011

My hosting windows server doesnot have the component "dotnetopenauth" installed with it.
Thus i am unable to use this dotnetopenauth OpenID features.

Can anyone suggest a windows server (asp classic) having dotnetopenauth component.

Posted by Rajeev K Dec 02, 2010
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter