I'm working on a small MVC5 website that makes use of Google authentication however I wanted to do it without the ASP.NET Identity.
I have so far followed the steps in this blog post and have a working login: http://coding.abel.nu/2014/11/using-owin-external-login-without-asp-net-identity/
However currently the User.Identity.Name is being set as the user's full name. I want to set it to the user's email address as I prefer to have it set to my user's primary key. My code consists so far solely on what is in that blog post.
I'm able to retrieve the user's email address with the following code but this is only after the user has authenticated.
ClaimsPrincipal.Current.FindFirst(ClaimTypes.Email).Value;
I have tried overriding the OnAuthenticated for the GoogleOAuth2ProviderOptions and found that there is a NameClaimType however it is readonly.
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
{
ClientId = "...",
ClientSecret = "...",
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnAuthenticated = async context =>
{
context.Identity.NameClaimType = ClaimTypes.Email;
}
}
});
I haven't been able to find anything else that lets me set what the User.Identity.Name is set to. Any ideas?