Я реализую авторизацию oauth2 для нашего приложения, используя keycloak для аутентификации пользователей. Я успешно получаю «код» от keycloak. Я отправляю это обратно в API rest keycloak, чтобы получить токен для пользователя, используя Curl в модуле PHP. Затем я получаю сообщение об ошибке «не удалось подключиться к серверу», однако у меня активны инструменты разработчика Firefox, и это показывает успешное соединение с возвращенным access_token (как и журнал keycloak).
Код: Выделить всё
$ch = curl_init("http://localhost:8080/realms/openemr-local/protocol/openid-connect/token");
$cparams = ['code' => $kc_code, 'grant_type'=>'authorization_code', 'redirect_uri'=>'http://localhost:8300/interface/login/login.php?kc_response=true', 'client_id'=>'openemr'];
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $cparams);
$ch_response = curl_exec($ch);
if( curl_error($ch)) {
echo '
curl error: - ' . curl_error($ch);
echo ' and returned: ' . $ch_response;
}
else {
echo '
got token response: ' . $ch_response;
$json_text = json_decode($ch_response);
echo $json_text->contents . '
';
}
Код: Выделить всё
curl_error
Failed to connect to localhost port 8080 after 0 ms: Couldn't connect to server and returned:
However when I use firefox's developer tools it shows that there was a response from this curl connection, with the data i need. Looking at the keycloak log the call was seen and answered as well.
So my question is:
- how can i get php curl function to indicate there was no error and
- return the correct data
Источник: https://stackoverflow.com/questions/781 ... ow-success