Infinite loop returning to the authentication page when using OAuth in MVC5

I wrote a webpage that uses Google / Facebook features using MVC5 and OAuth

sometimes, I can use Facebook or Google very well. It works quite well.

However, it often happens that

  • Go to the login page
  • Choose either google or facebook
  • provide account information, get the necessary redirects
  • redirect back to login page but not log in

I am not getting (or not looking in the right place) any errors that tell me: I use SSL on Azure for hosting

Does anyone have any tips on why it sometimes works and sometimes not? Does it look like it could be a cookie problem or a server side configuration problem? I cannot understand why this sometimes works and sometimes does not work.

I tried

  • using a second machine that has never been logged in before (for the rule cookies), the same problem
  • clearing cookie cache, same problem

How am I configured:

public void ConfigureAuth(IAppBuilder app) { // Enable the application to use a cookie to store information for the signed in user app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login") }); // Use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Uncomment the following lines to enable logging in with third party login providers //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); //app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); app.UseFacebookAuthentication( appId: "abc", appSecret: "123"); app.UseGoogleAuthentication(); } 

I followed this guide to use OAuth in MVC5 ( http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google- oauth2-and-openid-sign-on) j

+7
asp.net-mvc facebook-oauth asp.net-mvc-5 google-oauth
source share
1 answer

This is a serious problem when, randomly, your application starts to go into an endless loop and several times redistributing the application makes it work, but only temporarily. The quick way I found to solve this problem is to use the nuget kentor.owincookiesaver package, as @cooper commented. you must make a call to this class before calling cookieauthentication in the owin run class, as shown below.

 app.UseKentorOwinCookieSaver(); app.UseCookieAuthentication(new CookieAuthenticationOptions()); 

There seems to be a bug in owin and katana where your cookie just disappears and that fixes it.

+2
source share

All Articles