Your issue is that you are not correctly getting hold of the Authorisation header.
If you are using Apache, then most PHP/Apache distributions come with a built in function apache__request_headers()
.
You can use this as follows:
$headers = apache_request_headers();
if (strtoupper($_SERVER['REQUEST_METHOD']) === "POST"
&& isset($headers['Authorization'])
&& strpos($headers['Authorization'], 'ApplePass') === 0
&& $request[2] === "devices"
&& $request[4] === "registrations") {
$auth_key = str_replace('ApplePass ', '', $headers['Authorization']);
If your distribution does not have the apache_request_headers
function you can replicate it.
if (!function_exists('apache_request_headers')) {
function apache_request_headers() {
foreach($_SERVER as $key=>$value) {
if (substr($key,0,5)=="HTTP_") {
$key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
$out[$key]=$value;
}else{
$out[$key]=$value;
}
}
return $out;
}
}
For Nginx then add the following fastcgi_param
to your config, then you can access the variable with $_SERVER['Authorization']
.
fastcgi_param Authorization $http_authorization;