Overriding 'user.login.http' method I am trying to override the core login method in Drupal\user\Controller\UserAuthenticationController by extending the UserAuthenticationController class so that I can inject custom data into the response object. I could achieve override by creating an Event subscriber service and using the alterRoutes method. 

 public function login(Request $request) {
     $response_data = parent::login($request);

      return $response_data;

  }


However the response data is an object of type Symfony\Component\HttpFoundation\Response and there is absolutely no way to access the data. I would like to do the following but not able to modify the response object. 

 public function login(Request $request) {
     $response_data = parent::login($request);
     $response_date = $this-&gt;fetchCustomdata($response_data);
     return $response_data;

  }

  private function fetchCustomdata($response_data) {
   // Do some work and return modified $response_dat
   return $reponse_data
 }


Is there any better way to inject custom data into the response parameters? 

Note: The additional data I am trying to inject is additional fields i have added to the user profile like First Name, Email and other reference fields. It is required to deliver these along with the other default responses along with the default response on login. 

Note: I tried copying the original method and modifying the data and it works but it goes against the good practice as we are trying to reduce duplication.
I figured out how to actually do this. We need to go to the class from which the object was instantiated and figured out any public getter and setter methods. This should be obvious for someone well versed with OOPs. Here is I managed to modify the response. 

public function login(Request $request) {
  $response_data = parent::login($request);

  // We need to get data in the original response and there is actually a 
  // a public method provided by the parent class getContent which we are using
  // below.
  $mydata = $response_data-&gt;getContent();

  // Original data is serialized so we need to decode it. 
  $decoded_data = $this-&gt;serializer-&gt;decode($mydata, 'json');
  $uid = $decoded_data['current_user']['uid'];
  $user = $this-&gt;userStorage-&gt;load($uid);

  // custom function to process the user
  $mynewdata = $this-&gt;customfunction($user);

  // Adding to the original decoded response array and
  // then encoding again. 
  $decoded_data += $mynewdata;
  $combined data = $this-&gt;serializer-&gt;encode($decoded_data, 'json');

  // Setting the content to the origina response object. Important!!!
  $response_data-&gt;setContent($encoded_sponsor_data);
  return $response_data;
}