I am new to MVC 5 authentication. Currently I tried Google Authorization using Owin The code in startup.Auth.cs
var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
{
ClientId = "Client-id",
ClientSecret = "secret-key",
CallbackPath = new PathString("/Account/ExternalLoginCallback"),
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnAuthenticated = async context =>
{
context.Identity.AddClaim(new Claim("picture", context.User.GetValue("picture").ToString()));
context.Identity.AddClaim(new Claim("profile", context.User.GetValue("profile").ToString()));
}
}
};
googleOAuth2AuthenticationOptions.Scope.Add("email");
app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions);
But it does not hit ExternalLoginCallback Action for debug.
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
It stop at /Account/ExternalLoginCallback?ReturnUrl=%2F with blank white screen. I won't find what is wrong with this. and find similar question Google Authentication using OWIN Oauth in MVC5 not hitting ExternalLoginCallback function, but it is not helpful in mine case.
This is similar to: Google Authentication using OWIN Oauth in MVC5 not hitting ExternalLoginCallback function
Basically, set your google App in the Developers dashboard to point to your */ExternalLoginCallback method.
Leave the GoogleProvider with the default callback path.
Add a route to handle signin-google in RouteConfig:
That should fix google provider and all the others too.
Try the same code but change the
CallbackPath
to/umbraco/surface/UmbracoIdentityAccount/LinkLoginCallback
and register it in the Authorized redirect URIs in your app.You have add the follow in order to map the route in RouteConfig.cs because Google sends the response to yourdomain/signin-google.
Try this it may work. Its works for my case
I've been having issues with setting up Owin/Katana/Oath etc.
In short...
GoogleOAuth2AuthenticationOptions.CallbackPath
as the defaultIn long...
Clear your browser history. I've been trying to learn OWIN/Katana etc for the past few days and have been making many configuration changes on the Google Developer Console and within my code. I was occasionally getting the "white screen" and unable to get the debugger to hit code within my
ExternalLoginCallback()
function. Clearing my browser history seems to fix this.There is no need to set the
GoogleOAuth2AuthenticationOptions.CallbackPath
, leave it as the defaultsignin-google
.I'm testing locally so I've set my the Google credentials to (replacing the port number with the one you're using!)
Authorised Javascript Origins : "https://localhost:44353"
Authorised redirect URIs: "https://localhost:44353/signin-google" and "https://localhost:44353/Account/ExternalLoginCallback"
Overly verbose code if anyone is interested
Startup.Auth.cs
Function executed when user clicks my "Sign in with Google".
provider
will be "Google"Function that will be executed when user returns from Google.