I'm trying add GitHub authentication to my ASP.NET Core app so that certain users have administrator role. This role I want implement through IdentityRole and users should be stored as IdentityUsers.
I used information from this post as starting point.
I set up authentication through GitHub like this:
services
.AddAuthentication()
.AddGitHub(options =>
{
options.ClientId = "xxx";
options.ClientSecret = "xxx";
})
And my Sigin method in controller is here:
public IActionResult SignIn(string provider, string returnUrl = null) =>
Challenge(new AuthenticationProperties { RedirectUri = returnUrl ?? "/" }, provider);
And I can get GitHub claims via this code:
public IActionResult Index()
{
var vm = new ProfileViewModel
{
Claims = User.Claims,
Name = User.Identity.Name
};
return View(vm);
}
Everything works and everything is fine but it's ClaimsPrincipal not IdentityUser. And I don't understand how can I create new or identify previously stored IdentityUser using this claims.
Here are set of articles from Microsoft about using external logins but they used Razor pages and don't provide much info how does it actually bind to IdentityUser.
How can I do the same without using Razor pages?