IdentityServer4具有没有UI的LDAP / AD身份验证

问题描述 投票:1回答:1

我正在开发一个项目,我正在尝试建立一个基于IdentityServer4(https://github.com/IdentityServer/IdentityServer4)的服务,该服务通过LDAP查询本地Active Directory来验证用户。

为此,我还在我的项目中包含了IdentityServer4.LdapExtension(https://github.com/Nordes/IdentityServer4.LdapExtension)。来自存储库的工作示例工作正常(https://github.com/Nordes/IdentityServer4.LdapExtension/tree/master/Sample/IdentityServer) - 但自定义逻辑是UI的一部分,我需要我的服务在没有任何UI的情况下运行。

只需添加

.AddLdapUsers<ActiveDirectoryAppUser>(Conf.GetSection("ldap"), UserStore.InMemory) 

如文档中所述,不会更改请求管道,因为提供的登录/验证方法永远不会执行 - 它们仅通过来自UI(AccountController)的调用触发。但是,正如我所说,我不想在这个服务中集成任何UI,而是使用Token-Endpoint已经提供的接口(带有client_id和client_secret的POST请求,带有JWT的响应)。

有没有办法集成LDAP身份验证,而无需根据需要重写开箱即用的大部件?

asp.net-core ldap identityserver4
1个回答
1
投票

从你的问题听起来你已经有一个usernamepassword。注意client_id!= usernameclient_secret!= passwordclient_id是客户端应用程序的标识。

您尝试使用的授权类型在使用授权端点时称为Resource Owner Password,在使用令牌端点时称为password。此授权类型用于支持旧系统,不建议用于新开发。

要对用户进行身份验证而要执行的代码位于LdapUserResourceOwnerPasswordValidator.cs中,如果将正确的参数传递给令牌端点,则应执行该代码:

POST / connect / token

client_id=yourclientid&
client_secret=yourclientsecret&
grant_type=password&
username=yourusername&password=yourusernamespassword

请参阅令牌端点文档:https://identityserver4.readthedocs.io/en/release/endpoints/token.html

您可以使用Identity Model来帮助您发出令牌请求:

var response = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
{
    Address = "https://demo.identityserver.io/connect/token",

    ClientId = "yourclientid",
    ClientSecret = "yourclientsecret",
    UserName = "yourusername",
    Password = "yourusernamespassword"
});

这里记录了https://identitymodel.readthedocs.io/en/latest/client/token.html

© www.soinside.com 2019 - 2024. All rights reserved.