summaryrefslogtreecommitdiffstats
path: root/Authentication/JWT.php
diff options
context:
space:
mode:
authorLuis Miguel Cabral <luis.miguel.cabral@pearson.com>2015-05-11 12:20:39 +0200
committerLuis Miguel Cabral <luis.miguel.cabral@pearson.com>2015-05-11 12:20:39 +0200
commit95fa9ae8ff71e3fc697befda39d9530cc15e5e8e (patch)
tree0731bdbf757345a466484ffa50639440e44b04c3 /Authentication/JWT.php
parent61ff1780af6a0200f18711d897a52eb1aa53729d (diff)
downloadphp-jwt-95fa9ae8ff71e3fc697befda39d9530cc15e5e8e.zip
php-jwt-95fa9ae8ff71e3fc697befda39d9530cc15e5e8e.tar.gz
php-jwt-95fa9ae8ff71e3fc697befda39d9530cc15e5e8e.tar.bz2
Changed the leeway to be a static variable
Diffstat (limited to 'Authentication/JWT.php')
-rw-r--r--Authentication/JWT.php12
1 files changed, 7 insertions, 5 deletions
diff --git a/Authentication/JWT.php b/Authentication/JWT.php
index 5f319e3..e65dc50 100644
--- a/Authentication/JWT.php
+++ b/Authentication/JWT.php
@@ -17,9 +17,11 @@ class JWT
{
/**
- * When cheking nbf, iat or expiration times, we want to provide some extra leeway time to account for clock skew.
+ * When checking nbf, iat or expiration times,
+ * we want to provide some extra leeway time to
+ * account for clock skew.
*/
- const LEEWAYTIME = 60;
+ public static $leeway = 0;
public static $supported_algs = array(
'HS256' => array('hash_hmac', 'SHA256'),
@@ -86,7 +88,7 @@ class JWT
// Check if the nbf if it is defined. This is the time that the
// token can actually be used. If it's not yet that time, abort.
- if (isset($payload->nbf) && $payload->nbf > (time() + self::LEEWAYTIME)) {
+ if (isset($payload->nbf) && $payload->nbf > (time() + self::$leeway)) {
throw new BeforeValidException(
'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->nbf)
);
@@ -95,14 +97,14 @@ class JWT
// Check that this token has been created before 'now'. This prevents
// using tokens that have been created for later use (and haven't
// correctly used the nbf claim).
- if (isset($payload->iat) && $payload->iat > (time() + self::LEEWAYTIME)) {
+ if (isset($payload->iat) && $payload->iat > (time() + self::$leeway)) {
throw new BeforeValidException(
'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->iat)
);
}
// Check if this token has expired.
- if (isset($payload->exp) && (time() - self::LEEWAYTIME) >= $payload->exp) {
+ if (isset($payload->exp) && (time() - self::$leeway) >= $payload->exp) {
throw new ExpiredException('Expired token');
}
}