# Bug NEX-677 - [Backport] PATCH /setup fails when converting OAuth to SSO because default values are not applied like POST

Project: Stream Nextcloud app "OpenProject Integration"
Status: closed
URL: https://community.openproject.org/work_packages/NEX-677

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module |  |
| Target versions |  Nextcloud Integration 2.12.0 |
| Observed in versions |  |
| Bug found in version (deprecated) |  |
| Requires doc change | No |
| Accessibility | No |
| Pull preview |  |
| List |  |
| Labels |  |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable |  |
| Product manager |  |
| Developers |  |
| Designer |  |
| Signed off by |  |
| Interest by |  |

## Planning

| Attribute | Value |
| --- | --- |
| Relevance |  |

## Costs

| Attribute | Value |
| --- | --- |
| Votes |  |
| Work |  |
| Labor costs |  |

## Description

### Description

The `PATCH` `/index.php/apps/integration_openproject/setup` endpoint does not apply the same defaulting logic as the `POST` endpoint when updating an existing integration connection. As a result, converting an existing `OAuth` connection to an `SSO` connection (or vice versa) fails, even though the equivalent `POST` request succeeds.

### Steps to reproduce

Creating an `SSO` integration with `POST`

```bash
curl -s -XPOST 'https://nextcloud.local/index.php/apps/integration_openproject/setup' \
-H 'Content-Type: application/json' \
-d '{
  "values": {
    "openproject_instance_url": "https://openproject.local",
    "sso_provider_type": "nextcloud_hub",
    "authorization_method": "oidc",
    "targeted_audience_client_id": "openproject",
    "default_enable_navigation": false,
    "default_enable_unified_search": false,
    "setup_project_folder": false,
    "setup_app_password": false
  }
}' \
-u admin:admin
```

Result

```json
{"status": true}
```

<br>

Converting an existing `OAuth` integration to `SSO` with `PATCH`

```bash
curl -s -XPATCH 'https://nextcloud.local/index.php/apps/integration_openproject/setup' \
-H 'Content-Type: application/json' \
-d '{
  "values": {
    "sso_provider_type": "nextcloud_hub",
    "authorization_method": "oidc",
    "targeted_audience_client_id": "openproject"
  }
}' \
-u admin:admin
```

Result

```json
{"status": false}
```

### Cause

The `PATCH` request returns `false` because `checkAdminConfigOk()` returns `false` due to `oidc_provider` not being set.

The `setUpIntegration` controller (`POST`) handles this case by assigning a default value when `oidc_provider` is missing:

```php
if (
    $values['authorization_method'] === Application::AUTH_METHOD_OIDC
    && $values['sso_provider_type'] === Application::NEXTCLOUD_HUB_OIDC_PROVIDER_TYPE
    && (!\array_key_exists('oidc_provider', $values) || !$values['oidc_provider'])
) {
    $values['oidc_provider'] = Application::NEXTCLOUD_HUB_OIDC_PROVIDER_LABEL;
}
```

However, the corresponding `updateIntegration` controller (`PATCH`) does not contain equivalent logic, so `oidc_provider` remains unset and `checkAdminConfigOk()` returns `false`.

### Environment information

integration\_openproject `2.11` and nextcloud `32`

**OpenProject installation type**

*   Docker-compose installation
    

**Browser**

*   [x] Chrome
*   [ ] Firefox
*   [ ] Safari
*   [ ] Mobile Safari
*   [ ] Other (please specify)

**Operating System**

*   [ ] Windows
*   [ ] Mac OS X
*   [ ] Mobile iOS
*   [ ] Mobile Android
*   [x] Linux (please specify distro)
*   [ ] Chrome OS
*   [ ] Other (please specify)
