1

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?

Abbadon
  • 2,513
  • 3
  • 25
  • 33

2 Answers2

0

You can update the user's attribute in the session by admin API.

Demo

Prepaire

#1 Using Keycloak version 21.0.0

enter image description here

#2 Add my-realm realm

enter image description here

#3 Add two users at my-realm realm

enter image description here

#4 Login user to enter session for her

enter image description here

Steps

enter image description here

#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

enter image description here

#2 Get session id by the client session statics API

GET http://localhost:8080/admin/realms/my-realm/client-session-stats

enter image description here

#3 Get user list in session

GET http://localhost:8080/admin/realms/my-realm/clients/[session uuid]/user-sessions

enter image description here

#4 Get user information with attributes

GET http://localhost:8080/admin/realms/my-realm/users/[user uuid]

enter image description here

enter image description here

#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"
        ]
    }
}

enter image description here

enter image description here

Bench Vue
  • 5,257
  • 2
  • 10
  • 14
0

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:

Update the user enter image description here

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: enter image description here

CAMD_3441
  • 2,514
  • 2
  • 23
  • 38