visit wellness : GWM
This commit is contained in:
parent
e6917db425
commit
17afc6a8ea
@ -549,7 +549,7 @@ $routes->post("employeeRest/getPostEmployeeDataForAuth", "RestAuthenticationCont
|
|||||||
$routes->get("employeeRest/getClientDetails", "EmployeeRestController::getClientDetails");
|
$routes->get("employeeRest/getClientDetails", "EmployeeRestController::getClientDetails");
|
||||||
$routes->get("employeeRest/getAdvertisementImage", "EmployeeRestController::getAdvertisementImage");
|
$routes->get("employeeRest/getAdvertisementImage", "EmployeeRestController::getAdvertisementImage");
|
||||||
|
|
||||||
|
$routes->get("getSSORedirectUrl", "ApiServiceController::getSSORedirectUrl");
|
||||||
|
|
||||||
$routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
|
$routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
|
||||||
|
|
||||||
|
|||||||
@ -310,6 +310,87 @@ class ApiServiceController extends BaseController
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function getSSORedirectUrl($email = 'user@example.com')
|
||||||
|
{
|
||||||
|
// ---------- CONFIG ----------
|
||||||
|
$authUrl = env('VIDAL_WELLNESS_BASE_URL'); // Authentication API URL
|
||||||
|
$subscriptionKey = env('VIDAL_WELLNESS_SUBSCRIPTION_KEY');
|
||||||
|
$apiVersion = "1";
|
||||||
|
|
||||||
|
// Provided Base64 AES key
|
||||||
|
$base64Key = env('VIDAL_WELLNESS_BASE64_KEY');
|
||||||
|
$key = base64_decode($base64Key);
|
||||||
|
|
||||||
|
// ---------- STEP 1: Build plaintext payload ----------
|
||||||
|
$plainPayload = json_encode([
|
||||||
|
"email" => $email,
|
||||||
|
"corporateId" => env('VIDAL_WELLNESS_CORPORATE_ID'),
|
||||||
|
"urlIdentifier" => env('VIDAL_WELLNESS_URL_IDENTIFIER')
|
||||||
|
]);
|
||||||
|
|
||||||
|
// ---------- STEP 2: Encrypt payload ----------
|
||||||
|
$iv = random_bytes(16);
|
||||||
|
$encryptedRaw = openssl_encrypt($plainPayload, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $iv);
|
||||||
|
|
||||||
|
$encryptedPayload = base64_encode($iv) . ":" . base64_encode($encryptedRaw);
|
||||||
|
|
||||||
|
// ---------- STEP 3: Call Authentication API ----------
|
||||||
|
$requestBody = json_encode([
|
||||||
|
"payload" => $encryptedPayload,
|
||||||
|
"source" => "portal",
|
||||||
|
"subPartnerId" => env('VIDAL_WELLNESS_SUB_PARTNER_ID')
|
||||||
|
]);
|
||||||
|
|
||||||
|
$headers = [
|
||||||
|
"Ocp-Apim-Subscription-Key: $subscriptionKey",
|
||||||
|
"apiver: $apiVersion",
|
||||||
|
"mode: encrypt",
|
||||||
|
"Content-Type: application/json"
|
||||||
|
];
|
||||||
|
|
||||||
|
$ch = curl_init($authUrl);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
|
||||||
|
$apiResponse = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$jsonResponse = json_decode($apiResponse, true);
|
||||||
|
|
||||||
|
dd($jsonResponse);
|
||||||
|
|
||||||
|
if (!isset($jsonResponse["data"])) {
|
||||||
|
return ["error" => "Invalid API response", "response" => $apiResponse];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ---------- STEP 4: Decrypt response ----------
|
||||||
|
list($ivBase64, $cipherBase64) = explode(":", $jsonResponse["data"]);
|
||||||
|
|
||||||
|
$respIv = base64_decode($ivBase64);
|
||||||
|
$respCipher = base64_decode($cipherBase64);
|
||||||
|
|
||||||
|
$decryptedJson = openssl_decrypt($respCipher, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $respIv);
|
||||||
|
|
||||||
|
$decryptedData = json_decode($decryptedJson, true);
|
||||||
|
|
||||||
|
if (!isset($decryptedData["redirectUrl"])) {
|
||||||
|
return ["error" => "redirectUrl missing", "decrypted" => $decryptedData];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- FINAL ----------
|
||||||
|
return $decryptedData["redirectUrl"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user