4

I want to retrieve the basic authentication credentials from Symfony's HttpFoundation component. A cursory look at the docs reveals nothing; is there a way I can do it?

(I'm using the HttpFoundation component in an application not based on the Symfony framework.)

  • Normally they would be in the request header bag. There used to be a problem as documented here: http://stackoverflow.com/questions/11990388/request-headers-bag-is-missing-authorization-header-in-symfony-2 But I thought it was fixed. – Cerad Dec 03 '16 at 17:11
  • What do you mean by basic auth credentials? In a controller you can just do $this->getUser() – siguy85 Dec 03 '16 at 20:47

1 Answers1

17

The values of $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] can be accessed through an instance of Symfony\Component\HttpFoundation\Request in the following manner:

$username = $request->headers->get('php-auth-user');
$password = $request->headers->get('php-auth-pw');