0

Using multiple authentication for the application project. I need to use IIS Server and my application has both application UI and Services with same code project and has two authentication - Negotiate authentication and Bearer authentication. Kestrel server has no issues with this. It just IIS does not use Policy Bearer authentication added to Authorize filter.


var myMultipleSchemePolicy = new AuthorizationPolicyBuilder()
                        .AddAuthenticationSchemes(new string[] { NegotiateDefaults.AuthenticationScheme, JwtBearerDefaults.AuthenticationScheme })
                        .RequireAuthenticatedUser()
                        .Build();
var bearerPolicy = new AuthorizationPolicyBuilder()
                        .RequireAuthenticatedUser()
                        .AddAuthenticationSchemes("Bearer")
                        .RequireClaim(somerequiredclaim)
                        .Build();


//Negotiate authentication added here
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();
//Okta bearer authentication added here
builder.Services.AddAuthentication("Bearer").AddOktaWebApi(SomeoktaWebApiOptions);

builder.Services.AddAuthorization(options =>
{
    options.DefaultPolicy = myMultipleSchemePolicy ;
    options.AddPolicy("SomeBearerPolicy", bearerPolicy); // Used with Authorize attribute on service call)
});
//In the service call
    public class SomeController : Controller
    {
        [HttpPost()]
        [Route("/Some/MyMethodCall")]
        [Authorize(AuthenticationSchemes = "Bearer", Policy = "SomeBearerPolicy")]
        public ActionResult MyMethodCall()
        {
            var response = new { Result = "Testing Application Service call" };

            return Content(JsonConvert.SerializeObject(response, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }), "application/json");
        }
    }

Issue here with IIS it expects service call to Negotiate with NTLM! This is not the case for Kestrel server were call goes thru and works. How can we resolve this with IIS.

Also tried out to use ForwardDefaultSelector to redirect to use correct authentication scheme but it did not work for IIS server instead IIS expected to Negotiate using NTLM. –

Expecting to know the solution to run this with IIS Server.

0 Answers0