【问题标题】:Authentication against ADFS with WCF hosted on Windows service使用 Windows 服务上托管的 WCF 对 ADFS 进行身份验证
【发布时间】:2013-10-24 09:45:42
【问题描述】:

我有一个 wcf 服务,它可以在 ADFS 中查询 SAML 令牌。这是从网络查询 ADFS 并取回 SAML 令牌的常见 sn-p。 然而,它总是在 return channel.Issue(rst); 行结束。 .错误为 ID3082:请求范围无效或不受支持。 至少在高层次上,我无法确定错误是在 ADFS 服务器端还是与 WCF 服务的配置方式或代码有关。请帮忙。

public SecurityToken GetSamlToken()
{
    using (var factory = new WSTrustChannelFactory(
        new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
        new EndpointAddress(new Uri("https://serv/adfs/services/trust/13/usernamemixed"))))
    {
        factory.Credentials.UserName.UserName = "username";
        factory.Credentials.UserName.Password = "password";
        factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
        factory.TrustVersion = TrustVersion.WSTrust13;                
        WSTrustChannel channel = null;                
        try
        {
            string KeyType;
            var rst = new RequestSecurityToken
            {
                RequestType = WSTrust13Constants.RequestTypes.Issue,
                AppliesTo = new EndpointAddress("net.tcp://localhost:xxxx/Service1/mex"),                         
                KeyType = Microsoft.IdentityModel.Protocols.WSTrust.WSTrust13Constants.KeyTypes.Bearer,                                        
            };

            channel = (WSTrustChannel)factory.CreateChannel();

            return channel.Issue(rst);
        }
        finally
        {
            if (channel != null)
            {
                channel.Abort();
            }
            factory.Abort();
        }
    }
}

【问题讨论】:

    标签: c# wcf adfs2.0 adfs


    【解决方案1】:

    问题出在

    AppliesTo = new EndpointAddress("net.tcp://localhost:xxxx/Service1/mex")
    

    我将其替换为依赖方 uri,它会向我发放令牌。这里唯一的问题是令人困惑的错误消息。

    【讨论】:

      【解决方案2】:

      该错误可能与 ADFS 端点的配置有关。以下文章似乎很好地概述了 ADFS Web 服务通信以及解决一些问题的步骤:

      http://msinnovations.wordpress.com/2011/03/28/some-tips-on-active-federation-with-adfs-2-0/

      为了获得有关错误发生的位置(可能还有原因)的更多信息,您可能希望/需要配置 WCF 跟踪/日志记录。以下链接提供了概述:

      http://msdn.microsoft.com/en-us/library/ms733025.aspx

      问候,

      【讨论】:

      • 博客显示“ID3082:请求范围无效或不受支持。发生这种情况的原因之一是您尚未在 ADFS 中为您的应用程序设置依赖方信任。”那么这是否意味着我的 wcf 服务必须添加为依赖方?我是 ADFS 2.0 的新手。我看过有关如何配置依赖方的文章,但我们是否为 WCF 服务做同样的事情?目前我还没有物理访问 ADFS 服务器的权限。
      • 既然你特别提到了 ADFS 点,我想我将不得不接受你的作为答案
      猜你喜欢
      • 2019-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      • 2012-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多