Tim*_*Tim 5 ldap asp.net-core identityserver4
我目前正在开发一个项目,尝试设置一个基于 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 的一部分,我需要我的服务在没有任何用户界面。
只需添加
.AddLdapUsers<ActiveDirectoryAppUser>(Conf.GetSection("ldap"), UserStore.InMemory)
Run Code Online (Sandbox Code Playgroud)
如文档中所述,不会更改请求管道,因为所提供的登录/验证方法永远不会执行 - 它们仅通过来自 UI (AccountController) 的调用来触发。但是,正如我所说,我不想在此服务中集成任何 UI,而是使用 Token-Endpoint 已提供的接口(使用 client_id 和 client_secret 进行 POST 请求,使用 JWT 进行响应)。
有没有一种方法可以集成 LDAP 身份验证,而无需重写按需要开箱即用的大部分内容?
从你的问题来看,听起来你已经有一个usernameand password。注意client_id!=username和client_secret!= password。client_id是客户端应用程序的标识。
您尝试使用的授权类型在使用授权端点时称为资源所有者密码,在使用令牌端点时称为密码。此拨款类型用于支持遗留系统,不建议用于新开发。
您想要执行以验证用户身份的代码位于LdapUserResourceOwnerPasswordValidator.cs中,如果您将正确的参数传递到令牌端点,则应该执行该代码:
POST /连接/令牌
Run Code Online (Sandbox Code Playgroud)client_id=yourclientid& client_secret=yourclientsecret& grant_type=password& username=yourusername&password=yourusernamespassword
请参阅令牌端点文档:https://identityserver4.readthedocs.io/en/release/endpoints/token.html
您可以使用身份模型来帮助您发出令牌请求:
var response = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
{
Address = "https://demo.identityserver.io/connect/token",
ClientId = "yourclientid",
ClientSecret = "yourclientsecret",
UserName = "yourusername",
Password = "yourusernamespassword"
});
Run Code Online (Sandbox Code Playgroud)
此处记录了https://identitymodel.readthedocs.io/en/latest/client/token.html
| 归档时间: |
|
| 查看次数: |
6476 次 |
| 最近记录: |