Skip to content

Instantly share code, notes, and snippets.

@ChrisCinelli
Last active December 13, 2015 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisCinelli/4981051 to your computer and use it in GitHub Desktop.
Save ChrisCinelli/4981051 to your computer and use it in GitHub Desktop.
Zendesk PHP integration snippet for Single Sign On (SSO)
/*
* Remote authentication snippet in PHP fro Zendesk
* See: http://www.zendesk.com/support/api/remote-authentication
*/
/* This is the token that you can find or recreate on https://bloomboard.zendesk.com/agent/#/admin/security */
$token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
/* Insert your account prefix here. Ex: yoursite.zendesk.com */
$urlPrefix = "yoursite";
//Name and email are mandatory. The other can be empty strings
$param = array(
'name' => $user['first_name'].' '.$user['last_name'],
'email' => $user['email'],
'external_id' => '',
'organization' => $user['org_id'],
'tags' => '',
'remote_photo_url' => $user['pic'],
//'returnTo' => '',
);
/* Timestamp */
$ts = isset($_GET['timestamp']) ? $_GET['timestamp'] : time();
$param['timestamp'] = $ts;
/* Hash please */
$blob = "{$param['name']}|{$param['email']}|{$param['external_id']}|{$param['organization']}|{$param['tags']}|{$param['remote_photo_url']}|$token|$ts";
$hash = MD5($blob);
$param['hash'] = $hash;
//This can be used as direct link to create/login a user in Zendesk
$sso_url = "https://".$urlPrefix.".zendesk.com/access/remoteauth/?".http_build_query($param);
//Use this line in the login redirect URL
header("Location: ".$sso_url);
@zesda
Copy link

zesda commented Mar 21, 2013

I've got in touch with the dev about this issue but I thought I would include the solution here too; On line 32 you'll need to wrap your http_build_query() method with htmlentities().

The reason for this is that &timestamp resolves to "xtamp" when parsed into a URL. This is due to &times being a HTML character for the multiplication symbol. It's bad practice on Zendesk's part, and I doubt they'll change it now but since there's a lot of PHP integrating with Zendesk I thought an update to your code would help you (and many others) out :)

Best,
~C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment