My main goal is using the Windows Authentication to query my custom Users table to use through the web application. I am not sure there is a conventional way of doing this.
I have a predefined Users table and Roles table in a SQL database. How do I use the User.Identity.Name
to query this Users table and map all the tables data along with the roles to a ApplicationUser
class that can be further used later in the intranet web application?
I was unable to find anything closely related to what I am after from reading tons of articles. I assume this will be done in the Startup
class under ConfigureServices
but am also unsure of that. I need the user to be looked up whenever they navigate to the site for the first time.
I would go with
ClaimsTransformer
to get user claims. I just will try to show how to get user claims and to handle authorization for Windows Authenticatin.First create a
ClaimsTransformer
class:Then use it in
Configure
methodUnfortunately
User.IsInRole
method doesn't work withClaimsTransformer
(if you add role withClaimsTransformer
, IsInRole will be false) so you can't use[Authorize(Roles = "")]
withClaimsTransformer
. In this case you can use Claims Based Authorization to handle authotorization.So finally add below code to ConfigureServices and use
Authorize
attribute: