Last active
December 13, 2015 21:58
-
-
Save ChrisCinelli/4981051 to your computer and use it in GitHub Desktop.
Zendesk PHP integration snippet for Single Sign On (SSO)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ×tamp resolves to "xtamp" when parsed into a URL. This is due to × 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.