# I can't add user attribute to tokens, guess some caching is happening?

**URL:** https://forum.keycloak.org/t/i-cant-add-user-attribute-to-tokens-guess-some-caching-is-happening/14073
**Category:** Miscellanaeous
**Created:** [March 6, 2022, 6:53pm UTC](https://forum.keycloak.org/t/i-cant-add-user-attribute-to-tokens-guess-some-caching-is-happening/14073 "2022-03-06T18:53:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![asteroidqq](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@asteroidqq](https://forum.keycloak.org/u/asteroidqq)
#### Post date: [March 6, 2022, 6:53pm UTC](https://forum.keycloak.org/t/i-cant-add-user-attribute-to-tokens-guess-some-caching-is-happening/14073/1 "2022-03-06T18:53:43Z")

</div>

I added a custom attribute to my access token but it is now shown.

1. user has attribute named `birthDate`
2. created a client mapper (UserAttribute)
3. when I evaluate in Client Scopes, it can be found in the list but when I check the access token, nowhere it is

I did every step on a keycloak I can connect remotely and there it works. Feels like it is caching something. I used the cache buttons at Realm → Caches. Also I deleted the keycloak, installed it again and same. Does keycloak cache somewhere else on a windows?

> <https://stackoverflow.com/questions/71372878/keycloak-i-cant-add-custom-user-attribute-into-the-token>

Thanks in advance.

---

<div class="post-metadata">

### Author: ![corporateguy](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@corporateguy](https://forum.keycloak.org/u/corporateguy)
#### Post date: [October 31, 2024, 3:49pm UTC](https://forum.keycloak.org/t/i-cant-add-user-attribute-to-tokens-guess-some-caching-is-happening/14073/2 "2024-10-31T15:49:41Z")

</div>

I couldn’t add user attributes to the token as well.  
For me the solution was to use keycloak’s `token exchange` feature.  
More info → [Using token exchange - Keycloak](https://www.keycloak.org/securing-apps/token-exchange)

To do so, I had to do the following:

1. Add features option to keycloak’s build command. Then rebuild/restart keycloak.

```auto
kc.sh build --features="token-exchange"

```

1. Make a POST keycloak request to `/auth/realms/client-id/protocol/openid-connect/token` endpoint with `grant_type=password` in payload.
2. Get an access token from this request
3. Make a new request to `/auth/realms/client-id/protocol/openid-connect/token` endpoint with `grant_type=urn:ietf:params:oauth:grant-type:token-exchange` and `subject_token` containing access token from previous request.
4. Decode token from `token exchange` to be able to view user attributes.
