title: External login callback signs incorrect user
body: <p>I have a strange problem with <code>ExternalLoginCallback</code> method. I am logging some information in the log and what is interesting <code>Email</code> is correct, but then <code>userId</code> is incorrect and it belongs to another user who was logged previously.</p>
  
  <p>I.e. some <code>UserA</code> is logged into the system and now <code>UserB</code> wants to log into the system in <code>another</code> window. I am expecting that in new window <code>UserB</code> will be logged in and overwrite cookies, so if I refresh first window it will show <code>UserB</code>, but somehow that is not happening and in second window it shows <code>UserA</code>.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>public async Task&lt;ActionResult&gt; 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);
                  ...
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I think I should add more clarifications. There is some action which is being called from third party - <code>Shopify</code>. It looks like:</p>
  
  <pre><code>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", ""));
  }
  </code></pre>