Skip to content

Commit c195734

Browse files
authored
Merge pull request #7 from BulkGate/security-token
Security token
2 parents edd0652 + 2492319 commit c195734

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/Settings/Settings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ public function install(bool $update = false): void
117117

118118
public function uninstall(): void
119119
{
120+
$this->delete('static:application_token');
121+
120122
if ($this->load('main:delete_db') ?? false)
121123
{
122124
$this->repository->dropTable();

src/User/Sign.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
use BulkGate\{Plugin\AuthenticateException, Plugin\Debug\Logger, Plugin\Eshop\Configuration, Plugin\InvalidResponseException, Plugin\IO\Connection, Plugin\IO\Request, Plugin\IO\Url, Plugin\Localization\Language, Plugin\Settings\Settings, Plugin\Strict, Plugin\Utils\Jwt};
11-
use function array_merge;
11+
use function array_merge, time;
1212

1313
class Sign
1414
{
@@ -83,7 +83,7 @@ public function in(string $email, string $password, ?string $success_redirect =
8383
$this->settings->set('static:application_token', $response->data['data']['application_token'], ['type' => 'string']);
8484
$this->settings->set('static:synchronize', 0, ['type' => 'int']);
8585

86-
return ['token' => $this->authenticate(true), 'data' => ['redirect' => $success_redirect]];
86+
return ['token' => $this->authenticate(true, ['expire' => time() + 300]), 'data' => ['redirect' => $success_redirect]];
8787
}
8888
catch (InvalidResponseException|AuthenticateException $e)
8989
{
@@ -101,6 +101,6 @@ public function out(string $success_redirect): array
101101
{
102102
$this->settings->delete('static:application_token');
103103

104-
return ['token' => $this->authenticate(true), 'data' => ['redirect' => $success_redirect]];
104+
return ['token' => $this->authenticate(true, ['expire' => time() + 300]), 'data' => ['redirect' => $success_redirect]];
105105
}
106106
}

tests/Settings/SettingsTest.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class SettingsTest extends TestCase
102102
'delete_db' => new Setting(['scope' => 'main', 'key' => 'delete_db', 'type' => 'bool', 'value' => '1']),
103103
]));
104104
$repository->shouldReceive('dropTable')->withNoArgs()->once();
105+
$repository->shouldReceive('remove')->with('static', 'application_token')->once();
105106

106107
Assert::noError(fn () => $settings->uninstall());
107108
}

0 commit comments

Comments
 (0)