locked
Retrieve user data from gmail and yahoo login RRS feed

  • Question

  • User1223035165 posted

    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:
                               Session["GoogleIdentifier"] = r.ClaimedIdentifier.ToString();
                              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

    Tuesday, October 11, 2011 12:20 AM

All replies

  • User619554136 posted

    Access Gmail InBox

    You can access Gmail InBox using Google Mail API.

    Gmail API

    Documentation

    .NET Client Library Developer's Guide

    Gmail IMAP and SMTP using OAuth - Overview

    Authentication and Authorization in the Google Data Protocol

    Registration

    I do not think so Google exposed API to create Mail Ids programatically.
    As per official documentation Google Mail API only helpful to access Inbox

    Tuesday, October 11, 2011 12:59 AM
  • User-935979976 posted
    protected void Page_Load(object sender, EventArgs e)
            {
    
                openIdAuth();
            }
    
            #region "openId"
            protected void openIdAuth()
            {
                OpenIdRelyingParty rp = new OpenIdRelyingParty();
                var response = rp.GetResponse();
                if (response != null)
                {
                    switch (response.Status)
                    {
                        case AuthenticationStatus.Authenticated:
                        //    NotLoggedIn.Visible = false;
                            //Response.Redirect("~/Default.aspx"); //redirect to main page of your website
                            var fetchResponse = response.GetExtension<FetchResponse>();
                            Session["FetchResponse"] = fetchResponse;
                            var response2 = Session["FetchResponse"] as FetchResponse;
                            // Use FormsAuthentication to tell ASP.NET that the user is now logged in,
                            // with the OpenID Claimed Identifier as their username.
                            string uname = response2.GetAttributeValue(WellKnownAttributes.Name.First) ?? "Guest";
                            FormsAuthentication.RedirectFromLoginPage(uname, false);   //(response.ClaimedIdentifier, false);
                            break;                        
                        case AuthenticationStatus.Canceled:
                        //    lblAlertMsg.Text = "Cancelled.";
                            break;
                        case AuthenticationStatus.Failed:
                        //    lblAlertMsg.Text = "Login Failed.";
                            break;
                    }
                }
            }
    
            protected void OpenLogin_Click(object src, CommandEventArgs e)
            {
                       string discoveryUri = e.CommandArgument.ToString();
                       OpenIdRelyingParty openid = new OpenIdRelyingParty();
                       var b = new UriBuilder(Request.Url) { Query = "" };
                  //var req = openid.CreateRequest(discoveryUri, b.Uri, b.Uri);
                       var req = openid.CreateRequest(discoveryUri);
    
                       // This is where you would add any OpenID extensions you wanted
                       // to include in the authentication request. In this case, we are making use of OpenID Attribute Exchange 1.0
                       // to fetch additional data fields from the OpenID Provider
                       var fetchRequest = new FetchRequest();
                       fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
                       fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.First);
                       fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.Last);
                       fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.HomeAddress.Country);
                       req.AddExtension(fetchRequest);
    
                       req.RedirectToProvider();
            }
    
            #endregion "openId"
    
    

    use theese functions to get the details

    use namespaces:

    using DotNetOpenAuth.OpenId;
    using DotNetOpenAuth.OpenId.RelyingParty;
    using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
    using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
    Friday, December 2, 2011 8:36 AM
  • User1526291375 posted

    Except the Email, FirstName, LastName & Country, Can you get the other details like Phone Number, PostalCode, HomeAddress etc.?

    Tuesday, April 10, 2012 10:36 AM