OAuth 2 Owin not working StackExchange.Redis Sessi

2019-05-06 17:54发布

问题:

Starting with a fresh, new MVC5 Project I hooked up External OAuth Login with Google, Facebook Twitter, Microsoft etc. All is working as expected.

I then added the new ASP.NET Session State Provider for Redis Preview Release and have it working. Yeah!

I soon noticed that attempting to login using any of the OAuth providers no longer works properly. The Google & Facebook login buttons calls the ExternalLoginCallback(string returnUrl) on the Accont controller but goes nowhere. The login page simply refreshes.

The LinkedIn, Twitter, and Microsoft buttons all direct the user to those login pages but when returned back to my application they return to the login page and no user is added to the system.

Commenting out the custom sessionState entry in my web.config returns the external login back to normal.

Considering both frameworks are black-boxes to me I am not sure how to go about geting these two to play together.

回答1:

this helped me with the exact issue.

http://www.nsilverbullet.net/2014/06/24/tough-mvc-5-owin-external-authentication-issue/

basically: Must Have Session State? in AccountController modify:

    [AllowAnonymous]
    public ActionResult Login(string returnUrl)
    {
        //Ensure Session has at least one value
        Session["EnableExternalAuth"] = true; // <--------- This helped

        ViewBag.ReturnUrl = returnUrl;
        return View();
    }

There seem to be an issue with sessions and external login providers