繁体   English   中英

使用 Windows 服务上托管的 WCF 对 ADFS 进行身份验证

[英]Authentication against ADFS with WCF hosted on Windows service

我有一个 wcf 服务,可以查询 ADFS 以获取 SAML 令牌。 这是来自 Web 的常见代码段,用于查询 ADFS 并取回 SAML 令牌。 然而,它总是最终在线路返回通道处中断。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();
        }
    }
}

问题出在

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

我用依赖方 uri 替换了它,它向我发出令牌。 这里唯一的问题是令人困惑的错误消息。

该错误可能与 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

问候,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM