![](/img/trans.png)
[英]Consume WebAPI that uses Windows Authentication with Blazor WASM
[英]Blazor - Windows Authentication
我设计了一个内部应用程序,要求用户针对 AD 进行身份验证。 话虽如此,用户必须在登录屏幕上提供他/她的 ID/密码才能进行身份验证。 (我们不希望任何人都可以打开应用程序并做任何事情)
我已经阅读了几篇关于设置环境和通过 System.Security.Principal.WindowsIdentity.GetCurrent() 使用现有标识的文章。 没有人谈论通过 UI 提供的信息进行身份验证。
我构建了登录表单并且我有一个自定义的 AuthenticationStateProvider,但我不知道如何将从用户那里获得的凭据传递给 Windows,因此它可以使用 AD 对其进行身份验证。
有人可以阐明我如何 go 这样做吗? 谢谢!
为此,我正在使用.NET 标准 LDAP 客户端库,它工作正常。
像这样使用它:
using (var cn = new LdapConnection())
{
// connect to AD host
cn.Connect("your_ad", 389);
try
{
cn.Bind("user@domain", "pwd");
}
catch(LdapException e)
{
// invalid credentials
}
}
通过 Stefan 的引导,我找到了 package System.DirectoryServices.Protocols。 用法与 Stefan 提到的 Novell 非常相似。 下面是我计划集成到 AuthenticationStateProvider 中的测试代码。
using (var cn = new LdapConnection(new LdapDirectoryIdentifier("ad_servername")))
{
try
{
// this how you can verify the password of an user
cn.Bind(new NetworkCredential("myid", "mypwd"));
}
catch(LdapException l)
{
Console.WriteLine("logon failed");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.