I have an web application through which users access the zendesk portal
Previous Code
$now = time();
$token = array(
"jti" => md5($now . rand()),
"iat" => $now,
"name" => $name
"email" => $email
);
$jwt = JWT::encode($token, ZendeskJWT::$key, 'HS256');
$url = "https://mysubdomain.zendesk.com/access/jwt?jwt=" . $jwt;
if ('' == $returnTo) {
$location = $url;
}
$location = $url . '&return_to=' . $returnTo;
header("Location: " . $location);
exit;
Current code
$now = time();
$token = array(
"jti" => md5($now . rand()),
"iat" => $now,
"name" => $name
"email" => $email
);
$jwt = JWT::encode($token, ZendeskJWT::$key, 'HS256');
$ch = curl_init();
$postData = json_encode([
'jwt' =>jwt,
'return_to' => ‘https://mysubdomain.zendesk.com’
]);
$headers = array(
"Content-Type: application/json",
);
curl_setopt_array($ch, array(
CURLOPT_URL => 'https://mysubdomain.zendesk.com/access/jwt',
CURLOPT_POST => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_MAXREDIRS => 10,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $postData,
CURLOPT_HTTPHEADER => $headers,
));
$response = curl_exec($ch);
if ($response && ($curlHttpCode == 200 || $curlHttpCode == 302)) {
$location = ‘https://mysubdomain.zendesk.com’;
header("Location: " . $location);
exit;
}
But the current code does not make me login to zendesk
when I redirect the user to return url on success it takes me back to my application as
https://my-app-admin.eventscloud.com/zendesk_sso.php?brand_id=10****20&locale_id=1&return_to=https%3A%2F%mysubdomain.zendesk.com%2Fagent×tamp=1720694748
Can you please explain why?