来自ADFS的RequestSecurityToken使用Windows身份验证

时间:2016-08-22 05:27:40

标签: wcf windows-authentication adfs2.0

我的客户端应使用当前登录用户的上下文从ADFS服务器请求安全令牌。我已经成功地使用来自客户端的用户名和密码从adfs / services / trust / 13 / usernamemixed端点请求安全令牌并将其发布到我的网站。

这是我的代码片段。

WS2007HttpBinding binding = new WS2007HttpBinding(SecurityMode.TransportWithMessageCredential);
        binding.Security.Message.EstablishSecurityContext = false;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
        EndpointAddress EpAddress;
        if (!bWindowsAuth)
        {
            binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
            EpAddress = new EndpointAddress(".../adfs/services/trust/13/usernamemixed");
        }
        else
        {
            binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
            EpAddress = new EndpointAddress(".../adfs/services/trust/13/windowsmixed");
        }

        WSTrustChannelFactory trustChannelFactory = new WSTrustChannelFactory(binding, EpAddress);
        trustChannelFactory.TrustVersion = TrustVersion.WSTrust13;

        if (!bWindowsAuth)
        {
            trustChannelFactory.Credentials.UserName.UserName = username;
            trustChannelFactory.Credentials.UserName.Password = password;
        }
        else
        {
            trustChannelFactory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
        }

        trustChannelFactory.ConfigureChannelFactory();

        // Create issuance issuance and get security token 
        RequestSecurityToken requestToken = new RequestSecurityToken(WSTrust13Constants.RequestTypes.Issue, WSTrust13Constants.KeyTypes.Bearer);
        requestToken.AppliesTo = new EndpointAddress(appliesTo);
        WSTrustChannel tokenClient = (WSTrustChannel)trustChannelFactory.CreateChannel();
        SecurityToken token = tokenClient.Issue(requestToken, out rsts);

CredentialCache.DefaultNetworkCredentials为空!!

还有其他配置吗?

提前致谢。

0 个答案:

没有答案