群组RESTful API无法连接

时间:2015-05-18 18:16:20

标签: php rest atlassian-crowd

我正在尝试将Crowd身份验证用于我的网站,但我一直在使401应用程序无法进行身份验证。我不知道为什么,因为我正确地传递了应用程序的用户名和密码。我有什么:

$data = array("value" => "APP_PASS");
$data_string = json_encode($data);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://PATH:8095/crowd/rest/usermanagement/2/authentication?username=APP_NAME');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string),
    'Accept: application/json'
    )                                                                       
);      

$output = curl_exec($ch);

echo $output;

curl_close($ch);

1 个答案:

答案 0 :(得分:0)

您需要为应用程序用户使用CURLOPT_HTTPAUTH和CURLOPT_USERPWD:密码。 Crowd对请求的应用程序使用ACL以及您请求的用户身份验证。

curl -i -u 'APP_USER:APP_PASS' --data '{"value": "USER_PASS"}' https://SERVER_URL/crowd/rest/usermanagement/1/authentication?username=USER_ID --header 'Content-Type: application/json' --header 'Accept: application/json'