【问题标题】:ASP.Net Core 2.1 Web Api 2 And Active Directory CredentialsASP.Net Core 2.1 Web Api 2 和 Active Directory 凭证
【发布时间】:2018-10-19 11:50:57
【问题描述】:

我目前正在为 Group of organizations 在ASP.Net Core 2.1 上开发Web Api 2 application,他们都有自己的Active Directory Domain services

我想在domain 上检查来自ASP.Net Core 2.1 Web Api 2 的凭据,该凭据将由用户指定。 我的目标是拥有一个连接到指定活动目录服务并检查凭据的功能。

如果从active directory获取用户信息,解决方案会更有价值,所以我可以在数据库中自动填写一些字段

【问题讨论】:

  • Windows 身份验证(内置于 IIS)是否不适合您?
  • 如果我有 1 个域,则 IIS 内置身份验证将起作用,但我有多个域。其实 Pelice 的回答很简单,非常接近我的需要,我必须先测试一下,如果一切顺利,我会在我的代码中实现它。
  • 域是否在同一个 AD 林中?还是他们之间有信任?仅当域之间没有信任时,Windows 身份验证才会起作用。
  • 我使用了 Pelice 的答案,没关系,正是我需要的,我自己构建的所有其他东西,比如在数据库中有几个域作为连接和填充的模式。无论如何,谢谢你的帮助

标签: c# asp.net active-directory ldap


【解决方案1】:

我的项目也是如此。我使用了 Novell 库(也适用于 linux)Novell.Directory.Ldap

这里是文档:https://www.novell.com/documentation/developer/ldapcsharp/?page=/documentation/developer/ldapcsharp/cnet/data/bovumfi.html

为了检查用户凭据,我编写了以下代码:

using (LdapConnection testConn = new LdapConnection() { SecureSocketLayer = _useSSL })
{
    try {
        //Connect function will create a socket connection to the server - Port 389 for insecure and 3269 for secure   
        testConn.Connect(_serverName, _serverPort);

        //Bind function with null user dn and password value will perform anonymous bind to LDAP server 
        testConn.Bind(user.DistinguishedName, password);

        var res = testConn.Bound;
        return res;
    }catch (Exception ex){
        Console.WriteLine($"Authenticate: {ex.Message}");
        return false;
    }
}

【讨论】:

  • 感谢您的帮助。如果您在实践中使用它,它可以用于验证以外的其他用途吗?比如抓取特定用户的数据。
  • 我刚刚打开文档,一切都清楚了。
猜你喜欢
  • 2019-01-17
  • 2017-09-05
  • 2022-08-16
  • 2018-03-10
  • 2018-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多