Аутентификация CAS получить данные

Я пытаюсь получить информацию о пользователе с сервера, который использует CAS для аутентификации. Я уже могу войти в систему пользователя и получить ключ аутентификации с сервера, но когда я пытаюсь получить пользовательские данные с сервера, я получаю сообщение об ошибке 401.

// Generate time stamp information
date_default_timezone_set('UTC');
$timestamp = date(YmdGis);

// Generate hash key
$hashKey = hash_hmac(SHA1, $cURL . $date, $_SESSION['AuthKey']);

// Initialize and execute cURL
$url = "https://d1m.server.edu/API/v2.0/Student/CourseSections";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: " . $_SESSION['userid'] . ":" . $hashKey . ":" . $timestamp));

if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);

$response = json_decode($result);
if(isset($response->{'StatusCode'}))
{
return "Failed to connect to server with error code " . $response->{'StatusCode'};
exit();
}
else
{
return var_dump($response);
// TODO: print course information in user-friendly format
exit();
}

Этот php-код — это то, что я преобразовал из существующей реализации в Java, которая, как я знаю, работает, найдена здесь:

String cURL = "https://d1m.server.edu/API/v2.0/Student/CourseSections";
SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMddHHmmss");
simpledateformat.setTimeZone(TimeZone.getTimeZone("UTC"));
String date = Authenticate.getUTCdatetimeAsString();
String s2 = cURL + date;
String s3 = "";
String key = Authkey;
s3 = s4 = Authenticate.generateHash(key, String.valueOf(cURL) + date).replace("\n", "");
String userid = u;
HttpGet httpget = new HttpGet(cURL);
httpget.setHeader("Authorization", String.valueOf(userid) + ":" + s4 + ":" + date);
inputstream = defaulthttpclient.execute((HttpUriRequest)httpget).getEntity().getContent();
root = jp.parse((Reader)new InputStreamReader(inputstream));
JsonArray jArray = root.getAsJsonArray();

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector