Skip to content

Instantly share code, notes, and snippets.

@deskie-io
Created November 30, 2022 20:52
Show Gist options
  • Save deskie-io/c2ce918c9412bb1feccef60213447411 to your computer and use it in GitHub Desktop.
Save deskie-io/c2ce918c9412bb1feccef60213447411 to your computer and use it in GitHub Desktop.
jwt_example.php
<?php
/*
JWT can be downloaded here: https://github.com/firebase/php-jwt
You can also use JWT PEAR package http://pear.php.net/pepr/pepr-proposal-show.php?id=688
*/
include "Authentication/JWT.php";
define('CURRENT_TIME', strtotime(gmdate("M d Y H:i:s").'+0000'));
$payload = array(
"iat" => CURRENT_TIME,
"exp" => CURRENT_TIME+86400,
"email" => 'testuser@gmail.com',
"name" => 'John Foden',
"company_name" => 'Alfastar',
"company_position" => 'PHP Developer',
"remote_photo_url" => 'http://mydomain.com/myimage.jpg',
);
$marker='uMxNpq7WSsUI6KSHPBv1eTLf4X6txCwj';
$subdomain = 'yourcompany';
$encoded = JWT::encode($payload, $marker);
$url = 'http://'.$subdomain.'.deskie.io/access/jwt?jwt='.$encoded;
if(isset($_GET["return_to"])) {
$url .= "&return_to=" . urlencode($_GET["return_to"]);
}
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_TIMEOUT, 60 );
$result = curl_exec( $ch );
$headers = curl_getinfo($ch);
if($headers['http_code']==200) {
header("Location: ".$result);
} else {
echo "Error: ".$result;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment