|
|
@@ -4,6 +4,7 @@ namespace App\Service\ApiLegacy;
|
|
|
|
|
|
use App\Service\Rest\ApiRequestService;
|
|
|
use JetBrains\PhpStorm\Pure;
|
|
|
+use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\NullToken;
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
|
|
|
@@ -17,7 +18,11 @@ use Symfony\Contracts\HttpClient\ResponseInterface;
|
|
|
class ApiLegacyRequestService extends ApiRequestService
|
|
|
{
|
|
|
#[Pure]
|
|
|
- public function __construct(HttpClientInterface $apiLegacyClient, private Security $security)
|
|
|
+ public function __construct(
|
|
|
+ HttpClientInterface $apiLegacyClient,
|
|
|
+ private Security $security,
|
|
|
+ private JWTTokenManagerInterface $jwtManager
|
|
|
+ )
|
|
|
{
|
|
|
parent::__construct($apiLegacyClient);
|
|
|
}
|
|
|
@@ -36,7 +41,6 @@ class ApiLegacyRequestService extends ApiRequestService
|
|
|
}
|
|
|
|
|
|
$headers = [
|
|
|
- 'authorization' => 'BEARER ' . $_REQUEST['BEARER'],
|
|
|
'Accept' => '*/*',
|
|
|
'Charset' => 'UTF-8',
|
|
|
'Accept-Encoding' => 'gzip, deflate, br',
|
|
|
@@ -49,12 +53,15 @@ class ApiLegacyRequestService extends ApiRequestService
|
|
|
throw new HttpException(500, 'Request error : Switch original user missing');
|
|
|
}
|
|
|
|
|
|
+ $jwt = $this->jwtManager->create($originalUser->getPerson());
|
|
|
$headers['x-accessid'] = $originalUser->getId();
|
|
|
$headers['x-switch-access'] = $token->getUser()->getId();
|
|
|
} else {
|
|
|
+ $jwt = $this->jwtManager->create($token->getUser()->getPerson());
|
|
|
$headers['x-accessid'] = $token->getUser()->getId();
|
|
|
}
|
|
|
|
|
|
+ $headers['authorization'] = 'BEARER ' . $jwt;
|
|
|
$options['headers'] = array_merge($options['headers'] ?? [], $headers);
|
|
|
|
|
|
return parent::request($method, $url, $parameters, $options);
|