Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow changing JWT leeway parameter #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/MessageBird/RequestValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,27 @@ class RequestValidator
*/
private $skipURLValidation;

/**
* Allows the JWT token to be that many seconds after the expiration date
* without being considered it expired. Useful to account for server
* clocks being slightly out of sync or for integration testing with
* a known good token. Should be kept reasonably low in production.
*
* @var int
*/
private $leewaySeconds;

/**
* RequestValidator constructor.
*
* @param string $signingKey customer signature key. Can be retrieved through <a href="https://dashboard.messagebird.com/developers/settings">Developer Settings</a>. This is NOT your API key.
* @param bool $skipURLValidation whether url_hash claim validation should be skipped. Note that when true, no query parameters should be trusted.
*/
public function __construct(string $signingKey, bool $skipURLValidation = false)
public function __construct(string $signingKey, bool $skipURLValidation = false, int $leewaySeconds = 1)
{
$this->signingKey = $signingKey;
$this->skipURLValidation = $skipURLValidation;
$this->leewaySeconds = $leewaySeconds;
}

/**
Expand Down Expand Up @@ -139,7 +150,7 @@ public function validateSignature(string $signature, string $url, string $body)
throw new ValidationException("URL cannot be empty");
}

JWT::$leeway = 1;
JWT::$leeway = $this->leewaySeconds;
try {
$headb64 = \explode('.', $signature)[0];
$headerRaw = JWT::urlsafeB64Decode($headb64);
Expand Down