我正在使用LiveID和Google提供程序將OpenID集成到我現有的應用程序中。在我的登錄頁面上,除了我已添加的「登錄Google」和「使用Microsoft登錄」按鈕的原始登錄字段外。在同一頁面中處理來自不同供應商的AuthenticationResult
我可以成功讀取上面都提供商AuthenticationResult數據,但我通過以下方式實現這個...
新登錄按鈕,我精心設計了一個返回URL來區分它們對用戶的回報:
Protected Sub btn_google_Click(sender As Object, e As EventArgs) Handles btn_google.Click
Dim client As New GoogleOpenIdClient
Dim u As New System.Uri("http://www.mytest.com/login.aspx?action=signin&provider=google")
client.RequestAuthentication(New HttpContextWrapper(HttpContext.Current), u)
End Sub
Protected Sub btn_live_Click(sender As Object, e As EventArgs) Handles btn_live.Click
Dim client As New MicrosoftClient("xyz", "12345")
Dim u As New System.Uri("http://www.mytest.com/login.aspx?action=signin&provider=microsoft")
client.RequestAuthentication(New HttpContextWrapper(HttpContext.Current), u)
End Sub
因此,當用戶被重定向回到login.aspx的,然後我有以下檢查來處理登錄功能:
If Not Page.IsPostBack Then
If Request.QueryString("action") IsNot Nothing AndAlso Request.QueryString("action").Trim = "signin" Then
If Request.QueryString("provider") IsNot Nothing AndAlso Request.QueryString("provider").Trim <> String.Empty Then
Select Case Request.QueryString("provider").Trim
Case "microsoft"
Dim client As New MicrosoftClient("xyz", "12345")
Dim u As New System.Uri("http://www.mytest.com/loginlive.aspx?action=signin&provider=microsoft")
Dim result As DotNetOpenAuth.AspNet.AuthenticationResult = client.VerifyAuthentication(New HttpContextWrapper(HttpContext.Current), u)
' remainder of logic removed
' ...
Case "google"
Dim client As New GoogleOpenIdClient
Dim result As DotNetOpenAuth.AspNet.AuthenticationResult = client.VerifyAuthentication(New HttpContextWrapper(HttpContext.Current))
' remainder of logic removed
' ...
End Select
End
End
End If
我的主要問題在於,這是處理AuthenticationResults的好方法嗎?或者,是否有更好/更安全/更聰明的方法來完成相同的目標?
感謝您的輸入。我很欣賞你的觀點,但有一些保留意見,即......我希望能夠自動登錄到我的系統,如果他們已經通過谷歌登錄這樣的鏈接,如www.mydomain.com/autologin。 aspx?provider = Google',以節省正常登錄頁面上額外按鈕的時間。此外,因爲像ConsumerKey這樣的字符串值只能使用一次,所以將它們移動到類中時,每次更新時都需要重新編譯。這是不錯的做法嗎?對不起,我的編程技能只有平均水平,所以我可能錯過了一些關鍵點。 – EvilDr 2013-06-04 07:53:32
1.直接登錄:您仍然可以通過上述模式實現此目的。使用登錄按鈕中使用的相同方法。在自動登錄的頁面加載中使用相同的方法。aspx 2.將Consumerkey移動到代碼中:消費者密鑰可以保存在配置文件或資源文件中,您可以直接將它們引用到您的代碼中。 我希望這會回答您的查詢。 – 2013-06-04 09:52:55
好吧。我努力看到的一點是*爲什麼*你的代碼比我的方法更好。再次指責我的經驗,只是一些指針會很棒! – EvilDr 2013-06-06 10:31:33