Skip to content

Commit 06d0309

Browse files
committed
Adding Symfony Uid on User::uid
1 parent a1b14b7 commit 06d0309

File tree

6 files changed

+41
-9
lines changed

6 files changed

+41
-9
lines changed

Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
dev\:fixtures:
3+
php bin/console doctrine:database:drop --if-exists --force
4+
php bin/console doctrine:database:create
5+
php bin/console doctrine:schema:create
6+
php bin/console doctrine:fixtures:load --append
7+
php bin/console cache:clear
8+
9+
test\:fixtures:
10+
php bin/console doctrine:database:drop --if-exists --force --env=test
11+
php bin/console doctrine:database:create --env=test
12+
php bin/console doctrine:schema:create --env=test
13+
php bin/console doctrine:fixtures:load --append --env=test
14+
php bin/console cache:clear --env=test
15+
16+
clear:
17+
php bin/console cache:clear

config/packages/uid.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
uid:
3+
default_uuid_version: 7
4+
time_based_uuid_version: 7

config/services.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
parameters:
77
app.admin_email: '%env(resolve:ADMIN_EMAIL)%'
88
app.from_email: '%env(resolve:FROM_EMAIL)%'
9+
app.timezone: '%env(resolve:APP_TIMEZONE)%'
910
jwt.secret: '%env(resolve:JWT_SECRET)%'
1011
jwt.iss: '%env(resolve:JWT_ISS)%'
1112
jwt.algorithm: '%env(resolve:JWT_ALGORITHM)%'

src/Controller/Api/ApiLoginController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function login(Request $request)
4343
return $this->json([
4444
"username" => $username,
4545
"token" => $jwtToken,
46-
'expire_at' => $expireAt->format('Y-m-d H:i:s')
46+
'expire_at' => $expireAt->format('c')
4747
]);
4848
} else {
4949
return $this->json(['error' => 'User or password is not match']);

src/Kernel.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,33 @@ class Kernel extends BaseKernel
1111
{
1212
use MicroKernelTrait;
1313

14+
public function boot()
15+
{
16+
parent::boot();
17+
date_default_timezone_set($this->getContainer()->getParameter('app.timezone'));
18+
}
19+
1420
protected function configureContainer(ContainerConfigurator $container): void
1521
{
1622
$container->import('../config/{packages}/*.yaml');
17-
$container->import('../config/{packages}/'.$this->environment.'/*.yaml');
23+
$container->import('../config/{packages}/' . $this->environment . '/*.yaml');
1824

19-
if (is_file(\dirname(__DIR__).'/config/services.yaml')) {
25+
if (is_file(\dirname(__DIR__) . '/config/services.yaml')) {
2026
$container->import('../config/{services}.yaml');
21-
$container->import('../config/{services}_'.$this->environment.'.yaml');
22-
} elseif (is_file($path = \dirname(__DIR__).'/config/services.php')) {
27+
$container->import('../config/{services}_' . $this->environment . '.yaml');
28+
} elseif (is_file($path = \dirname(__DIR__) . '/config/services.php')) {
2329
(require $path)($container->withPath($path), $this);
2430
}
2531
}
2632

2733
protected function configureRoutes(RoutingConfigurator $routes): void
2834
{
29-
$routes->import('../config/{routes}/'.$this->environment.'/*.yaml');
35+
$routes->import('../config/{routes}/' . $this->environment . '/*.yaml');
3036
$routes->import('../config/{routes}/*.yaml');
3137

32-
if (is_file(\dirname(__DIR__).'/config/routes.yaml')) {
38+
if (is_file(\dirname(__DIR__) . '/config/routes.yaml')) {
3339
$routes->import('../config/{routes}.yaml');
34-
} elseif (is_file($path = \dirname(__DIR__).'/config/routes.php')) {
40+
} elseif (is_file($path = \dirname(__DIR__) . '/config/routes.php')) {
3541
(require $path)($routes->withPath($path), $this);
3642
}
3743
}

src/Security/AccessTokenHandler.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1010
use Firebase\JWT\JWT;
1111
use Firebase\JWT\Key;
12-
use DomainException;
12+
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
1313

1414
class AccessTokenHandler implements AccessTokenHandlerInterface
1515
{
@@ -27,6 +27,10 @@ public function getUserBadgeFrom(string $accessToken): UserBadge
2727
new Key($this->parameterBag->get('jwt.secret'), $this->parameterBag->get('jwt.algorithm'))
2828
);
2929

30+
if ((new \DateTimeImmutable())->setTimestamp($decoded->exp) < new \DateTimeImmutable()) {
31+
throw new CustomUserMessageAuthenticationException('Token Expired');
32+
}
33+
3034
// return $decoded;
3135
$accessToken = $this->repository->findOneByToken($accessToken);
3236
if (null === $accessToken || !$accessToken->isValid()) {

0 commit comments

Comments
 (0)