【问题标题】:IdentityServer4 with LDAP/AD authentication without UIIdentityServer4 具有 LDAP/AD 身份验证,无 UI
【发布时间】:2018-09-08 04:30:07
【问题描述】:

我目前正在开展一个项目,我正在尝试设置基于 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】:

    从您的问题看来,您已经拥有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

    【讨论】:

    • 非常感谢! client_id/secret 不是用户名/密码的提示真的很有帮助....当我使用grant_type“password”发送请求并按照描述提供client_id、client_secret、用户名和密码时,它会根据需要查询Active Directory。
    猜你喜欢
    • 2018-07-05
    • 2014-08-09
    • 2015-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多