add client scope
This commit is contained in:
parent
8a404d371e
commit
023bf29e0b
|
|
@ -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
|
||||
|
|
@ -39,22 +46,26 @@ final class ScopeResolveListener implements EventSubscriberInterface
|
|||
$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')) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
use League\Bundle\OAuth2ServerBundle\Model\Client;
|
||||
|
||||
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class ClientService{
|
||||
/**
|
||||
* Retrieves a Client entity by its identifier.
|
||||
*
|
||||
* @param string $identifier The identifier of the client.
|
||||
* @param EntityManagerInterface $entityManager The entity manager to use for database operations.
|
||||
* @return Client|null The Client entity or null if not found.
|
||||
*/
|
||||
|
||||
public function getClientIdentifier(String $identifier, EntityManagerInterface $entityManager): Client
|
||||
{
|
||||
return $entityManager->getRepository(Client::class)->findOneBy(['identifier' => $identifier]);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue