ADFS STS authentication with console application
<p>I have a website and API secured with our corporate ADFS-backed token service. I need to hit an endpoint on the API with a C# console application. I am finding a lack of resources for using C# code to access STS secured websites. It uses ADFS 3.0.</p>

<p>When I use an <code>HttpClient</code> (or similar) to hit an endpoint I receive an HTML form in return.</p>

<p>My code:</p>

<pre><code>Uri baseAddress = new Uri("http://localhost:64022");

using (HttpClient client = new HttpClient() { BaseAddress = baseAddress })
{
    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "#");
    HttpResponseMessage response = client.SendAsync(request).Result;

    var encoding = ASCIIEncoding.ASCII;
    using (var reader = new System.IO.StreamReader(response.Content.ReadAsStreamAsync().Result, encoding))
    {
        string responseText = reader.ReadToEnd();
    }
}
</code></pre>

<p>The settings I have in my web.config file for my application are:</p>

<pre><code>&lt;system.identityModel.services&gt;
    &lt;federationConfiguration&gt;
        &lt;cookieHandler requireSsl="false" persistentSessionLifetime="1.0:0:0" /&gt;
        &lt;wsFederation persistentCookiesOnPassiveRedirects="true" passiveRedirectEnabled="true" issuer="https://sts.company.com/adfs/ls/" realm="http://myapp.company.com/" requireHttps="false" /&gt;
    &lt;/federationConfiguration&gt;
&lt;/system.identityModel.services&gt;
&lt;system.identityModel&gt;
    &lt;identityConfiguration&gt;
        &lt;audienceUris&gt;
            &lt;add value="http://myapp.company.com/" /&gt;
        &lt;/audienceUris&gt;
        &lt;issuerNameRegistry&gt;
            &lt;trustedIssuers&gt;
                &lt;add thumbprint="0000000000000000000000000000000000000000" name="https://sts.company.com/adfs/services/trust" /&gt;
            &lt;/trustedIssuers&gt;
        &lt;/issuerNameRegistry&gt;
    &lt;/identityConfiguration&gt;
&lt;/system.identityModel&gt;
</code></pre>

<p>I am not sure what the various terms will be. What will my remote address be? My client id? What is the thumbprint?</p>