2016-09-25 150 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