mirror of
https://github.com/RobThree/TwoFactorAuth.git
synced 2026-08-28 02:57:17 +00:00
* You can now specify the expected time format returned by a 3rd party to the HttpTimeProvider.
This commit is contained in:
@@ -9,11 +9,12 @@ class HttpTimeProvider implements ITimeProvider
|
||||
{
|
||||
public $url;
|
||||
public $options;
|
||||
public $expectedtimeformat;
|
||||
|
||||
function __construct($url = 'https://google.com', array $options = null)
|
||||
function __construct($url = 'https://google.com', $expectedtimeformat = 'D, d M Y H:i:s O+', array $options = null)
|
||||
{
|
||||
$this->url = $url;
|
||||
|
||||
$this->expectedtimeformat = $expectedtimeformat;
|
||||
$this->options = $options;
|
||||
if ($this->options === null) {
|
||||
$this->options = array(
|
||||
@@ -41,7 +42,7 @@ class HttpTimeProvider implements ITimeProvider
|
||||
|
||||
foreach ($headers['wrapper_data'] as $h) {
|
||||
if (strcasecmp(substr($h, 0, 5), 'Date:') === 0)
|
||||
return \DateTime::createFromFormat('D, d M Y H:i:s O+', trim(substr($h,5)))->getTimestamp();
|
||||
return \DateTime::createFromFormat($this->expectedtimeformat, trim(substr($h,5)))->getTimestamp();
|
||||
}
|
||||
throw new \TimeException(sprintf('Unable to retrieve time from %s (Invalid or no "Date:" header found)', $this->url));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user