English 中文(简体)
Keycloak REST API > Is it possible to update user session data using admin REST API?
原标题:

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?

问题回答

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

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





相关问题
凌驾于多租期的钥匙花 the?

so I have micro service application where one of those called auth_manager used to authenticate and register new user , I use the auth_manager to get token for user from keycloak , and other services ...

Add custom attribute in my keycloak client roles

I can add a custom attribute to my user following this link. I want to add a (common) custom attribute to my client roles. Is it possible? I tried to replicate the custom attribute like my user ...

Keycloak custom theme reject login.ftl

I create custom keycloak login screen. I download from keycloak web page Server Standalone server distribution And copy from keycloak-8.0.2 hemeskeycloak to C:xxconfigurationkeycloak...

WSO2 APIM 4.2 http gateaway mixed content error

I m using wso2 apim 4.2 with keycloak key manager to invoke an api through http. I published the api to get published through http and https, for the domain I already inject the ssl on wso2 apim. I ...

热门标签