【问题标题】:IdentityServer4 with integrated Windows authentication具有集成 Windows 身份验证的 IdentityServer4
【发布时间】:2018-02-13 09:32:52
【问题描述】:

我是相当新的 IdentityServer4,我正在尝试为我们不同的内部 API 配置访问控制。内部我的意思是它不是通过互联网。我选择了 IdentityServer4,因为它在处理不同的客户端和授权类型时似乎具有很大的灵活性。

现在我正在尝试让 Windows 身份验证(针对 AD)工作。首先让我向您展示我希望它如何工作,然后我将向您展示我的尝试。

登录到 AD 的任何用户都应该能够从令牌端点请求令牌。因此,对于任何集成了 Windows 身份验证的应用程序,它都应该能够自动运行。

这是我希望如何在 PowerShell 中工作的示例。我不确定身体应该是什么样子,但希望你明白这一点。

$cred = Get-Credential
$body = @{grant_type='client_credentials';client_id='client'}
Invoke-RestMethod http://localhost:5000/connect/token -Method POST -Credential $cred -Body $body

所以我研究了 IdentityServer4 的快速入门示例,并阅读了 Windows Authentication 上的文档。我使用了simplest quickstart example 并尝试对其进行修改以使用 Windows 身份验证。

该示例使用WebHost.CreateDefaultBuilder 作为服务器,这意味着应该自动配置 Kestrel(根据文档)。然后我相应地修改ConfigureServices

public void ConfigureServices(IServiceCollection services)
{
    services.AddIdentityServer()
        .AddDeveloperSigningCredential()
        .AddInMemoryApiResources(Config.GetApiResources())
        .AddInMemoryClients(Config.GetClients());

    services.Configure<IISOptions>(iis =>
    {
        iis.AuthenticationDisplayName = "Windows";
        iis.AutomaticAuthentication = false;
    });
}

launchSettings.json我设置了

iisSettings": {
    "windowsAuthentication": true,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:5000/",
      "sslPort": 0
    }
  }

但是,这不起作用。当我运行服务器并尝试使用上述 PowerShell 脚本请求令牌时,我从 IdentityServer 收到以下错误日志:

[10:24:56 Debug] IdentityServer4.Validation.ClientSecretValidator
Start client validation

[10:24:56 Debug] IdentityServer4.Validation.BasicAuthenticationSecretParser
Start parsing Basic Authentication secret

[10:24:56 Debug] IdentityServer4.Validation.PostBodySecretParser
Start parsing for secret in post body

[10:24:56 Debug] IdentityServer4.Validation.PostBodySecretParser
client id without secret found

[10:24:56 Debug] IdentityServer4.Validation.SecretParser
Parser found secret: PostBodySecretParser

[10:24:56 Debug] IdentityServer4.Validation.SecretParser
Secret id found: client

[10:24:56 Debug] IdentityServer4.Validation.HashedSharedSecretValidator
Hashed shared secret validator cannot process NoSecret

[10:24:56 Debug] IdentityServer4.Validation.SecretValidator
Secret validators could not validate secret

[10:24:56 Error] IdentityServer4.Validation.ClientSecretValidator
Client secret validation failed for client: client.

[10:24:56 Verbose] IdentityServer4.Hosting.IdentityServerMiddleware
Invoking result: IdentityServer4.Endpoints.Results.TokenErrorResult

我觉得有点无能为力,好像我在这里遗漏了一些东西(比如正确设置客户端?)。我将非常感谢这里的任何帮助!

【问题讨论】:

    标签: identityserver4 ntlm ntlm-authentication


    【解决方案1】:

    日志说明了这一点 - 您缺少客户端密码。

    但是你在这里有一个更大的缺失。您正在尝试使用 client credentials 授权类型。根据我从您的解释中了解到,您想与当前的 Windows 用户进行身份验证,对吗?

    如果是这样 - 你的方法是错误的。客户端凭据授予类型用于客户端(了解应用程序)身份验证。换句话说 - 它将验证应用程序本身(无论是您的 powershell 脚本、控制台应用程序还是其他任何东西),而不是使用它的用户。

    例如,如果我们(我和你)在不同的机器上执行相同的脚本,在不同的用户凭据下,我们仍然会在访问令牌中收到相同的声明,因为我们作为客户端进行了身份验证。

    查看token endpoint 文档了解更多选项。

    如果要获取token,基于用户和密码,需要使用密码授权类型。

    希望这对您有所帮助并为您提供一些线索。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-02
      • 2011-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-08
      • 2010-12-08
      相关资源
      最近更新 更多