There is already a class that can provide ClaimsAuthenticationManager claims correction, which you can extend to handle your domain-related requests, for example ...
public class MyClaimsAuthenticationManager : ClaimsAuthenticationManager { public override ClaimsPrincipal Authenticate(string resourceName, ClaimsPrincipal incomingPrincipal) { if (!incomingPrincipal.Identity.IsAuthenticated) { return base.Authenticate(resourceName, incomingPrincipal); } return AddApplicationClaims(incomingPrincipal); } private ClaimsPrincipal AddApplicationClaims(ClaimsPrincipal principal) {
The next task is to provide the appropriate middleware to call this. For my projects, I wrote the following classes ...
And then expand the wiring ...
public static class AppBuilderExtensions {
I know this is an anti-pattern for a service locator, but using IServiceProvider is a neutral container and seems to be an acceptable way to place dependencies in Owin middleware.
The last thing you need to associate with this at startup, the example below assumes Unity and registers / expands the IServiceLocator property ...
source share