我有一個已經住了一段時間,現在Facebook的連接(FBML)的Web應用程序Facebook連接 - 單點登錄導致無限循環:(
一切工作正常,但用戶要報告有關單一議題登錄(我已經在他們的計算機上看到了這個問題,但一直沒有能夠在本地複製)
有了FBC,您可以掛接一個「事件」來自動確定用戶是否已通過Facebook身份驗證。
這是通過這個來實現的:
FB.Connect.ifUserConnected(onUserConnected, null);
onUserConnected函數然後可以做任何它需要嘗試單一登錄。
對我而言,我所做的是向服務器發送一個AJAX調用,以查看用戶是否有活動網站帳戶(基於Facebook詳細信息 - 用戶標識,我在系統中存儲它們時連接)。
如果他們這樣做,我會顯示一個jQuery模式對話框(「與Facebook連接」)並執行window.location.reload()。
然後服務器啓動並執行單一登錄。此代碼的每一頁上執行:
public static void SingleSignOn(string redirectUrl)
{
if (!HttpContext.Current.Request.IsAuthenticated) // If User is not logged in
{
// Does this user have an Account?
if (ActiveFacebookUser != null)
{
// Get the user.
var saUser = tblUserInfo.GetUserByUserId(ActiveFacebookUser.IdUserInfo);
if (saUser != null)
{
// Get the Membership user.
MembershipUser membershipUser = Membership.GetUser(saUser.UserID);
if (membershipUser != null && membershipUser.IsApproved)
{
// Log Them Automically.
FormsAuthentication.SetAuthCookie(membershipUser.UserName, true);
// At this point, the Forms Authentication Cookie is set in the HTTP Response Stream.
// But the current HTTP Context (IsAuthenticated) will read HTTP Request Cookies (which wont have the new cookie set).
// Therefore we need to terminate the execution of this current HTTP Request and refresh the page to reload the cookies.
HttpContext.Current.Response.Redirect(
!string.IsNullOrEmpty(redirectUrl) ? redirectUrl : HttpContext.Current.Request.RawUrl,
true);
}
else
{
HandleUnregisteredFacebookUser();
}
}
else
{
HandleUnregisteredFacebookUser();
}
}
else
{
HandleUnregisteredFacebookUser();
}
}
}
我從來沒有經歷過這個問題,但用戶要報告「無限」循環,其中的對話框得到顯示,窗口被刷新,顯示對話框,窗口刷新等。
基本上,我的AJAX調用是說用戶存在,但我的單一登錄不是。
這是很難相信,因爲代碼很相似:
這是AJAX Web服務:
if (!HttpContext.Current.Request.IsAuthenticated) // If user is not yet authenticated
{
if (FacebookConnect.Authentication.IsConnected) // If user is authenticated to Facebook
{
long fbId;
Int64.TryParse(Authentication.UserId, out fbId);
if (fbId > 0)
{
tblFacebook activeUser = tblFacebook.Load(facebookUniqueId: fbId);
if (activeUser != null && activeUser.IsActive) // If user has an active account
{
return true;
}
}
}
}
因此,如果這個WS的反應是「真」,我做一個窗口.location.reload();
所以我不知道問題是什麼(因爲我不能複製),聽起來像單點登錄不正確地添加窗體身份驗證cookie到響應流或Response.Redirect(Request.RawUrl)不正確地重新加載cookie。
其他人如何處理?
這是應該發生的事情:
- 用戶登錄到Facebook的(在Facebook上本身)
- 用戶來到我的網站(先前已授權)
- 我的網站的FBID與比較FBID在我的DB,並簽署他們。
我的網站是一個ASP.NET 4.0 Web窗體應用程序,使用「舊」Facebook連接JavaScript API(FeatureLoader.js)和窗體身份驗證。
我唯一能想到的AJAX UpdatePanel是AJAX調用/ window.reload的其他解決方案。
任何人都可以幫我嗎?
編輯
而且,我知道我還可以使用'reloadIfSessionStateChanged':true
以進行重裝(其停止無限循環),但這個問題是我不能表現出我的漂亮花哨的對話框。