I am creating a windows 8 client app in c#.This app will use odata service of SAP. For authentication I need SAML token issued by ADFS. Is there any method to get SAML token from ADFS using windows credentials?
            Asked
            
        
        
            Active
            
        
            Viewed 5,387 times
        
    1 Answers
0
            
            
        You can get the SAML token using the below code.
var factory = new WSTrustChannelFactory(new Microsoft.IdentityModel.Protocols.WSTrust.Bindings.UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential), adfsEndpoint);
factory.Credentials.UserName.UserName = "username";
factory.Credentials.UserName.Password = "********";
factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
factory.TrustVersion = TrustVersion.WSTrust13;
WSTrustChannel channel = null;
try
{
    var rst = new RequestSecurityToken
    {
        RequestType = WSTrust13Constants.RequestTypes.Issue,
        AppliesTo = new EndpointAddress("https://yourserviceendpoint.com/"),
        KeyType = KeyTypes.Bearer,
    };
    channel = (WSTrustChannel)factory.CreateChannel();
    return channel.Issue(rst);
}
catch (Exception e)
{
    return null;
}
 
    
    
        John Saunders
        
- 160,644
- 26
- 247
- 397
 
    
    
        KhanS
        
- 1,167
- 2
- 12
- 27
- 
                    Is there a reason to ignore the exception? – John Saunders Nov 16 '12 at 14:40
