[keycloak-user] Direct Access to KeyCloak

Christopher Davies christopher.james.davies at gmail.com
Wed Aug 12 12:56:14 EDT 2015


I am trying to write  a test harness for out application which uses
KeyCloak.
In order to run my tests I need to manipulate KeyCloak.

I am able to get data out of KeyCloak using the REST API. However I am
unclear what I should send to KeyCloak to change a setting.

I was trying to set the role for a user and wrote the script at the bottom
of the email.

I get back an error of org.codehaus.jackson.map.JsonMappingException: Can
not deserialize instance of java.util.ArrayList out of START_OBJECT token
 at [Source: io.undertow.servlet.spec.ServletInputStreamImpl at 73cda37e;
line: 1, column: 1]

I have obviously missed a key point in the format of my data, but cannot
see what it is.


Chris




---------------------------------------
#!/bin/bash

host=192.168.10.221:8088
realm=ATS-ci


t=$(curl -X POST
http://${host}/auth/realms/${realm}/protocol/openid-connect/token
--data "username=${1}" --data "password=${2}" --data "grant_type=password"
--data "client_id=client" 2>/dev/null | jq -r ".id_token")

client=$(curl http://${host}/auth/admin/realms/${realm}/clients -H "Accept:
application/json" -H "Authorization: Bearer ${t}" 2>/dev/null | jq -r ".[]
| select(.name == \"client\").id")
user=$(curl http://${host}/auth/admin/realms/${realm}/users -H "Accept:
application/json" -H "Authorization: Bearer ${t}" 2>/dev/null | jq -r ".[]
| select(.username == \"${3}\").id")

echo ${client}
echo ${user}

echo "Roles"
curl http://${host}/auth/admin/realms/${realm}/clients/${client}/roles \
-H "Accept: application/json" \
-H "Authorization: Bearer ${t}" 2>/dev/null  | jq -r ".[] | {id, name }"

echo ""
echo "Roles:${3}"
curl http://${host}/auth/admin/realms/${realm}/users/${user}/role-mappings/clients/${client}
\
-H "Accept: application/json" \
-H "Authorization: Bearer ${t}" 2>/dev/null | jq -r ".[] | {id, name }"


curl http://${host}/auth/admin/realms/${realm}/users/${user}/role-mappings/clients/${client}
\
-X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer ${t}" \
--data "{'realm': 'ATS-${realm}', 'id': '${user}', 'client': '${client}',
'\$entity': [ 'operator' ] }"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20150812/4b81ee41/attachment.html 


More information about the keycloak-user mailing list