Skip to content

Instantly share code, notes, and snippets.

@ChrisCinelli
Forked from sbkinney/zendesk_sso_basic.php
Last active December 13, 2015 21:49
Show Gist options
  • Save ChrisCinelli/4980381 to your computer and use it in GitHub Desktop.
Save ChrisCinelli/4980381 to your computer and use it in GitHub Desktop.
/*
* 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