简体   繁体   English

如何在 Blazor 服务器端应用程序中从本地 Active Directory 实施身份验证?

[英]How do I implement authentication from a local Active Directory in Blazor Server-Side application?

I want all people from our local Active Directory to be able to login into our blazor server side application.我希望本地 Active Directory 中的所有人都能够登录我们的 blazor 服务器端应用程序。 On MSDN they offer me all kind of authentication options.在 MSDN 上,他们为我提供了各种身份验证选项。 But non of these are for a local Active Directory, just for an Active Directory in Azure.但这些都不是针对本地 Active Directory,仅针对 Azure 中的 Active Directory。

Windows Authentication is no option because I need the user to be able to logout of the app. Windows 无法进行身份验证,因为我需要用户能够注销该应用程序。 Does anyone know a reliable way to achive an authentication with a local Active Directory?有谁知道使用本地 Active Directory 进行身份验证的可靠方法? Any help is appreciated.任何帮助表示赞赏。

First add nutget package System.DirectoryServices then in your login component首先添加 nutget package System.DirectoryServices然后在您的登录组件中

    @using System.DirectoryServices


<EditForm Model="@user" OnValidSubmit="@HandleValidSubmit">
    <DataAnnotationsValidator />
    <ValidationSummary />
    <div class="row">
        <div class="col-md-12">
            <label>User Name :</label>
            <InputText @bind-Value="user.UserName"></InputText>
        </div>
        <div class="col-md-12">
            <label>Password</label>
            <InputText @bind-Value="user.Password"></InputText>
        </div>
        <div class="col-md-12">
            <button type="submit">Login</button>
        </div>
    </div>

</EditForm>

@code {

    public UserData user { get; set; } = new UserData();
    private void HandleValidSubmit()
    {
        DirectoryEntry entry = new DirectoryEntry();
        entry = new DirectoryEntry("LDAP://Your Active directory IP");
        entry.Username = user.UserName;
        entry.Password = user.Password;

        DirectorySearcher search = new DirectorySearcher(entry);
        search.Filter = "(SAMAccountName=" + user.UserName + ")";

        SearchResult result = search.FindOne();

        if (result == null)
        {
            //return false;
        }
        else
        {
           // return true;
        }


    }

}

var directorySearch = new DirectorySearcher(new DirectoryEntry("LDAP://" + domain, user.UserName, password)); var directorySearch = new DirectorySearcher(new DirectoryEntry("LDAP://" + domain, user.UserName, password)); directorySearch.Filter = "(SAMAccountName=" + user.UserName+ ")"; directorySearch.Filter = "(SAMAccountName=" + user.UserName+ ")"; SearchResult result = directorySearch.FindOne(); SearchResult result = directorySearch.FindOne();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Blazor(服务器端),具有组织/Office 365/Microsoft 帐户身份验证; 如何做本地多个角色? - Blazor (Server-Side) with Organizational/Office 365/Microsoft Account Authentication; How to do Local Multiple Roles? 如何从 blazor(服务器端)Web 应用程序获取访问令牌? - How do I get the access token from a blazor (server-side) web app? 自定义 blazor 服务器端身份验证 - Custom blazor server-side authentication 如何在 blazor 服务器端应用程序中扩展身份验证过程? - How do I extend the authentication process in a blazor server side app? 从 Blazor 客户端模块查询本地 Active Directory? - Querying local Active Directory from Blazor client side module? 在 Blazor 服务器端应用程序中调用 StateHasChanged() 异步会影响所有打开的浏览器,我该如何阻止它? - calling StateHasChanged() async in Blazor Server-Side application effects all open browsers, how can I stop this? 如何在 Blazor 服务器端的 CircuitHandler 中调用方法? - How can I invoke method in CircuitHandler of Blazor server-side? 如何从 Blazor 服务器端应用程序成功注销? - How to sign out successfully from a Blazor server-side app? 如何在 blazor 服务器端应用程序中检测移动设备? - How do I detect mobile devices in blazor server side application? 如何从服务器端禁用 RadButton? - How do I disable RadButton from server-side?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM