I created an asp.net core project in visual studio 2015 with windows authentication. I can\'t figure out how to add roles to the Identity.
I have a table with usernames
With Windows Authentication the roles come from Active Directory, not a database.
You could use Claims Transformation to change the inbound identity on every request to pull extra roles from your database.
public class ClaimsTransformer : IClaimsTransformer
{
public Task TransformAsync(ClaimsPrincipal principal)
{
((ClaimsIdentity)principal.Identity).AddClaim(
new Claim("ExampleClaim", "true"));
return Task.FromResult(principal);
}
}
And then wire it up with
app.UseClaimsTransformation(new ClaimsTransformationOptions
{
Transformer = new ClaimsTransformer()
});
Note that in the current incarnation there's no DI support, so you'll have to manually pull out your database information from DI if that's where it is.