title: How to add bearer token authentication to typed HttpClient in Asp.Net Core 6
body: <p>I'm trying to setup a web api using ASP.Net Core 6 so that users can hit my end points and then I do some work in D365 behind the scenes using a privileged account. I'm using a typed HTTP Client, but I'm not sure how to plugin the bearer authentication so that all the requests from this client have the correct Authorization header attached.</p>
  <p>Program.cs</p>
  <pre><code>builder.Services.AddHttpClient&lt;D365Service&gt;();
  </code></pre>
  <p>D365Service.cs</p>
  <pre><code>private readonly HttpClient httpClient;
  
  public D365Service(HttpClient httpClient)
  {
    this.httpClient = httpClient;
  
    this.httpClient.DefaultRequestHeaders.Add(&quot;Accept&quot;, &quot;*/*&quot;);
    this.httpClient.DefaultRequestHeaders.Add(&quot;Accept-Encoding&quot;, &quot;gzip, deflate, br&quot;);
    // a whole bunch of other headers
    // Is this where I can add in the bearer Authorization header? How do I generate that token?
  }
  </code></pre>
  <p>Any help is appreciated. Thanks.</p>