1

I'm understanding this has to do with a timezone difference between the library and my server.

I set my PHP scripts to use UTC timezone. I'm really not sure how to fix this problem. There doesn't seem to be too much out there on the internet to fix the problem. I tried changing the leeway of JWT class and I'm still receiving problems. Code is posted below.

<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
date_default_timezone_set('UTC');

include "../../inc/dbinfo.inc";
require '../vendor/vendor/autoload.php';
use \Firebase\JWT\JWT;
JWT::$leeway = 60;
?>

Also I've tried:

JWT:$leeway += 60;

I am using an EC2 instance from Amazon Web Services. I am also using Firebase JWT api to produce the token.

EDIT: If i'm not providing enough information, please let me know. If there's a better way to produce JWT also let me know. I'm having a lot of issues with this library atm.

EDIT-----------------------------------------------------------------------------------------------------------------------------

Here is how I'm creating the token....

date_default_timezone_set('UTC');
use \Firebase\JWT\JWT;

    $currentTimeInMillis = round(microtime(true) * 1000);

        $token = array(
            "iss" => "http://example.org",
            "sub" => $username,
            "iat" => $currentTimeInMillis,
            "exp" => $currentTimeInMillis + 256000000);

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

1 Answers1

0

The problem is in this line:

$currentTimeInMillis = round(microtime(true) * 1000);

If you run this command:

echo date('Y-m-d', round(microtime(true) * 1000));

You see 50901-06-21, which points to your problem. Remove the round part:

$currentTimeInMillis = microtime(true);
Felippe Duarte
  • 14,901
  • 2
  • 25
  • 29
  • Wow thank you Felippe. I honestly have no idea why I didn't think of that. That makes total sense. I got that snippet of code from a highly rated posted. Why in the world was that posted in the first place... https://stackoverflow.com/questions/3656713/how-to-get-current-time-in-milliseconds-in-php –  Dec 06 '18 at 20:32