title: Can you change Flurl's authentication credentials after a client has been created via DI?
body: <p>I have a service that uses <code>Flurl</code>; the service always sets <code>BasicAuth</code> credentials based on a configuration flag. This is no longer the case, and I need to change the credentials based on data that isn't available when the dependency is provided.</p>
  <p>Is there a way to modify how Flurl authenticates after creating a new client?</p>
  <p>The setup (greatly simplified but sufficient) is as follows:</p>
  <pre><code>public class MyClient : IMyClient, IDisposable
  {
  
      private readonly IFlurlClient _client;
  
      public MyClient(IFlurlClientFactory flurlClientFactory)
      {
          var baseUrl = config.BaseUrl;
          _client = flurlClientFactory
              .Get(new Url(baseUrl))
              .WithBasicAuth(&quot;my&quot;, &quot;credentials&quot;);
      }
  
      public async Task&lt;MyProcessResponse&gt; MyProcess(MyProcessRequest processRequestData)
      {
          var resource = GetProcessResource();
          // I need to change credentials here, based on data within resouce.
          var response = await _client.Request(resource)
              .PostJsonAsync(processRequestData)
              .ReceiveJson&lt;MyProcessResponse&gt;();
  
          return response;
      }
  }
  </code></pre>
  <p>The service is used as such:</p>
  <pre><code>public class Process : IProcess
  {
      private readonly IMyClient _myClient
  
      public Process(IMyClient myClient)
      {
          _myClient = myclient;
      }
  
      private async Task&lt;bool&gt; RunProcess()
      {
          var processRequestData = GetProcessRequestData()
          await _myClient.MyProcess(processRequestData);
          // do stuff
      }
  }
  </code></pre>
  <p>As the environment is no longer the only factor, I need to change/set the credentials based on data defined within <code>processRequestData</code>.</p>
  <p>It is my understanding I shouldn't be creating multiple clients, hence creating the one which has (so far) served its purpose.</p>
  <p>What's the sanest way of achieving this?</p>
  <p>Using the dated .NET 4.8 with MVC with AutoFac handling the DI.</p>