在 .NET Web 中使用 Kerberos 进行身份验证 API

Authenticate with Kerberos in .NET Web API

我需要在 .NET 中实现桌面客户端 + 应用程序服务器(Web 服务)的解决方案。

客户端应针对 Active Directory(Kerberos 单点登录)进行身份验证,并将其经过验证的 Active Directory 身份转发到 Web 服务(NET Web API 或 WCF)。

Web 服务应验证客户端是否针对 Active Directory 进行了签名。两台计算机(客户端和服务器)都在一个 AD 域中 运行。

我想这可以使用 WCF 实现 (see code here), but today NET Web API is preferred over Windows Communication Foundation。也可以在 ASP Web API 中实现吗?

Similar question not answered is here.

是的,这是可能的。答案在这里:https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/integrated-windows-authentication

API可以使用Windows认证。身份验证由 IIS 处理,只要您的 web.config 设置正确,如那篇文章所述。

在您的应用程序中,您只需使用 UseDefaultCredentials 属性:

告诉它传递 Windows 凭据
HttpClientHandler handler = new HttpClientHandler() {
    UseDefaultCredentials = true
};

HttpClient client = new HttpClient(handler);