Search code examples
restjbosskeycloak

Is it possible to create new user with jboss/keycloak:16.1.1using REST APIs?


Based on this link,I am able to successfully:

  1. Run a docker container based on jboss/keycloak:16.1.1
  2. Setup a client which has secret and client_id
  3. Get a valid access_token

However, i am requeired to create (and GET) users in keycloak via REST APIs. In the below picture, you can see what i have tried in postman and as a result i got 404:

enter image description here

Question1: Is create and GET users via REST supported in jboss/keycloak:16.1.1 ?

When i check the provided APIs in the below picture, there is no API related to users.

enter image description here

Question2: Which roles do i need to assign to my client to be able to create or get users ?

I use the jwt website to investigate my token and i figured out this token has a few realm_roles and accoint_roles such as [ "default-roles-master", "offline_access", "uma_authorization" ] , but i am not sure if these are roles which give me the previledegs to create or get user. Are they ?

Here is my token, and you can put it in jwt.io and check the results:

eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ2X1gtMFJaTWhEbkNER0NnUjhoZGx5RGRwaENvUWxOcnNuZHZVUm9scms4In0.eyJleHAiOjE3MDMyNjU5MzcsImlhdCI6MTcwMzI2NTg3NywianRpIjoiZGQ1ZDNjOGQtM2Q1Yi00MjVjLTkwZTktOWJmNzc1MjNmMzMxIiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwL2F1dGgvcmVhbG1zL21hc3RlciIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiIyYzVmNDQxMy04ZGIxLTQ4NjgtYTJiNC1kMzA2Njg2NDc5YWMiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJhZG1pbi1yZXN0LWNsaWVudCIsImFjciI6IjEiLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsiZGVmYXVsdC1yb2xlcy1tYXN0ZXIiLCJvZmZsaW5lX2FjY2VzcyIsInVtYV9hdXRob3JpemF0aW9uIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnsiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwidmlldy1wcm9maWxlIl19fSwic2NvcGUiOiJwcm9maWxlIGVtYWlsIiwiY2xpZW50SWQiOiJhZG1pbi1yZXN0LWNsaWVudCIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwiY2xpZW50SG9zdCI6IjE3Mi4xNy4wLjEiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJzZXJ2aWNlLWFjY291bnQtYWRtaW4tcmVzdC1jbGllbnQiLCJjbGllbnRBZGRyZXNzIjoiMTcyLjE3LjAuMSJ9.LuEEDoRKubMXrccgxAkpVPun4jbmr7Kn_8EG0eeyxcwudnEF-aUDd0zLEIz8cDUnvLybbAIfq0CUOr6sslTdzgV52FFrOrIfo3kqyy6stHEuhSCs-G7SPwwbv3aOIUmQqC9H2Mi4rW3K46edutBGwDKqJ-bSKTTHfhw128UrU-x5Clk7pZ1hHEV56KttgBtlLIOpmhQ4Ji88ah0RaYb3I9j7ekLQWwUmd04c1JfR3rcOEquYYUfA-Se2wyhDP14HNOCQWq4Nx1ctf3Y9KDfX_qqF-cjG7JJy88bc7FDjBZjC5xAfdahScLS3aUR_wa0NyBYEY-4BC1G3qHMkvPYycg

Solution

  • #1 Create User and Get users by REST API

    1. Assign "manage_users" role to client enter image description here

    2. Get Token enter image description here

    enter image description here

    Decoding token by jwt.io enter image description here

    1. Create User
    POST http://localhost:8080/auth/admin/realms/my-realm/users
    

    In Body

    {
      "enabled": true,
      "attributes": {},
      "groups": [],
      "username": "user2",
      "emailVerified": "",
      "email": "user2@test.com",
      "firstName": "Tom",
      "lastName": "Cruise"
    }
    

    enter image description here

    enter image description here

    Result enter image description here

    #2 Which role to create a user in the client

    "manage-users" role.

    Detail in here and here