Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

In want to retrieve user data to SignIn through Gmail or Yahoo id.
I am designing such a web application in which it has no own user registration.
User can use there existing Gmail or Yahoo id to SignIn in the web application.
I have required OAuth Consumer Key and OAuth Consumer Secret for both application.
I want C# code for user login through Gmail and Yahoo and retrieve login information of user like username , firstname and lastname.


I have used this code for login with google
add these namespace
C#
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty;


      protected void Page_Load(object sender, EventArgs e)
       {
          if (!IsPostBack)
        {
            OpenIdRelyingParty rp = new OpenIdRelyingParty();
            var r = rp.GetResponse();
            if (r != null)
            {
                switch (r.Status)
                {
                    case AuthenticationStatus.Authenticated:
                       // NotLoggedIn.Visible = false;
                        Session["GoogleIdentifier"] = r.ClaimedIdentifier.ToString();
                        //AttributeValues att = new AttributeValues();
                        //Response.Write(Session["GoogleIdentifier"]);

                        //Response.Redirect("Main.aspx"); //redirect to main page of your website
                        break;
                    case AuthenticationStatus.Canceled:
                        //lblAlertMsg.Text = "Cancelled.";
                        break;
                    case AuthenticationStatus.Failed:
                        //lblAlertMsg.Text = "Login Failed.";
                        break;
                }
            }
         }
     }

protected void imgbtnGoogle_Click(object sender, ImageClickEventArgs e)
    {
        string discoveryUri = "https://www.google.com/accounts/o8/id";
        OpenIdRelyingParty openid = new OpenIdRelyingParty();
        var b = new UriBuilder(Request.Url) { Query = "" };
        var req = openid.CreateRequest(discoveryUri, b.Uri, b.Uri);
        req.RedirectToProvider();
    }

This code helped me in Login with the Google.

But Now the problem is how to retrieve login information of user like username , firstname and lastname.

With Warm Regards,
Deepak Pandey
Posted
Updated 10-Oct-11 20:22pm
v5
Comments
kodharisridhar 26-Nov-11 8:32am    
i have a webpage in my website.if any one can login to my website using either gmail or yahoo account.here my requirement is i want c# code for openid to retrieve user information from the open servers of gmail and yahoo(firstname,lastname,date of birth).plz anyone help me..
my email:sri.auxano@gmail.com

 
Share this answer
 
v2
 
Share this answer
 
Comments
aryan2010 11-Oct-11 7:24am    
Hello Anuja,
Have you not checked that the link that you have provided is of my question.
I have posted the same question on CodeProject, C Sharp Corner and ASP.Net.
And I have checked all link but I am not able to find appropriate solution for my problem.

Thanks,
Deepak

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900