From ee031fb7588bf350e88d550ebe85054a0e3cb8bb Mon Sep 17 00:00:00 2001 From: Rob DiMarco Date: Mon, 18 May 2015 14:38:18 -0700 Subject: [PATCH] Reset clock skew / leeway after relevant tests & update README --- README.md | 8 ++++---- tests/JWTTest.php | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bda2d96b..d94b40ab 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,12 @@ $decoded_array = (array) $decoded; /** * You can add a leeway to account for when there is a clock skew times between - * the signing and verifying servers. It is recomended this leeway should not - * be bigger than a few minutes. + * the signing and verifying servers. It is recommended that this leeway should + * not be bigger than a few minutes. + * * Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef */ - -JWT::$leeway = 60; +JWT::$leeway = 60; // $leeway in seconds $decoded = JWT::decode($jwt, $key, array('HS256')); ?> diff --git a/tests/JWTTest.php b/tests/JWTTest.php index da9975c0..e8f510f2 100644 --- a/tests/JWTTest.php +++ b/tests/JWTTest.php @@ -84,6 +84,7 @@ public function testValidTokenWithLeeway() $encoded = JWT::encode($payload, 'my_key'); $decoded = JWT::decode($encoded, 'my_key', array('HS256')); $this->assertEquals($decoded->message, 'abc'); + JWT::$leeway = 0; } public function testExpiredTokenWithLeeway() @@ -96,6 +97,7 @@ public function testExpiredTokenWithLeeway() $encoded = JWT::encode($payload, 'my_key'); $decoded = JWT::decode($encoded, 'my_key', array('HS256')); $this->assertEquals($decoded->message, 'abc'); + JWT::$leeway = 0; } public function testValidTokenWithList() @@ -129,6 +131,7 @@ public function testValidTokenWithNbfLeeway() $encoded = JWT::encode($payload, 'my_key'); $decoded = JWT::decode($encoded, 'my_key', array('HS256')); $this->assertEquals($decoded->message, 'abc'); + JWT::$leeway = 0; } public function testInvalidTokenWithNbfLeeway() @@ -140,6 +143,7 @@ public function testInvalidTokenWithNbfLeeway() $encoded = JWT::encode($payload, 'my_key'); $this->setExpectedException('BeforeValidException'); $decoded = JWT::decode($encoded, 'my_key', array('HS256')); + JWT::$leeway = 0; } public function testValidTokenWithIatLeeway() @@ -151,6 +155,7 @@ public function testValidTokenWithIatLeeway() $encoded = JWT::encode($payload, 'my_key'); $decoded = JWT::decode($encoded, 'my_key', array('HS256')); $this->assertEquals($decoded->message, 'abc'); + JWT::$leeway = 0; } public function testInvalidTokenWithIatLeeway() @@ -162,6 +167,7 @@ public function testInvalidTokenWithIatLeeway() $encoded = JWT::encode($payload, 'my_key'); $this->setExpectedException('BeforeValidException'); $decoded = JWT::decode($encoded, 'my_key', array('HS256')); + JWT::$leeway = 0; } public function testInvalidToken()