Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Jira Basic Authentification via PHP/CURL

Klaus Haberkorn
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 18, 2019

While trying to get Search Results from Jira I get the following error message (while curl does not report any error):

HTTP/2 401 server: nginx date: Tue, 18 Jun 2019 12:49:55 GMT content-type: text/html;charset=UTF-8 x-arequestid: 895x15999953x1 x-xss-protection: 1; mode=block x-content-type-options: nosniff x-frame-options: SAMEORIGIN content-security-policy: frame-ancestors 'self' x-asen: SEN-8414684 x-seraph-loginreason: AUTHENTICATED_FAILED www-authenticate: OAuth realm="https%3A%2F%2FOURSERVER.com"

Unauthorized (401)

Encountered a "401 - Unauthorized" error while loading this page.

Basic Authentication Failure - Reason : AUTHENTICATED_FAILED

Here is my PHP (v.7.3 on IIS) code:

<?php
$restUser = 'XXX';
$restPass = 'YYY';
$restSearch = 'jql=filter=12789';
$restMax = 10;
$restGET ="https://OURSERVER/rest/api/2/search?$restSearch&maxResults=$restMax";
$connMsg = "Verbindung zu Jira REST Api via curl ";
$connObject = false;
$connInfo = '';
$connCtr = 0;
$connJson = '';
$connResult = '';
// lets go:
$connHeader = array();
$connHeader[] = "Authorization: Basic ".base64_encode($restUser.":".$restPass);
$connHeader[] = "Content-Type: application/json";
$conn = curl_init();
curl_setopt($conn,CURLOPT_URL,$restGET);
curl_setopt($conn,CURLOPT_RETURNTRANSFER,1);
curl_setopt($conn,CURLOPT_HEADER,true);
curl_setopt($conn,CURLOPT_HTTPHEADER,$connHeader);
curl_setopt($conn,CURLOPT_CAINFO,'C:\...\cert\cacert.pem'); // from: https://curl.haxx.se/ca/cacert.pem
// curl_setopt($conn,CURLOPT_SSL_VERIFYPEER,false); // disable SSL Verification (dirty)
$connJson = curl_exec($conn);
if(!curl_errno($conn)){
$connInfo = curl_getinfo($conn);
$connMsg .= "ok, Zeichenanzahl = ".strlen($connJson).' ('.$connInfo['total_time'].' Sek.)';
$connMsg .= '<br>Abfrageergebnis: ';
$connResult = $connJson;
} else {
$connMsg .= 'FEHLER:<br>'.curl_error($conn);
}
curl_close($conn);
?>
<html>
<body>
<h1>Jira REST Testseite (curl)</h1>
<h2><?php echo $connMsg;?></h2>
<p><?php echo $connResult;?></p>
</body>
</html>

Same works fine when I do a PHP file_get_contents and include Username and Password in the Url. Also it ist 100% sure that the sent credentials are valid.

What does the errormessage mean:

Is the Authentification Method not allowed on the server?

Thanks for any help!

1 answer

1 accepted

0 votes
Answer accepted
Aleksandr Zuevich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 18, 2019

Suggest an answer

Log in or Sign up to answer