Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net webforms google login

I have been searching the net for a solution to use a users google account for authentications on a asp.net webform application.

All I want is that the user login to his google account and return to my webform application with display name, google ID and Email form there I will take care of the rest.

I have tried http://dotnetopenauth.net/, Google .Net Api but I never found a working example.

Can anybody point me in the right direction with a example that works. (C# or vb.net)

like image 772
ccr Avatar asked Sep 25 '16 17:09

ccr


1 Answers

Have you thought about giving Nemiro.OAuth a try? It's easy to set up, supports asp.net and winforms, and the online documentation is very detailed.

protected void RedirectToLogin_Click(object sender, EventArgs e)
{
  // gets a provider name from the data-provider
  string provider = ((LinkButton)sender).Attributes["data-provider"];
  // build the return address
  string returnUrl = new Uri(Request.Url, "ExternalLoginResult.aspx").AbsoluteUri;
  // redirect user into external site for authorization
  OAuthWeb.RedirectToAuthorization(provider, returnUrl);
}

protected void Page_Load(object sender, EventArgs e)
{
   var result = OAuthWeb.VerifyAuthorization();

   Response.Write(String.Format("Provider: {0}<br />", result.ProviderName));

   if (result.IsSuccessfully)
   {
      // successfully
      var user = result.UserInfo;
      Response.Write(String.Format("User ID:  {0}<br />", user.UserId));
      Response.Write(String.Format("Name:     {0}<br />", user.DisplayName));
      Response.Write(String.Format("Email:    {0}", user.Email));
    }
    else
    {
      // error
      Response.Write(result.ErrorInfo.Message);
    }
 }

You can also follow this tutorial for a step-by-step instruction on how to use OAuth with Nemiro.OAuth library.

like image 170
woodykiddy Avatar answered Nov 18 '22 11:11

woodykiddy