# Bug NEX-684 - [Backport] [UI] User is shown connected in webUI after converting exisiting OAuth to SSO via setup endpoint 

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

## 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

### Steps to reproduce

*   Setup `integration_openproject` with `OAuth`.
    
*   Connect the Nextcloud admin with an OpenProject admin.
    
*   Convert the existing `OAuth` integration setup to `SSO` by:
    

```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
```

*   and the Response should be:
    

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

*   In `Nextcloud`, navigate to `Personal settings` -&gt; `OpenProject`
    

<br>

### What is the buggy behavior?

*   OpenProject Integration status shows `Connected as OpenProject Admin` in the webUI
    
    <br>
    
    <img class="op-uc-image op-uc-image_inline" src="/api/v3/attachments/923175/content">
    

&nbsp;Then

*   In Nextcloud, navigate to Administration settings -&gt; OpenProject and reset the OpenProject integration setup.
    
*   `Nextcloud OAuth client ID` and `Nextcloud OAuth client secret` are not deleted.
    

<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="https://community.openproject.org/api/v3/attachments/923660/content"></div></figure>

### What is the expected behavior?

*   OpenProject Integration status should show `Unauthorized to connect to OpenProject` in the webUI
    
    Or, error related to settings not available (for Nextcloud users)
    
    <br>
    
    <img class="image_resized op-uc-image op-uc-image_inline" style="width:931px;" src="/api/v3/attachments/923174/content">
    

Then

*   In Nextcloud, navigate to Administration settings -&gt; OpenProject and reset the OpenProject integration setup.
    
*   `Nextcloud OAuth client ID` and `Nextcloud OAuth client secret` should be deleted.
    

<figure class="image op-uc-figure"><div class="op-uc-figure--content"><img class="op-uc-image" src="https://community.openproject.org/api/v3/attachments/923661/content"></div></figure>

### Cause

In function `setIntegrationConfig`:  
the following `if` block is never `true` for converting existing `OAuth` to `SSO`

```php
		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))) ||
			// when the OP client information is reset
			$runningFullResetWithOAuth2Auth ||
			$runningOauth2Reset
		) 
```

so deleting the `token` is not called

```php
$this->clearUserInfo($userUID);
```

the bug is in how the value of variable `$runningOauth2Reset` is computed

### 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)
