diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php index dbb1a9449..4b3c24cc6 100755 --- a/lib/Controller/ConfigController.php +++ b/lib/Controller/ConfigController.php @@ -124,11 +124,13 @@ public function clearUserInfo(?string $userId = null) { /** * @return void */ - public function resetOauth2Configs(): void { + public function resetOauth2Configs(bool $deleteOauthClient): void { // for oauth2 reset we reset openproject client credential as well as nextcloud client credential $this->config->setAppValue(Application::APP_ID, 'openproject_client_id', ""); $this->config->setAppValue(Application::APP_ID, 'openproject_client_secret', ""); - $this->deleteOauthClient(); + if ($deleteOauthClient) { + $this->deleteOauthClient(); + } } /** @@ -241,14 +243,9 @@ private function setIntegrationConfig(array $values): array { } // since we can now switch between both authorization method we need to know what we are resetting (either "oauth2" or "oidc" method) // determines if we are switching from "oauth2" to "oidc" auth method - $runningOauth2Reset = ( - key_exists('openproject_client_id', $values) && - !$values['openproject_client_id'] && - key_exists('openproject_client_secret', $values) && - !$values['openproject_client_secret'] && - $oldOpenProjectOauthUrl && - $oldClientId && - $oldClientSecret + $switchingOauthToOIDC = ( + $oldAuthMethod === Application::AUTH_METHOD_OAUTH && key_exists('authorization_method', $values) && + $values['authorization_method'] === Application::AUTH_METHOD_OIDC ); // determines if we are switching from "oidc" to "oauth2" auth method @@ -309,13 +306,18 @@ private function setIntegrationConfig(array $values): array { } $this->config->deleteAppValue(Application::APP_ID, 'oPOAuthTokenRevokeStatus'); + $resetOpenProjectClient = ((key_exists('openproject_client_id', $values) && $values['openproject_client_id'] !== $oldClientId) || + (key_exists('openproject_client_secret', $values) && $values['openproject_client_secret'] !== $oldClientSecret)); + $deleteOauthClient = false; + if ($runningFullResetWithOAuth2Auth || $switchingOauthToOIDC) { + $deleteOauthClient = true; + } if ( // when the OP client information has changed - (!$runningFullResetWithOIDCAuth && ((key_exists('openproject_client_id', $values) && $values['openproject_client_id'] !== $oldClientId) || - (key_exists('openproject_client_secret', $values) && $values['openproject_client_secret'] !== $oldClientSecret))) || + (!$runningFullResetWithOIDCAuth && $resetOpenProjectClient) || // when the OP client information is reset $runningFullResetWithOAuth2Auth || - $runningOauth2Reset + $switchingOauthToOIDC ) { $this->userManager->callForAllUsers(function (IUser $user) use ( $oldOpenProjectOauthUrl, $oldClientId, $oldClientSecret @@ -357,6 +359,7 @@ private function setIntegrationConfig(array $values): array { } $this->clearUserInfo($userUID); }); + $this->resetOauth2Configs($deleteOauthClient); } elseif ($runningFullResetWithOIDCAuth || $runningOIDCReset) { $this->resetOIDCConfigs(); $this->userManager->callForAllUsers(function (IUser $user) { @@ -377,12 +380,6 @@ private function setIntegrationConfig(array $values): array { $this->config->setAppValue(Application::APP_ID, 'fresh_project_folder_setup', "0"); } - // when switching from "oauth2" to "oidc" authorization method - if (key_exists('authorization_method', $values) && - $values['authorization_method'] === Application::AUTH_METHOD_OIDC && $runningOauth2Reset) { - $this->resetOauth2Configs(); - } - // when switching from "oidc" to "oauth2" authorization method if (key_exists('authorization_method', $values) && $values['authorization_method'] === Application::AUTH_METHOD_OAUTH && $runningOIDCReset) {