diff --git a/app/Controllers/SamlController.php b/app/Controllers/SamlController.php index fc3530c..79284c5 100644 --- a/app/Controllers/SamlController.php +++ b/app/Controllers/SamlController.php @@ -5,6 +5,7 @@ namespace App\Controllers; use App\Models\SamlClientModel; use App\Helpers\JWTToken; use App\Helpers\RestAuthHelper; +use App\Controllers\RestAuthenticationController; use OneLogin\Saml2\Auth as SamlAuth; use OneLogin\Saml2\Error as SamlError; use OneLogin\Saml2\Settings as SamlSettings; @@ -189,14 +190,33 @@ class SamlController extends BaseController $postEnrollment = ['status' => 'failed', 'code' => 404, 'data' => '']; if (! empty($empdata['post'])) { - $postData = $empdata['post']; - unset($postData['employee_id']); - $postData['token_type'] = 'post'; - $postEnrollment = [ - 'status' => 'success', - 'code' => 200, - 'data' => JWTToken::encode($postData), - ]; + $postId = $empdata['post']['id'] ?? $empdata['post']['employee_id'] ?? null; + if ($postId !== null && $postId !== '') { + $restAuth = new RestAuthenticationController(); + $endpoint = env('POST_ENROLLMENT_BASEURL', 'getTokenforSamulssOAuthLogin'); + $rawBody = $restAuth->callThirdPartyGETAPI( + ['id' => $postId], + $endpoint + ); + $api = is_string($rawBody) ? json_decode($rawBody, true) : null; + if (is_array($api) + && (($api['status'] ?? '') === 'success' || (int) ($api['code'] ?? 0) === 200) + && isset($api['data']) + && $api['data'] !== '' + ) { + $postEnrollment = [ + 'status' => 'success', + 'code' => 200, + 'data' => is_string($api['data']) ? $api['data'] : (string) $api['data'], + ]; + } else { + $postEnrollment = [ + 'status' => 'failed', + 'code' => (int) ($api['code'] ?? 404), + 'data' => '', + ]; + } + } } if (empty($empdata)) {