diff --git a/src/EventSubscriber/ScopeResolveListener.php b/src/EventSubscriber/ScopeResolveListener.php index 802c029..c90a170 100644 --- a/src/EventSubscriber/ScopeResolveListener.php +++ b/src/EventSubscriber/ScopeResolveListener.php @@ -2,7 +2,10 @@ namespace App\EventSubscriber; +use App\Service\ClientService; +use Doctrine\ORM\EntityManagerInterface; use League\Bundle\OAuth2ServerBundle\Event\ScopeResolveEvent; +use League\Bundle\OAuth2ServerBundle\Repository\ScopeRepository; use League\Bundle\OAuth2ServerBundle\ValueObject\Scope; use League\Bundle\OAuth2ServerBundle\Model\Client; use League\OAuth2\Server\Repositories\ClientRepositoryInterface; @@ -13,12 +16,16 @@ final class ScopeResolveListener implements EventSubscriberInterface { private ClientRepositoryInterface $clientRepository; private LoggerInterface $logger; + private ClientService $clientService; + private EntityManagerInterface $entityManager; - public function __construct(ClientRepositoryInterface $clientRepository, LoggerInterface $logger) + public function __construct(ClientRepositoryInterface $clientRepository, LoggerInterface $logger, ClientService $clientService, EntityManagerInterface $entityManager) { $this->logger = $logger; // Inject the client repository $this->clientRepository = $clientRepository; + $this->clientService = $clientService; + $this->entityManager = $entityManager; } public function onScopeResolve(ScopeResolveEvent $event): void @@ -38,23 +45,27 @@ final class ScopeResolveListener implements EventSubscriberInterface foreach ($defaultScopes as $scope) { $finalScopes[] = new Scope($scope); } - + + $clientEntity = $this->entityManager->getRepository(Client::class)->findOneBy(['identifier' => $clientIdentifier]); + + $finalScopes[] = new Scope('apps:'. $clientEntity->getName()); + // Add client-specific scopes based on client identifier or name - switch ($clientIdentifier) { - case 'a712b3caede9588372b2a83947fae53e': - $finalScopes[] = new Scope('apps:easyexploit'); - break; - case 'EasyAccess': - $finalScopes[] = new Scope('apps:easyaccess'); - break; - case 'EasyMonithor': - $finalScopes[] = new Scope('apps:easymonithor'); - break; - case 'EasyCheck': - $finalScopes[] = new Scope('apps:easycheck'); - break; - // Add more cases as needed for other applications - } +// switch ($clientIdentifier) { +// case 'a712b3caede9588372b2a83947fae53e': +// $finalScopes[] = new Scope('apps:easyexploit'); +// break; +// case '14bbb1b1692ac3a45159e263e3e7ec67': +// $finalScopes[] = new Scope('apps:client'); +// break; +// case 'EasyMonithor': +// $finalScopes[] = new Scope('apps:easymonithor'); +// break; +// case 'EasyCheck': +// $finalScopes[] = new Scope('apps:easycheck'); +// break; +// // Add more cases as needed for other applications +// } // // If the client is an admin client, add admin scopes // if (str_contains($client->getName(), 'Admin')) { diff --git a/src/Service/ClientService.php b/src/Service/ClientService.php new file mode 100644 index 0000000..be42258 --- /dev/null +++ b/src/Service/ClientService.php @@ -0,0 +1,23 @@ +getRepository(Client::class)->findOneBy(['identifier' => $identifier]); + } +} \ No newline at end of file