clearFusionCMS can be used to authenticate users for Zendesk, the following describes the process of enabling it in just 4 steps.
Login to your Zendesk to enable single sign-on and get the shared secret you'll need in the next step.
Login to your clearFusionCMS installation that will be authenticating Zendesk users, go to Elements and create a new snippet. Name the snippet zendeskLogin and use the following code:
/**
* THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* package clearFusionCMS
* copyright Copyright (c) 2013 clearFusionCMS. All rights reserved.
* link http://clearfusioncms.com
*/
// Check that the shared key and subdomain have been passed
if(!isset($key) || !isset($subdomain))
return;
// Only run if user authenticated
$user = clearFusionCMS::getUser();
if($user->isAuthenticated()) {
// Create JWT
$now = time();
$token = array(
'jti' => md5($now . rand()),
'iat' => $now,
'external_id' => $user->getId(),
'name' => $user->getUsername(),
'email' => $user->getEmail()
);
// Encode and sign
$segments = array();
$segments[] = str_replace('=', '', strtr(base64_encode(json_encode(array('typ' => 'JWT', 'alg' => 'HS256'))), '+/', '-_'));
$segments[] = str_replace('=', '', strtr(base64_encode(json_encode($token)), '+/', '-_'));
$segments[] = str_replace('=', '', strtr(base64_encode(hash_hmac('sha256', implode('.', $segments), $key, true)), '+/', '-_'));
// Redirect
clearFusionCMS::getResponse()->redirectTo(clearFusionCMS::getSession()->flashGet('zendesk_returnto', 'https://' . $subdomain . '.zendesk.com/access/jwt') . '?jwt=' . implode('.', $segments));
}
else {
if(clearFusionCMS::getRequest()->hasQuery('return_to'))
clearFusionCMS::getSession()->flashSet('zendesk_returnto', clearFusionCMS::getRequest()->getQuery('return_to'));
else
clearFusionCMS::getSession()->flashKeep('zendesk_returnto');
}
Save the snippet.
Head back to the dashboard and select Documents, create a new document which will be the help desk login page making sure that it's in the location that you specified in the Remote login URL field, and add the following to the content:
[[!members.login &loginByUsername=`1` &loginByEmail=`1`]]
[[!zendeskLogin &key=`xxxxxxxxxxxxxxxxxxx` &subdomain=`example`]]
Change xxxxxxxxxxxxxxxxxxx to be the shared secret you recorded when enabling single sign-on and change example to be your zendesk subdomain e.g. if your help desk is at example.zendesk.com then your subdomain will be example. The subdomain is only required as a fallback if something unexpected happens.
Publish the page.
Make sure that you're logged out of clearFusionCMS and Zendesk, then head to your Zendesk subdomain and click login, if everything is working correctly you'll be presented with the login page on your website, login and you should be redirected back to Zendesk.
That's it all done.