I'm trying to access the Azure DevOps REST API via php/curl and a personal access token, but am having trouble with the authentication process.
The documentation states, that the pat has to be converted to base64 and then added to the HTTP Header, however I have been unable to correctly do that. This is what I've tried:
function GetBuilds($url, $token) {
$ci = curl_init();
curl_setopt($ci, CURLOPT_URL, $url);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ci, CURLOPT_TIMEOUT, 30);
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ci, CURLOPT_HTTPHEADER, array(
"content-type: text/html",
"content-length: 0",
"Authorization: Basic ".base64_encode($token) // Several variants have been tried.
)
);
$buffer = curl_exec($ci);
curl_close($ci);
return $buffer;
};
$url is the Link to the DevOps API which works when called with a browser (after logging in), however when the page with this function is called, it returns the string "Object moved to here." with "here" beeing a link to the microsoft online login page.
CURLOPT_FOLLOWLOCATION
– AbraCadaver:
before being B64 encoded. Not sure if you're doing that. – Daniel Mann