Skip to content

Instantly share code, notes, and snippets.

@mbarrerar
Forked from ocke/gist:6723065
Created May 8, 2019 21:47
Show Gist options
  • Save mbarrerar/7ed96bade9d245d69ad7f5c4c15bef9e to your computer and use it in GitHub Desktop.
Save mbarrerar/7ed96bade9d245d69ad7f5c4c15bef9e 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