Created
November 30, 2022 20:52
-
-
Save deskie-io/c2ce918c9412bb1feccef60213447411 to your computer and use it in GitHub Desktop.
jwt_example.php
This file contains 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
<?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