[英]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.