From 51c3dc5c3c36cceb72934cc124423a77148619a6 Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 26 Oct 2023 09:46:39 +0200 Subject: [PATCH] Added a check on the validity of the token --- src/Cloud/Auth.php | 9 +++++---- .../Handler/Workflow/DeclareWorkflowCommandHandler.php | 5 ----- .../Handler/Workflow/RemoveWorkflowCommandHandler.php | 5 ----- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/Cloud/Auth.php b/src/Cloud/Auth.php index 1a069ccd..b7201d54 100644 --- a/src/Cloud/Auth.php +++ b/src/Cloud/Auth.php @@ -4,6 +4,7 @@ namespace Kiboko\Component\Satellite\Cloud; +use DateTimeInterface; use Gyroscops\Api; use Kiboko\Component\Satellite\Cloud\DTO\OrganizationId; use Kiboko\Component\Satellite\Cloud\DTO\WorkspaceId; @@ -166,10 +167,10 @@ public function token(string $url): string throw new AccessDeniedException('There is no available token to authenticate to the service.'); } - // $date = \DateTimeImmutable::createFromFormat(\DateTimeImmutable::RFC3339_EXTENDED, $this->configuration[$url]['date']); - // if ($date <= new \DateTimeImmutable('-1 hour')) { - // throw new AccessDeniedException('The stored token has expired, you need a fresh token to authenticate to the service.'); - // } + $date = \DateTimeImmutable::createFromFormat(DateTimeInterface::RFC3339_EXTENDED, $this->configuration[$url]['date']); + if ($date <= new \DateTimeImmutable('-1 hour')) { + throw new AccessDeniedException('The stored token has expired, you need a fresh token to authenticate to the service.'); + } return $this->configuration[$url]['token']; } diff --git a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php index 82bfdbee..15c3506a 100644 --- a/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php +++ b/src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php @@ -85,11 +85,6 @@ function (Cloud\DTO\Workflow\JobInterface $job) { throw new Cloud\DeclareWorkflowFailedException('Something went wrong while declaring the workflow. It seems the data you sent was invalid, please check your input.', previous: $exception); } - /* TODO : we need to remove this condition from this class and fix the Authentication checker */ - if (null == $result) { - throw new \RuntimeException('Your token has expired, please refresh it.'); - } - return new Cloud\Event\Workflow\WorkflowDeclared($result->getId()); } } diff --git a/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php index 91ac80bf..94a144f4 100644 --- a/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php +++ b/src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php @@ -28,11 +28,6 @@ public function __invoke(Cloud\Command\Workflow\RemoveWorkflowCommand $command): throw new Cloud\RemoveWorkflowFailedException('Something went wrong while removing the workflow. It seems the data you want to delete do not exists.', previous: $exception); } - /* TODO : we need to remove this condition from this class and fix the Authentication checker */ - if (null == $result) { - throw new \RuntimeException('Your token has expired, please refresh it.'); - } - return new Cloud\Event\Workflow\WorkflowRemoved($result->getId()); } }