首页 > 解决方案 > Identity Server 中的 PrincipalContext.ValidateCredentials 与 HttpContext.AuthenticateAsync 有什么区别

问题描述

我通过调用HttpContext.AuthenticateAsyncExternalController 在 Identity Server 中使用 Windows 帐户实现了 SSO,就像 Identity Server MVC 代码中已经存在的默认代码一样(请参阅此代码)。这一切都很好。

在其他一些代码中,我找到了另一种方法,我想知道他们为什么这样做。基本上,他们所做的是验证凭据,AccountController如下所示:

using (var principalContext = new PrincipalContext(ContextType.Domain, domainName))
{
    return principalContext.ValidateCredentials(userName, password);
}

...如果验证成功,他们会:

await httpContext.SignInAsync(username, username, new AuthenticationProperties());

所以我的问题是:这两种方法有什么区别,哪一种是针对 Windows 对用户进行身份验证的推荐方法?

标签: c#authenticationasp.net-coresingle-sign-onidentityserver4

解决方案


推荐阅读