Exemple #1
0
 private static function jsonDecode($input)
 {
     if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {
         $object = json_decode($input, false, 512, JSON_BIGINT_AS_STRING);
     } else {
         $maxIntLength = strlen((string) PHP_INT_MAX) - 1;
         $jsonWithoutBigints = preg_replace('/:\\s*(-?\\d{' . $maxIntLength . ',})/', ': "$1"', $input);
         $object = json_decode($jsonWithoutBigints);
     }
     if (function_exists('json_last_error') && ($errno = json_last_error())) {
         JWT::handleJsonError($errno);
     } elseif ($object === null && $input !== 'null') {
         throw new DomainException('Null result with non-null input');
     }
     return $object;
 }
Exemple #2
0
<?php

define('APP_PATH', dirname(__FILE__));
define('APP_NAME', 'Sample');
use JWT\JWT;
use CBase\Query\Query;
$libConfig = ['pdo' => new PDO('mysql:host=127.0.0.1;dbname=dbname', 'dbuser', 'dbpassword'), 'apikey' => 'secret'];
$jwt = new JWT();
$jwt->setIssuer('http://localhost')->setAudience('http://localhost')->setIssuedAt(time())->sign($libConfig['apikey'])->getToken();
$db = new Query($libConfig);
return ['db' => $db, 'jwt' => $jwt, 'apikey' => &$libConfig['apikey']];
Exemple #3
0
<?php

require 'vendor/autoload.php';
use JWT\JWT;
$jwt = new JWT();
$jwt->setIssuer('http://example.com')->setAudience('http://example.org')->setIssuedAt(time())->setNotBefore(time() + 60)->sign('secret')->getToken();
var_dump($jwt->verifyToken('secret'));
var_dump($jwt->getHeader('typ'), $jwt->getClaim('iss'));