<?php
namespace App\OAuth2\Repository; use App\OAuth2\Entity\ClientEntity; use App\OAuth2\Entity\ScopeEntity; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\ScopeEntityInterface; use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; class ScopeRepository implements ScopeRepositoryInterface { public function getScopeEntityByIdentifier(string $identifier): ?ScopeEntityInterface { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); $catalogue = $CFG['oauth2']['scopes'] ?? []; if (!isset($catalogue[$identifier])) { return null; } $scope = new ScopeEntity(); $scope->setIdentifier($identifier); return $scope; } public function finalizeScopes( array $scopes, string $grantType, ClientEntityInterface $clientEntity, string|null $userIdentifier = null, ?string $authCodeId = null ): array { $allowed = $clientEntity instanceof ClientEntity ? $clientEntity->getAllowedScopes() : []; if (!$allowed) { return []; } $final = []; foreach ($scopes as $scope) { if (in_array($scope->getIdentifier(), $allowed, true)) { $final[] = $scope; } } return $final; } }