使用MVC4 Internet模板项目复制我的问题的步骤:
所发生的情况是帐户A被注销,帐户B被登录。我希望有一些神奇的连接帐户A和帐户B,或者可能是一个例外。看来我得去做那部分了。到目前为止这是我的代码。它取代了帐户控制器中的ExternalLoginCallback。
[AllowAnonymous]
public ActionResult ExternalLoginCallback(string returnUrl)
{
AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
if (!result.IsSuccessful)
{
return RedirectToAction("ExternalLoginFailure");
}
// Need to do fancy logic in case of multiple accounts
if (User.Identity.IsAuthenticated)
{
// check for second blocking account
// NOTE : This is not a real method, need a real solution
var second = OAuthWebSecurity.GetUserIdFromProviderUserId(result.ProviderUserId);
if (second != WebSecurity.CurrentUserId)
{
// redirect to failure
// "This Login is used by another account... "
}如您所见,我被困在使用身份验证结果查找帐户上。是否有任何方法可以使用提供程序用户id来查找帐户?任何帮助或洞察力都会很好。
Hackish Fix我想出了一个快速而肮脏的修复方法。
public ActionResult ExternalLoginCallback(string returnUrl)
{
AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
if (!result.IsSuccessful)
{
return RedirectToAction("ExternalLoginFailure");
}
// Need to do fancy logic in case of multiple accounts
bool isBindingAction = User.Identity.IsAuthenticated;
if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false))
{
if (isBindingAction)
{
// tell the user that he has 2 accounts
return RedirectToAction("ExternalLoginSwitch", new {provider = result.Provider});
}
return RedirectToLocal(returnUrl);
}发布于 2013-05-09 17:02:45
我想如果你把登录电话换成:
public static string GetUserName(string providerName, string providerUserId);并检查此提供程序/providerUserId是否存在用户名,这样会更好。调用Login的唯一问题是,我相信这会将表单auth票证设置为错误的用户。
https://stackoverflow.com/questions/13962941
复制相似问题