对应用项目使用多重认证。 我需要使用 IIS 服务器,我的应用程序同时具有应用程序 UI 和具有相同代码项目的服务,并且具有两个身份验证 - 协商身份验证和 Bearer 身份验证。 Kestrel 服务器对此没有问题。它只是 IIS 不使用添加到授权过滤器的策略承载身份验证。
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");
}
}
IIS 问题,它期望服务调用与 NTLM 协商!对于 Kestrel 服务器而言,情况并非如此,因为调用可以正常进行。我们如何用 IIS 解决这个问题。
还尝试使用 ForwardDefaultSelector 重定向以使用正确的身份验证方案,但它不适用于 IIS 服务器而不是 IIS 预期使用 NTLM 进行协商。 –
期待知道用IIS Server运行这个的解决方案