I have written a webpage that takes advantage of Google/Facebook auth using MVC5 and OAuth.
Sometimes, I'm able to auth very well using either Facebook or Google. It works quite well.
However often what happens is:
- Navigate to the login page.
- Choose either google or facebook.
- Provide the account info, getting the necessary redirects.
- Redirect back to login page, but not logged in.
I'm not receiving (or not looking in the right place) any errors that clue me in - I am using SSL on Azure for hosting.
Does anyone have tips for why it sometimes works, and sometimes does not? This feels like it could be a cookie thing, or maybe a server side configuration problem? I can't figure out why it would sometimes work and sometimes wouldn't work.
I've tried:
- Using a second machine, one that has never logged in before (to rule out cookies), same problem.
- Clearing my cookie cache, same problem.
How I'm 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've followed this tutorial to use OAuth in MVC5: Create an ASP.NET MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on (C#)