PHP Classes

File: api5/services/JWT/test1.php

Recommend this page to a friend!
  Classes of Santo Nuzzolillo   PHP AJAX REST API 5 Call   api5/services/JWT/test1.php   Download  
File: api5/services/JWT/test1.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: PHP AJAX REST API 5 Call
Execute SQL queries and return JSON responses
Author: By
Last change:
Date: 6 years ago
Size: 4,632 bytes
 

Contents

Class file image Download
<?php

/*
 +-----------------------------------------------------------------------+
 | This file is part of API5 RESTful SQLtoJSON |
 | Copyright (C) 2007-2018, Santo Nuzzolillo |
 | |
 | Licensed under the GNU General Public License version 3 or |
 | any later version with exceptions for skins & plugins. |
 | See the LICENSE file for a full license statement. |
 | |
 | Pduction |
 | Date : 02/16/2018 |
 | Time : 12:47:27 PM |
 | Version: 0.0.1 |
 +-----------------------------------------------------------------------+
 | Author: Santo Nuzzolilo <snuzzolillo@gmail.com> |
 +-----------------------------------------------------------------------+
*/


require_once './Firebase/JWT.php';





$key = "Enfasy";
$token = array(
   
"iss" => "DOSQL"
   
,"sub" => "api5"
   
,"aud" => "developer"
   
,"iat" => time()
    ,
"exp" => time()+ (7 * 24 * 60 * 60) ,"nbf" => 1357000000
       
,"uid" => "developer"
   
,"data" => '{"username":"", "userroles":[1,2]}'
);


$jwt = JWT::encode($token, $key);

echo
"Print Encode<br>\n";
echo
$jwt."\n<br>";
$decoded = JWT::decode($jwt, $key, array('HS256'));

echo
"Print decoded<br>\n";
print_r($decoded);



echo
"Print decoded Array<br>\n";

$decoded_array = (array) $decoded;
print_r($decoded_array);



JWT::$leeway = 60; $decoded = JWT::decode($jwt, $key, array('HS256'));
echo
"Encode:\n" . print_r($jwt, true) . "\n";
echo
"\n"
?>
Example with RS256 (openssl)
<?php

/*
 +-----------------------------------------------------------------------+
 | This file is part of API5 RESTful SQLtoJSON |
 | Copyright (C) 2007-2018, Santo Nuzzolillo |
 | |
 | Licensed under the GNU General Public License version 3 or |
 | any later version with exceptions for skins & plugins. |
 | See the LICENSE file for a full license statement. |
 | |
 | Pduction |
 | Date : 02/16/2018 |
 | Time : 12:47:27 PM |
 | Version: 0.0.1 |
 +-----------------------------------------------------------------------+
 | Author: Santo Nuzzolilo <snuzzolillo@gmail.com> |
 +-----------------------------------------------------------------------+
*/






$privateKey = <<<EOD
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQC8kGa1pSjbSYZVebtTRBLxBz5H4i2p/llLCrEeQhta5kaQu/Rn
vuER4W8oDH3+3iuIYW4VQAzyqFpwuzjkDI+17t5t0tyazyZ8JXw+KgXTxldMPEL9
5+qVhgXvwtihXC1c5oGbRlEDvDF6Sa53rcFVsYJ4ehde/zUxo6UvS7UrBQIDAQAB
AoGAb/MXV46XxCFRxNuB8LyAtmLDgi/xRnTAlMHjSACddwkyKem8//8eZtw9fzxz
bWZ/1/doQOuHBGYZU8aDzzj59FZ78dyzNFoF91hbvZKkg+6wGyd/LrGVEB+Xre0J
Nil0GReM2AHDNZUYRv+HYJPIOrB0CRczLQsgFJ8K6aAD6F0CQQDzbpjYdx10qgK1
cP59UHiHjPZYC0loEsk7s+hUmT3QHerAQJMZWC11Qrn2N+ybwwNblDKv+s5qgMQ5
5tNoQ9IfAkEAxkyffU6ythpg/H0Ixe1I2rd0GbF05biIzO/i77Det3n4YsJVlDck
ZkcvY3SK2iRIL4c9yY6hlIhs+K9wXTtGWwJBAO9Dskl48mO7woPR9uD22jDpNSwe
k90OMepTjzSvlhjbfuPN1IdhqvSJTDychRwn1kIJ7LQZgQ8fVz9OCFZ/6qMCQGOb
qaGwHmUK6xzpUbbacnYrIM6nLSkXgOAwv7XXCojvY614ILTK3iXiLBOxPu5Eu13k
eUz9sHyD6vkgZzjtxXECQAkp4Xerf5TGfQXGXhxIX52yH+N2LtujCdkQZjXAsGdm
B2zNzvrlgRmgBrklMTrMYgm1NPcW+bRLGcwgW2PTvNM=
-----END RSA PRIVATE KEY-----
EOD;

$publicKey = <<<EOD
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8kGa1pSjbSYZVebtTRBLxBz5H
4i2p/llLCrEeQhta5kaQu/RnvuER4W8oDH3+3iuIYW4VQAzyqFpwuzjkDI+17t5t
0tyazyZ8JXw+KgXTxldMPEL95+qVhgXvwtihXC1c5oGbRlEDvDF6Sa53rcFVsYJ4
ehde/zUxo6UvS7UrBQIDAQAB
-----END PUBLIC KEY-----
EOD;


$jwt = JWT::encode($token, $privateKey, 'RS256');
echo
"Encode:\n" . print_r($jwt, true) . "\n";

$decoded = JWT::decode($jwt, $publicKey, array('RS256'));



$decoded_array = (array) $decoded;
echo
"Decode:\n" . print_r($decoded_array, true) . "\n";
?>