forked from zendesk/zendesk_jwt_sso_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp_jwt.php
30 lines (23 loc) · 773 Bytes
/
php_jwt.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Using JWT from PHP requires you to first either install the JWT PEAR package from
// http://pear.php.net/pepr/pepr-proposal-show.php?id=688 or get the JWT project
// from https://github.com/firebase/php-jwt on GitHub.
<?php
include_once "Authentication/JWT.php";
// Log your user in.
$key = "{my zendesk shared key}";
$subdomain = "{my zendesk subdomain}";
$now = time();
$token = array(
"jti" => md5($now . rand()),
"iat" => $now,
"name" => $user->name,
"email" => $user->email
);
$jwt = JWT::encode($token, $key);
$location = "https://" . $subdomain . ".zendesk.com/access/jwt?jwt=" . $jwt;
if(isset($_GET["return_to"])) {
$location .= "&return_to=" . urlencode($_GET["return_to"]);
}
// Redirect
header("Location: " . $location);
?>