Skip to content

Commit

Permalink
[Admin] adjust esCadre auth url for impersonified admin
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano committed Sep 20, 2024
1 parent 4393393 commit b6ac7b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion features/api/user.feature
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Feature:
},
"tags": [],
"cadre_access": true,
"cadre_auth_path": "/oauth/v2/auth?scope=jemengage_admin&response_type=code&client_id=4498e44f-f214-110d-8b76-98a83f9d2b0c"
"cadre_auth_url": "http://test.renaissance.code/oauth/v2/auth?scope=jemengage_admin&response_type=code&client_id=4498e44f-f214-110d-8b76-98a83f9d2b0c"
}
"""

Expand Down
11 changes: 10 additions & 1 deletion src/Normalizer/JecouteAdherentNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Repository\Jecoute\DataSurveyRepository;
use App\Repository\OAuth\ClientRepository;
use App\Security\Voter\DataCornerVoter;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;

Expand All @@ -20,6 +21,9 @@ public function __construct(
private readonly DataSurveyRepository $dataSurveyRepository,
private readonly AuthorizationCheckerInterface $authorizationChecker,
private readonly ClientRepository $clientRepository,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly string $adminRenaissanceHost,
private readonly string $userVoxHost,
) {
}

Expand All @@ -33,7 +37,12 @@ public function normalize($object, $format = null, array $context = [])
];

if ($data['cadre_access'] = $this->authorizationChecker->isGranted(DataCornerVoter::DATA_CORNER, $object)) {
$data['cadre_auth_path'] = '/oauth/v2/auth?scope='.Scope::JEMENGAGE_ADMIN.'&response_type=code&client_id='.$this->clientRepository->findOneBy(['code' => AppCodeEnum::JEMENGAGE_WEB])->getUuid();
$data['cadre_auth_url'] = $this->urlGenerator->generate('app_front_oauth_authorize', [
'app_domain' => $this->authorizationChecker->isGranted('ROLE_PREVIOUS_ADMIN') ? $this->adminRenaissanceHost : $this->userVoxHost,
'scope' => Scope::JEMENGAGE_ADMIN,
'response_type' => 'code',
'client_id' => $this->clientRepository->findOneBy(['code' => AppCodeEnum::JEMENGAGE_WEB])->getUuid(),
], UrlGeneratorInterface::ABSOLUTE_URL);
}

return $data;
Expand Down

0 comments on commit b6ac7b6

Please sign in to comment.