Skip to content

Commit

Permalink
Merge pull request #164 from SocialConnect/issue-163
Browse files Browse the repository at this point in the history
Fix nounce check when system's timezone in not UTC.
  • Loading branch information
ADmad authored Oct 17, 2021
2 parents e5cf45c + 5fc570c commit 725a1ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/OpenID/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function splitNonce(string $nonce): int
list(,$year, $month, $day, $hour, $min, $sec) = $matches;

try {
$timestamp = new \DateTime();
$timestamp = new \DateTime('now', new \DateTimeZone('UTC'));
$timestamp->setDate((int) $year, (int) $month, (int) $day);
$timestamp->setTime((int) $hour, (int) $min, (int) $sec);
} catch (\Throwable $e) {
Expand Down
5 changes: 5 additions & 0 deletions tests/Test/OpenID/Provider/AbstractProviderTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public function testGetAccessTokenByRequestParametersSuccess()
$time = new \DateTime();
$time->setTimestamp(time() - 10);

$timezone = date_default_timezone_get();
date_default_timezone_set('Asia/Tokyo');

$oauthToken = $this->getProvider($mockedHttpClient)->getAccessTokenByRequestParameters([
'openid_ns' => 'http://specs.openid.net/auth/2.0',
'openid_op_endpoint' => 'https://steamcommunity.com/openid/login',
Expand All @@ -143,6 +146,8 @@ public function testGetAccessTokenByRequestParametersSuccess()
'openid_sig' => 'test',
]);

date_default_timezone_set($timezone);

parent::assertSame(
'76561198066894048',
$oauthToken->getUserId()
Expand Down

0 comments on commit 725a1ec

Please sign in to comment.