Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions lib/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Loading