How do you perform a Guzzle POST request with "Basic Auth" for the current user? In my class, I have the following request:

    $rest_response = $client-&gt;post($endpoint, [
      'auth' =&gt; ['admin', 'admin'],
      'body' =&gt; $serialized_entity,
      'headers' =&gt; [
        'Content-Type' =&gt; 'application/hal+json',
        'X-CSRF-Token' =&gt; $token,
      ],
    ]);


It works because I have a user with the username/password as "admin"/"admin", but when that user's password is changed, it won't work anymore, as expected. 

In the logs, I am getting an "access denied" error for the endpoint I am trying to POST to - and the user associated with that error says "Anonymous (not verified)". All other log messages printed out in my controller show the current user's username. 

I am running Drupal core 8.1.9.

The question is - how do I use basic_auth to get the current logged-in user's credentials to be passed into the request?
You were so close  main thing here is the "Authorization" Header ...

 $current_user = \Drupal::currentUser();
 $account = $current_user-&gt;getAccount();

 $username = $account-&gt;name;
 // pass would be hard to get as stored hashed 
 //... so you would need to get a bit tricky to "catch" the users password when they log in... 
 $pass = 'admin';
 $auth = 'Basic '. base64_encode ($username . ':' . $pass);
 $rest_response = $client-&gt;post($endpoint, [
   'body' =&gt; $serialized_entity,
   'headers' =&gt; [
     'Authorization' =&gt; $auth,
     'Content-Type' =&gt; 'application/hal+json',
     'X-CSRF-Token' =&gt; $token,
  ],
]);


And just for fun:

  var basicAuthCredential = username + ":" + password;
  var bace64 =  btoa(basicAuthCredential);
  var Auth =  'Basic ' + bace64;
  fetch(url,{
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
      'Authorization': Auth,
      'X-CSRF-Token': token
    },
    body: JSON.stringify(data)
}).then(response =&gt; response.json())...