Skip to content

Commit

Permalink
Added a check on the validity of the token
Browse files Browse the repository at this point in the history
  • Loading branch information
sebprt committed Oct 26, 2023
1 parent d3e6f26 commit 51c3dc5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/Cloud/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'];
}
Expand Down
5 changes: 0 additions & 5 deletions src/Cloud/Handler/Workflow/DeclareWorkflowCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
5 changes: 0 additions & 5 deletions src/Cloud/Handler/Workflow/RemoveWorkflowCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 51c3dc5

Please sign in to comment.