Facebook, Google OAuth fails sometimes on Azure

2019-08-15 22:23发布

I am using Asp.Net MVC OAuth login with facebook and google and strange thing that at some period it doesnot work

var externalIdentity =
                HttpContext.GetOwinContext()
                    .Authentication.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);

var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
   return RedirectToAction("Login");
}

Seems here it cant get user info and redirect to login page. I cant figure out why or what can cause that. I also have two slots beta and production.

So any suggestion or maybe somebody already have that and found way how to fix that?

1条回答
倾城 Initia
2楼-- · 2019-08-15 22:30

Finally after few weeks i solve my problem. Its really something strange and probably issue is because of azure, since beforemy implementation works on VMvare for 6 month.

in AccountController there is method

public ActionResult ExternalLogin(string provider, string returnUrl)

add there

Session.RemoveAll();

PS/ Firstly when I have seen this recommendation I did not understood how it can help but then next time when OAuth fails i just simply restarted WebApp and it starts working. By the way even now i dont understand what is going on with session but it works.

查看更多
登录 后发表回答