我有一个客户端 - 服务器应用程序(Windows,客户端是WPF,非UWP),我想通过活动目录进行身份验证。我的想法是从客户端所在的Windows机器上获取凭证(或令牌)并将该信息发送到服务器(通过webservice,IIS,asp.net)。然后服务器检查广告是否有效凭证并进行授权...... 所以关键点是:
我怎样才能做到这一点?
答案 0 :(得分:0)
如果要在桌面应用程序中检查Windows用户身份验证,可以简单地使用
Environment.UserName
变量,它提供当前登录用户的用户名。 如果你想检查它是否是一个活动目录用户,你可以调用这样的函数:
public bool UserExists(string username)
{
// create your domain context
using (PrincipalContext domain = new PrincipalContext(ContextType.Domain))
{
// find the user
UserPrincipal foundUser = UserPrincipal.FindByIdentity(domain, IdentityType.Name, username);
return foundUser != null;
}
}
在客户端中,您可以使用Environment
变量获取AD用户名和域名,将其传递给服务器并使用UserExist()
函数检查用户是否存在