src/Core/EventSubscriber/AuthorizationHeaderSubscriber.php line 52
<?phpdeclare(strict_types=1);/*** Copyright (c) 2022 TECLA Consulting Group oü.* All rights reserved.** This unpublished material is proprietary to TECLA Consulting Group oü.* All rights reserved. The methods and* techniques described herein are considered trade secrets* and/or confidential. Reproduction or distribution, in whole* or in part, is forbidden except by express written permission* of TECLA Consulting Group oü.** @author Matúš Sýkorjak <matus@tecla.no>* @copyright 2022 TECLA Consulting Group oü*/namespace App\Core\EventSubscriber;use App\Contact\Model\Identity\ContactId;use App\Contact\Repository\ContactRepositoryInterface;use App\Contact\Security\ContactContextInterface;use JetBrains\PhpStorm\ArrayShape;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpKernel\Event\RequestEvent;use Symfony\Component\HttpKernel\KernelEvents;use Throwable;final class AuthorizationHeaderSubscriber implements EventSubscriberInterface{private ContactRepositoryInterface $contactRepository;private ContactContextInterface $contactContext;public function __construct(ContactRepositoryInterface $contactRepository, ContactContextInterface $contactContext){$this->contactRepository = $contactRepository;$this->contactContext = $contactContext;}#[ArrayShape([KernelEvents::REQUEST => 'string'])]public static function getSubscribedEvents(): array{return [KernelEvents::REQUEST => [['onKernelRequest', 5],],];}public function onKernelRequest(RequestEvent $event): void{if (false === $event->isMainRequest()) {return;}$request = $event->getRequest();if (false === $request->headers->has('Authorization')) {return;}try {$authorizationHeader = explode(' ', $request->headers->get('Authorization'));[$username, $password] = explode(':', base64_decode($authorizationHeader[1]));$contactId = ContactId::createFromString($username);$contact = $this->contactRepository->find($contactId);$this->contactContext->setCurrent($contact);} catch (Throwable $e) {}}}