【发布时间】: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