it seems that $_SERVER['PHP_AUTH_USER'] is always empty ?
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "GET /test/index.php/api/v1/appointments?q=erik HTTP/1.1[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "Accept-Encoding: gzip,deflate[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "Authorization: Basic YXV0b2F1dG86YXV0b2F1dG8=[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "Host: www.planjeafspraak.be[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "Connection: Keep-Alive[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "User-Agent: Apache-HttpClient/4.1.1 (java 1.5)[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "HTTP/1.1 401 Unauthorized[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Date: Sun, 19 Jan 2020 07:21:28 GMT[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Server: Apache/2.4.25 (Debian)[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "X-Powered-By: PHP/7.1.28[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "WWW-Authenticate: Basic realm="Easy!Appointments"[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Set-Cookie: csrfCookie=e20298a9083e2453c7c4e6050df94eae; expires=Sun, 19-Jan-2020 09:21:28 GMT; Max-Age=7200; path=/[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Strict-Transport-Security: max-age=31536000; includeSubDomains[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Keep-Alive: timeout=5, max=100[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Connection: Keep-Alive[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Transfer-Encoding: chunked[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Content-Type: text/html; charset=UTF-8[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "26[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "You are not authorized to use the API."
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "0[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "GET /test/index.php/api/v1/appointments?q=erik HTTP/1.1[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "Accept-Encoding: gzip,deflate[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "Authorization: Basic YXV0b2F1dG86YXV0b2F1dG8=[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "Host: www.planjeafspraak.be[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "Connection: Keep-Alive[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "User-Agent: Apache-HttpClient/4.1.1 (java 1.5)[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "Cookie: csrfCookie=e20298a9083e2453c7c4e6050df94eae[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "Cookie2: $Version=1[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:>> "[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "HTTP/1.1 401 Unauthorized[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Date: Sun, 19 Jan 2020 07:21:28 GMT[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Server: Apache/2.4.25 (Debian)[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "X-Powered-By: PHP/7.1.28[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "WWW-Authenticate: Basic realm="Easy!Appointments"[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Set-Cookie: csrfCookie=e20298a9083e2453c7c4e6050df94eae; expires=Sun, 19-Jan-2020 09:21:28 GMT; Max-Age=7200; path=/[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Strict-Transport-Security: max-age=31536000; includeSubDomains[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Keep-Alive: timeout=5, max=99[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Connection: Keep-Alive[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Transfer-Encoding: chunked[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "Content-Type: text/html; charset=UTF-8[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "26[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "You are not authorized to use the API."
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "0[\r][\n]"
- Sun Jan 19 08:21:28 CET 2020:DEBUG:<< "[\r][\n]"
------------------------------------------------------------------------------------------------------------------------------
application/controllers/api/v1/API_V1_Controller.php
-------------------------------------------------------------------------------------------------------------------------------
class API_V1_Controller extends CI_Controller {
/**
* Class Constructor
*
* This constructor will handle the common operations of each API call.
*
* Important: Do not forget to call the this constructor from the child classes.
*
* Notice: At the time being only the basic authentication is supported. Make sure
* that you use the API through SSL/TLS for security.
*/
public function __construct()
{
if ( ! isset($_SERVER['PHP_AUTH_USER']))
{
$this->_requestAuthentication();
return;
}
parent::__construct();
try
{
$username = new NonEmptyText($_SERVER['PHP_AUTH_USER']);
$password = new NonEmptyText($_SERVER['PHP_AUTH_PW']);
$authorization = new \EA\Engine\Api\V1\Authorization($this);
$authorization->basic($username, $password);
}
catch (\Exception $exception)
{
exit($this->_handleException($exception));
}
}
/**
* Sets request authentication headers.
*/
protected function _requestAuthentication()
{
header('WWW-Authenticate: Basic realm="Easy!Appointments"');
header('HTTP/1.0 401 Unauthorized');
exit('You are not authorized to use the API.');
}