# Bug SI-61 - Refreshing exchanged token does not work with Keycloak

Project: Stream Integration Basics
Status: closed
URL: https://community.openproject.org/work_packages/SI-61

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | Medium |
| Module |  |
| Target versions | 15.3.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 |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Planning

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

## Costs

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

## Description

### Steps to reproduce

Right now this bug is only reproducible in internal backend code. No QA is required probably:

1.  Use KeyCloak as IDP
    
2.  Use `OpenIDConnect::UserTokens::FetchService#access_token_for` to obtain an access token for another client via Token Exchange
    
3.  See that KeyCloak returned an access token and a refresh token
    
4.  After expiration, try to obtain another access token for the same audience
    

### What is the buggy behavior?

The newly issued token will internally not be issued to the correct audience anymore, because it was obtained via Token Refresh, not via Token Exchange.

### What is the expected behavior?

The newly issued token should still have the same audience as before, including the client for which the token was initially exchanged.

This is a bug/surprising behaviour in KeyCloak, documented in https://github.com/keycloak/keycloak/issues/37016. We might need to work around it.
