How to pass a certificate to WSTrust to get Saml Token

后端 未结 2 992
野趣味
野趣味 2021-01-21 10:17

Here is an example of getting tokem using WSTrustChannelFactory. From here.

var stsBinding = new WS2007HttpBinding();
stsBinding.Security.Mode = SecurityMode.Tra         


        
2条回答
  •  野性不改
    2021-01-21 11:02

    Use the ClientCertificate property:

    var stsBinding = new WS2007HttpBinding();
    stsBinding.Security.Mode = SecurityMode.TransportWithMessageCredential;
    stsBinding.Security.Message.EstablishSecurityContext = false;
    stsBinding.Security.Message.NegotiateServiceCredential = false;
    
    // select the authentication mode of Client Certificate
    stsBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
    
    var wifChannelFactory = new WSTrustChannelFactory(stsBinding, stsEndpoint);
    wifChannelFactory.TrustVersion = TrustVersion.WSTrust13;
    
    // Supply the credentials
    wifChannelFactory.Credentials.ClientCertificate.Certificate = config.Certificate;
    

    The PFX you can import to your certificate store via the certmgr.msc snapin. Make sure that the account your application is running as has access to the private key. You can reference it in the store using the x509certificate2 classes.

提交回复
热议问题