如何使用客户端证书从acs检索令牌?

时间:2012-03-21 20:15:18

标签: wcf saml servicebus acs

我想将ACS用作服务总线的STS。我已经设法使用ACS进行Web服务的身份验证。但是,服务总线需要一个令牌,我不知道如何从ACS中检索这些令牌?

简而言之,我希望我的客户端wcf服务能够使用服务总线进行身份验证,并使用与acs中存储为服务标识的证书相匹配的证书(与服务总线-sb对应的证书)。

另外,我正在使用NetTcpRelayBinding作为服务总线。

如果我可以使用客户端证书检索它,我想我可以使用来自acs的令牌??

1 个答案:

答案 0 :(得分:0)

通过WCF使用客户端证书凭据从ACS获取令牌是一种受到良好支持的方案。

有一个ACS样本可以使用WCF客户端证书身份验证here,查找Acs2CertificateBindingSample。兴趣点是如何创建从ACS获取令牌的绑定:

    public static Binding CreateServiceBinding(string acsCertificateEndpoint)
    {
        return new IssuedTokenWSTrustBinding(CreateAcsCertificateBinding(), new EndpointAddress(acsCertificateEndpoint));
    }

    public static Binding CreateAcsCertificateBinding()
    {
        return new CertificateWSTrustBinding(SecurityMode.TransportWithMessageCredential);
    }

如何使用此绑定创建频道工厂,以及如何指定客户端证书凭据:

ChannelFactory<IStringService> stringServiceFactory = new ChannelFactory<IStringService>(Bindings.CreateServiceBinding(acsCertificateEndpoint), serviceEndpointAddress);

// Set the service credentials and disable certificate validation to work with sample certificates
stringServiceFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
stringServiceFactory.Credentials.ServiceCertificate.DefaultCertificate = GetServiceCertificate();

// Set the client credentials.
stringServiceFactory.Credentials.ClientCertificate.Certificate = GetClientCertificateWithPrivateKey();

示例不使用服务总线,只是一个简单的“IStringService”接口,但是如果将NetTcpRelayBinding合并到绑定组合中,则相同的机制应该适用于您的场景。

相关问题