Skip to content

Instantly share code, notes, and snippets.

@ocke
Created September 27, 2013 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ocke/6723065 to your computer and use it in GitHub Desktop.
Save ocke/6723065 to your computer and use it in GitHub Desktop.
PHP implementation of SSO with JWT
<?php
// load JWT class
// Class can be found here: https://github.com/firebase/php-jwt
include __DIR__.'/JWT.class.php';
$JWT = new JWT();
// Zendesk provides a timestamp in the get.
$now = (!empty($_GET['timestamp'])) ? $_GET['timestamp'] : time();
// Information array send to zendesk. For all available options see: https://support.zendesk.com/entries/23675367 under: "Table 1. Supported attributes"
// {username} and {email@address} are username/email address of the user you are trying to login.
$payload = array(
"jti" => md5($now . rand()),
"iat" => $now,
"name" => '{username}',
"email" => '{email@address}'
);
// The zendesk SSO token is generated @ zendesk.com under settings/security/end-user
$jwtZD = $JWT->encode($payload, '{zendesk SSO token}');
// Domain is the zendesk domain
header('Location: https://{domain}.zendesk.com/access/jwt?jwt=' . $jwtZD . '&return_to=' . $_GET['return_to']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment