Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update custom attribute via Keycloak REST API

Is it possible to update the value of custom attribute via Keycloak REST API? For example, which endpoint to use and how to construct a request body for the attribute that was created here.

Thanks!

like image 632
kvitaliy Avatar asked Jul 02 '20 08:07

kvitaliy


People also ask

How do I add a custom attribute to a Keycloak?

Add custom attribute Before we start, you must be logged in as an admin in keycloak. In the left menu bar click on Users , choose a user, in our case (johndoe) and the click Attributes tab. Enter a key and value and click the Add button on the right side. Now click the Save button.

How do I get user attributes in Keycloak?

Adding Custom attributes to our Realm We will add a Custom Attribute from Keycloak Admin application. Select the Users Panel and check the Attributes Tab. There Click to Add an Attribute and Save it. We have now added the customer.id Custom Attribute.

What are attributes in Keycloak?

Keycloak is a third-party authorization server that manages users of our web or mobile applications. It offers some default attributes, such as first name, last name, and email to be stored for any given user.


1 Answers

You have to use Keycloak Admin REST API :

PUT {host}/{basepath}/admin/realms/{realm}/users/{id}

e.g. http://localhost:8080/auth/admin/realms/alumni-realm/users/cd57cfd8-cb1c-4025-abfd-67fe6b784d22

Request Body (JSON) :

{
    "attributes": {
        "DOB": "1984-07-01"
    }
}

Authorization (Bearer Token) :

  1. Use Admin user access_token for authorization.

  2. If you want to allow User to update their own profile then you have to grant manage-users role in Keycloak. (That user will be able to update other users info hence it is not recommended)

like image 157
srp Avatar answered Oct 25 '22 02:10

srp