title: RequestSecurityToken from STS and post it to my website
body: <p>My web site implements AD FS based authentication. Now I need to programmatically access my web site through a client. My client should request the security token from the ADFS server using the currently logged on user's context. I have been successfully able to request the security token from the <code>adfs/services/trust/13/usernamemixed</code> endpoint using username and password from the client and post it to my website.</p>
  
  <p>What is not working for me is requesting the same token from the <code>adfs/services/trust/13/windowsmixed</code> endpoint using the <code>DefaultNetworkCredentials</code>. I get the error <code>The HTTP request was forbidden with client authentication scheme 'Anonymous'.</code>. I am using <code>Microsoft.IdentityModel</code> SDK (instead of <code>System.IdentityModel</code> in .NET 4.5).</p>
  
  <p>Here's a snippet of my code.</p>
  
  <pre><code>  factory = new MSWSTrustChannelFactory(
    new Microsoft.IdentityModel.Protocols.WSTrust.Bindings.WindowsWSTrustBinding(SecurityMode.TransportWithMessageCredential),
                      stsUrl);
  
    factory.TrustVersion = TrustVersion.WSTrust13;
  
    factory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
  
    var rst = new RequestSecurityToken
    {
        RequestType = RequestTypes.Issue,
        AppliesTo = new EndpointAddress(realm),
        KeyType = KeyTypes.Bearer,
        RequestDisplayToken = true
    };
  
    MSIWSTrustChannelContract channel = factory.CreateChannel();
    RequestSecurityTokenResponse rstr;
    SecurityToken token = channel.Issue(rst, out rstr);
  </code></pre>
  
  <p>I don't have any control on the ADFS server and can't debug what is going wrong from there. Whatever I can do is only from the client end. Any idea what is going wrong with my code above? Any help or pointers are greatly appreciated.</p>