Using Windows Authentication in an Intranet web application I want to achieve the following:
- Gather additional attributes from AD (name, employee number)
- Gather additional attributes from a database table (working hours, pay)
- Authorize based on application roles (not AD groups)
- Authorize based on an AD attribute (has direct reports)
- User not provide a username/password
In my search for an answer it is suggested that I need to add ClaimsTransformation
to my application:
How do I use Windows Authentication with users in database
Populate custom claim from SQL with Windows Authenticated app in .Net Core
Caching Claims in .net core 2.0
Though I don't fully understand the solution and why ClaimsTransformation
happens on every request so I'm looking for answers to the following:
- Is ASP.NET Core Identity required for
ClaimsTransformation
to work? - Does
ClaimsTransformation
happen on every request with just Windows Authentication or also with form based authentication? - Does this have to happen on every request?
- Caching claims like GivenName, Surname seem simple but what about roles? What steps need to be taken to ensure the database isn't hit every time but roles do get updated when there are changes.
- Is there a simpler alternative for what I'm trying to do?
This article gave me some ideas and here is a possible solution.
Controllers would inherit from a base controller which has a policy that requires the
Authenticated
claim. When this isn't present it goes to theAccessDeniedPath
and silently performs the login adding theAuthenticated
claim along with any other claims, if this is already present then the Access Denied message would appear.When creating the new
ClaimsIdentity
I've had to strip most of the Claims in the original identity as I was getting a HTTP 400 - Bad Request (Request Header too long) error message.Are there any obvious issues with this approach?
Startup.cs
Controller