Last active
December 20, 2016 16:38
-
-
Save sjehutch/52ca17166e06a51fc6333ed7903fcf6a to your computer and use it in GitHub Desktop.
jwt-sample-php
This file contains hidden or 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
// 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. | |
// mobile app initializes zendesk sdk and passes NS user id to zendesk | |
// NS api webhook would be below (assuming php) | |
<?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); | |
echo json_encode(["token" => $jwt]); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change this line echo json_encode([“token”: $jwt]); to
echo json_encode(["token" => $jwt]);