2016-09-25 152 views
2

我一直在寻找一个解决方案,以在asp.net webform应用程序上使用用户Google帐户进行身份验证。asp.net webforms谷歌登录

我想要的是用户登录到他的谷歌帐户,并返回到我的webform应用程序显示名称,谷歌ID和电子邮件形式那里我会照顾其余的。

我试过http://dotnetopenauth.net/,Google .Net Api,但我从来没有找到一个工作的例子。

任何人都可以用正确的方向指向我的例子。 (C#或vb.net)

+1

嗨谢谢,但这是为MVC平台,而不是webforms :-( – ccr

回答

4

你有没有想过试一试Nemiro.OAuth?这很容易设置,支持asp.net和winforms,并且在线文档非常详细。

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); 
    } 
} 

您也可以按照this tutorial有关如何使用OAuth与Nemiro.OAuth库一步一步的指示。

+0

嗨Woodykiddy谢谢,但我找不到一个工作的例子用于谷歌:-(到目前为止,所有的例子已经与FB和Twitter。你有什么想法在哪里可以找到它 – ccr

+0

看看这个链接:https://github.com/alekseynemiro/nemiro.oauth.dll/blob/master/examples/GoogleDriveWebForms/Global.asax.cs。 – woodykiddy

+0

而这帮助文章:http://oauth.nemiro.net/?topic=html/aff36495-124c-a749-20ed-ce08ec915999.htm – woodykiddy