ASP.NET Core and on premise AD authentication

前端 未结 2 1750
鱼传尺愫
鱼传尺愫 2021-01-04 14:11

I\'d like to try and use ASP.NET Core MVC or Web API at my workplace but we have just Active Directory to authentication and authorization. Is there any solution to solve it

相关标签:
2条回答
  • 2021-01-04 14:29

    As of today, System.DirectoryServices is not available in ASP.NET Core yet. You can read more here.

    In the meantime, you can use Novell.Directory.Ldap.NETStandard. For example,

    public bool ValidateUser(string domainName, string username, string password)
    {
        string userDn = $"{username}@{domainName}";
        try
        {
            using (var connection = new LdapConnection {SecureSocketLayer = false})
            {
                connection.Connect(domainName, LdapConnection.DEFAULT_PORT);
                connection.Bind(userDn, password);
    
                if (connection.Bound)
                    return true;
            }
        }
        catch (LdapException ex)
        {
            // Log exception
        }
        return false;
    }
    

    Since it has too many moving pieces, I have created a sample project at GitHub.

    0 讨论(0)
  • 2021-01-04 14:37

    Microsoft has released pre-release version for System.DirectoryServices. You can get it from NuGet package manager using this command:

    Install-Package System.DirectoryServices -Version 4.5.0-preview1-25914-04
    

    This is working fine for me till now.

    0 讨论(0)
提交回复
热议问题