diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index b69fbd86a8..9387eaed17 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -369,6 +369,17 @@ Http::init() $authorization->addRole($authRole); } + $isAdminProjectRequest = ! $user->isEmpty() + && $project->getId() !== 'console' + && $mode === APP_MODE_ADMIN; + $isOAuthAdminKey = ! empty($apiKey) + && $apiKey->getType() === API_KEY_OAUTH2 + && $apiKey->getRole() === User::ROLE_OWNER; + + if ($isAdminProjectRequest && $isOAuthAdminKey) { + $authorization->setDefaultStatus(false); + } + if (!$impersonatorUser->isEmpty() && !$targetUser->isEmpty()) { $dbForProject->setMetadata('user', $targetUser->getId()); $dbForPlatform->setMetadata('user', $targetUser->getId()); @@ -379,7 +390,7 @@ Http::init() * But, for actions on resources (sites, functions, etc.) in a non-console project, we explicitly check * whether the admin user has necessary permission on the project (sites, functions, etc. don't have permissions associated to them). */ - if (empty($apiKey) && ! $user->isEmpty() && $project->getId() !== 'console' && $mode === APP_MODE_ADMIN) { + if ($isAdminProjectRequest && (empty($apiKey) || $isOAuthAdminKey)) { $input = new Input(Database::PERMISSION_READ, $project->getPermissionsByType(Database::PERMISSION_READ)); $initialStatus = $authorization->getStatus(); $authorization->enable(); diff --git a/app/init/constants.php b/app/init/constants.php index 2b7352e89c..8859937685 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -288,6 +288,7 @@ const API_KEY_STANDARD = 'standard'; const API_KEY_EPHEMERAL = 'ephemeral'; const API_KEY_ORGANIZATION = 'organization'; const API_KEY_ACCOUNT = 'account'; +const API_KEY_OAUTH2 = 'oauth2'; // Realtime const CONSOLE_TAIL_CHANNEL_PREFIX = 'console.tail';