I would like to update an attribute of the user session using Keycloak admin REST API, it seems not feasible. Is there any way to do so?
2 Answers
You can update the user's attribute in the session by admin API.
Demo
Prepaire
#1 Using Keycloak version 21.0.0
#2 Add my-realm
realm
#3 Add two users at my-realm
realm
#4 Login user
to enter session for her
Steps
#1 Get master's
access token by Postman
Detail in here
Note Make a good enough time the Access Token Lifespan
of master token. The default is 1 minute is not enough to demo
#2 Get session id by the client session statics API
GET http://localhost:8080/admin/realms/my-realm/client-session-stats
#3 Get user list in session
GET http://localhost:8080/admin/realms/my-realm/clients/[session uuid]/user-sessions
#4 Get user information with attributes
GET http://localhost:8080/admin/realms/my-realm/users/[user uuid]
#5 Update his attribute
PUT http://localhost:8080/admin/realms/my-realm/users/[user uuid]
Body of PUT
{
"id": "[user uuid]",
"username": "user name",
"attributes": {
"key1": [
"value2"
],
"key2": [
"New Value"
]
}
}

- 5,257
- 2
- 10
- 14
-
Thx for your answer. I want to update the attributes of the user sessions, not the user attributes :). – Abbadon Aug 24 '23 at 15:23
-
Can show the real example? – Bench Vue Aug 24 '23 at 17:09
Looking at the latest admin rest api docs it does seem possible.
Per this link https://www.keycloak.org/docs-api/18.0/rest-api/#_users_resource you can make this api call to update a user:
Notice the Body parameter using a UserRepresentation
object. When you go to that link https://www.keycloak.org/docs-api/18.0/rest-api/#_userrepresentation you can see that it contains an optional field for attributes
:

- 2,514
- 2
- 23
- 38