gpt4 book ai didi

c# - 在独立应用程序上使用 ADFS 进行 Windows 身份验证

转载 作者:太空宇宙 更新时间:2023-11-03 19:56:55 25 4
gpt4 key购买 nike

我有这个 Windows 控制台应用程序,它正在尝试针对 ADFS 执行 Windows 身份验证。我已经能够使用用户名/密码进行身份验证,但我不想这样做,因为用户已经在 Windows 中进行了身份验证。

我有这个代码:

        //Setup the connection to ADFS

const string adfsEndpoint = "https://iis.dev.lab/adfs/services/trust/13/windowsmixed";

var factory = new WSTrustChannelFactory(new WindowsWSTrustBinding(SecurityMode.TransportWithMessageCredential), new EndpointAddress(adfsEndpoint))
{
TrustVersion = TrustVersion.WSTrust13
};

//Setup the request object
var rst = new RequestSecurityToken
{
RequestType = RequestTypes.Issue,
KeyType = KeyTypes.Bearer,
AppliesTo = new EndpointReference(relyingPartyId)
};

//Open a connection to ADFS and get a token for the logged in user
var channel = factory.CreateChannel();

var genericToken = channel.Issue(rst) as GenericXmlSecurityToken;

当它试图获取 token 时我遇到了这个异常:

Security Support Provider Interface (SSPI) authentication failed. The ser ver may not be running in an account with identity 'host/iis.dev.lab'. If the se rver is running in a service account (Network Service for example), specify the account's ServicePrincipalName as the identity in the EndpointAddress for the se rver. If the server is running in a user account, specify the account's UserPrin cipalName as the identity in the EndpointAddress for the server.

事情是:

  • 用户已经在 dev.lab 域中通过身份验证
  • ADSF 服务在 dev.lab 域中的管理员用户帐户下运行
  • 在错误消息中,出于某种原因我有 iis.dev.lab 域,这可能是原因..

问题:

  1. 我应该使用这个 url ("../adfs/services/trust/13/windowsmixed") 来执行这种身份验证吗?或者我应该使用 kerberosmixed 吗?有人可以指出一些关于 ADFS 中可用的每项服务的目标的文档吗?
  2. 有没有办法在发出请求之前设置用户的域?我试过这个 factory.Credentials.Windows.ClientCredential.Domain = "dev.lab"; 但没有成功。
  3. 即使进行了 win auth,我还需要定义凭据吗?例如:factory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials; ?

感谢任何帮助。

最佳答案

因此,此错误消息的“可能”原因是您可能未正确配置 ADFS。

在此处查看 SPN 的定义:https://msdn.microsoft.com/en-us/library/ms677949(v=vs.85).aspx

要解决此问题,您需要在 ADFS 服务帐户或服务器本身上设置 SPN。

SETSPN -a HTTP/{ADFS 服务器的 URL} 域/服务名称

SETSPN -a HTTP/{ADFS 服务器的 URL} 计算机名

然后重新启动 ADFS 服务。关于服务帐户的一个注意事项,如果您使用网络或系统帐户运行,那么您仍然需要使用计算机名称,因为这些是本地服务器帐户。例如,如果您有 iis.dev.lab 的 ADFS URL,那么您可以这样做:

SETSPN -a HTTP/IIS.DEV.LAB ADFSServer

此外 - 测试您的 adfs 设置:https://iis.dev.lab/adfs/ls/IdpInitiatedSignon.aspx

关于c# - 在独立应用程序上使用 ADFS 进行 Windows 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32615043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com