首页 > 解决方案 > 外部登录回调标志不正确的用户

问题描述

我对方法有一个奇怪的问题ExternalLoginCallback。我在日志中记录了一些信息,有趣Email的是正确的,但随后userId不正确,它属于之前登录的另一个用户。

即有些人UserA已登录系统,现在UserB想在another窗口中登录系统。我期望在新窗口UserB中登录并覆盖 cookie,所以如果我刷新第一个窗口它会显示UserB,但不知何故这不会发生,在第二个窗口中它会显示UserA

这是代码:

public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
    var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
    if (loginInfo == null)
    {
        return RedirectToAction("Login");
    }

    EventLogManager.LogWarning(loginInfo.Email);

    var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: true);
    switch (result)
    {
        case SignInStatus.Success:
            {
                var userId = SignInManager.AuthenticationManager.AuthenticationResponseGrant.Identity.GetUserId();

                EventLogManager.LogWarning(userId);
                ...

编辑

我认为我应该添加更多说明。有一些动作正在从第三方调用 - Shopify。看起来像:

public ActionResult Callback(string code, string hmac, string shop, string state, string timestamp)
{
    //this resolved the issue
    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
    Session["Workaround"] = 0;

    return new ChallengeResult("Shopify", Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = "/Product/Products" }), null, shop.Replace(".myshopify.com", ""));
}

标签: asp.netasp.net-mvcasp.net-identityshopify

解决方案


推荐阅读