Skip to content

Fix PIMUrl definition on activate action #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Controller/ActivateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

namespace App\Controller;

use App\Validator\ReachableUrl;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Validator\ValidatorInterface;

final class ActivateAction
{
Expand All @@ -25,6 +28,7 @@ final class ActivateAction

public function __construct(
private string $akeneoClientId,
private ValidatorInterface $validator,
) {
}

Expand All @@ -35,7 +39,16 @@ public function __invoke(Request $request): Response

$pimUrl = $session->get('pim_url');
if (empty($pimUrl)) {
throw new \LogicException('Can\'t retrieve PIM url, please restart the authorization process.');
$pimUrl = $request->query->get('pim_url');
if (empty($pimUrl)) {
throw new \LogicException('Can\'t retrieve PIM url, please restart the authorization process.');
} else {
$violations = $this->validator->validate($pimUrl, new ReachableUrl());
if ($violations->count() > 0) {
throw new BadRequestHttpException('PIM url is not valid.');
}
$session->set('pim_url', \rtrim((string)$pimUrl, '/'));
}
}

$state = \bin2hex(\random_bytes(10));
Expand Down