4
Answers

Retrieve user data from gmail and yahoo login

Photo of Deepak Pandey

Deepak Pandey

13y
6.8k
1
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
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

Answers (4)