使用facebook登录按钮时遇到问题。我目前正在使用OAuthWebSecurity.RegisterFacebookClient()身份验证过程但突然停止正常工作。
当我点击登录按钮时,我可以进入Facebook进入我的帐户(如果需要),并且在回调和then this error pops up上失败。
我的ExternalLoginCallback代码就是这个
AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { returnUrl = returnUrl }));
if (!result.IsSuccessful)
{
return RedirectToAction("ExternalLoginFailure");
}
string fbId = "";
string first_name = "";
string last_name = "";
string email = "";
if (result.ExtraData.Keys.Contains("accesstoken"))
{
var client = new FacebookClient(result.ExtraData["accesstoken"]);
dynamic me = client.Get("me", new { fields = "email" });
Session["facebooktoken"] = result.ExtraData["accesstoken"];
fbId = result.ExtraData["id"];
email = me.email;
}
else
{
String[] full_name = result.ExtraData["name"].ToString().Split(' ');
if (full_name[0] != null)
first_name = full_name[0];
if (full_name[1] != null)
last_name = full_name[1];
}
if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false))
{
SetAuthCookie(email);
SetEncryptedCookie(Configuration.UserCookie, email, Configuration.CookieLifeTime);
if (Request.Cookies["isFromCheckOut"] != null)
{
SetCookie("isFromCheckOut", false, false);
RemoveCookie("isFromCheckOut");
return RedirectToAction("Cart", "Store");
}
if (returnUrl != null)
{
return Redirect(returnUrl);
}
return RedirectToAction("Index", "Store");
}
if (User.Identity.IsAuthenticated)
{
// If the current user is logged in add the new account
OAuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, email);
SetAuthCookie(email);
SetEncryptedCookie(Configuration.UserCookie, email, Configuration.CookieLifeTime);
UserService.LastSeenUpdate(email);
if (Request.Cookies["isFromCheckOut"] != null)
{
SetCookie("isFromCheckOut", false, false);
RemoveCookie("isFromCheckOut");
return RedirectToAction("Cart", "Store");
}
return RedirectToAction("Index", "Store");
}
else
{
// User is new, ask for their desired membership name
string loginData = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId);
ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(result.Provider).DisplayName;
ViewBag.ReturnUrl = returnUrl;
return View("ExternalLoginConfirmation", new RegisterExternalLoginModel
{
Id = fbId,
UserName = email,
ExternalLoginData = loginData,
});
}
此错误仅在我在生产时测试时显示,而不是在调试时显示。