Hello there, I have a code in my CI 4.4.1 helper like below :
Code:
function getSsoToken()
{
$curl = Services::curlrequest();
helper('utility');
$apiConfig = getDecodedJson('api_sso_integration.json');
$request = $curl->request('POST', $apiConfig['sso_token_url'], [
'http_errors' => false,
'verify' => false,
'timeout' => 15,
'body' => http_build_query([
'client_id' => $apiConfig['sso_client_id'],
'grant_type' => 'password',
'username' => $apiConfig['sso_username'],
'password' => $apiConfig['sso_password'],
]),
]);
$responseBody = json_decode($request->getBody());
if ($request->getStatusCode() >= 200 && $request->getStatusCode() <= 300) {
return (object) [
'success' => true,
'token' => $responseBody->access_token
];
} else {
return (object) [
'success' => false,
'error' => ($responseBody['error']) ?? 'no error property'
];
}
}
It keeps throws an error, though I have defined
http_errors in the curl options, idk if it is because of
timeout option. If I remove
timeout option, the error may be handled. Is this a bug or maybe it work like that, idk.
Maybe you guys can help, much appreciated for your attention.