I have a ASP.NET MVC application that uses oauth2 to authenticate googleplus users.
My problem is that the "OnAuthenticated" handler is never getting called even though the authentication is successful (ExternalLogin callback fires and i'm able to see that i'm logged in into google).
Can someone help me understand why the OnAuthenticated handler is not getting called and what mistake I'm doing? Thanks for all your help !
Here is the code i'm using in my startup.auth.cs
using Owin.Security.Providers.GooglePlus;
...
...
var googlePlusOptions = new GooglePlusAuthenticationOptions
{
ClientId = googleClientId,
ClientSecret = googleClientSecret,
SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
Provider = new Owin.Security.Providers.GooglePlus.Provider.GooglePlusAuthenticationProvider()
{
OnAuthenticated = (context) =>
{
context.Identity.AddClaim(new System.Security.Claims.Claim("urn:googleplus:accesstoken", context.AccessToken, System.Security.Claims.ClaimValueTypes.String, "Facebook"));
foreach (var x in context.User)
{
var claimType = string.Format("urn:googleplus:{0}", x.Key);
string claimValue = x.Value.ToString();
if (!context.Identity.HasClaim(claimType, claimValue))
context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, System.Security.Claims.ClaimValueTypes.String, "Facebook"));
}
return System.Threading.Tasks.Task.FromResult(0);
}
},
};
googlePlusOptions.Scope.Add("email");
app.UseGooglePlusAuthentication(googlePlusOptions);
Best Regards,
2P