I'm having trouble setting up Owin / Katana / Oath etc.
In short ...
In the long ...
Clear your browser history. I tried to find out OWIN / Katana etc. Over the past few days and made many changes to the configuration of Google Developer Console and its code. Sometimes I got a white screen and could not get the debugger to click on the code inside my ExternalLoginCallback() function. Clearing my browser history seems to fix this.
No need to set GoogleOAuth2AuthenticationOptions.CallbackPath , leave it as the default signin-google .
I am testing locally, so I set my Google credentials (replacing the port number with the one you are using!)
Authorized Javascript Origins: " https: // localhost: 44353 "
Authorized redirect URIs: https: // localhost: 44353 / signin-google "and" https: // localhost: 44353 / Account / ExternalLoginCallback "
Too detailed code if anyone is interested
Startup.Auth.cs
public partial class Startup { public void ConfigureAuth(IAppBuilder app) { var cookieAuthenticationProvider = new CookieAuthenticationProvider(); var cookieAuthenticationOptions = new CookieAuthenticationOptions(); cookieAuthenticationOptions.AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie; cookieAuthenticationOptions.LoginPath = new PathString("/Account/Login"); cookieAuthenticationOptions.Provider = cookieAuthenticationProvider; app.UseCookieAuthentication(cookieAuthenticationOptions); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions(); googleOAuth2AuthenticationOptions.ClientId = "TODO : add client id"; googleOAuth2AuthenticationOptions.ClientSecret = "TODO : add secret"; app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions); } }
The function is executed when the user clicks on my "Sign in to Google". provider will be "google"
[HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public void ExternalLogin(string provider) { var properties = new Microsoft.Owin.Security.AuthenticationProperties(); properties.RedirectUri = Url.Action("ExternalLoginCallback", "Account"); HttpContext.GetOwinContext().Authentication.Challenge(properties, provider); }
The function that will be executed when the user returns from Google.
[AllowAnonymous] public async Task<ActionResult> ExternalLoginCallback() { var loginInfo = await Microsoft.Owin.Security.AuthenticationManagerExtensions.GetExternalLoginInfoAsync(HttpContext.GetOwinContext().Authentication); if (loginInfo == null) { throw new NotImplementedException(); } var signInResult = await this.SignInManager.ExternalSignInAsync(loginInfo, false); if (signInResult == Microsoft.AspNet.Identity.Owin.SignInStatus.Success) { return RedirectToAction("Index", "Home"); } if (signInResult == Microsoft.AspNet.Identity.Owin.SignInStatus.RequiresVerification) {
source share