[keycloak-user] How to correctly use REST API? delete user through REST API for example
JasonPeng
hpeng at redhat.com
Tue Jan 12 13:05:45 EST 2016
Hi there,
Can someone give me some hint about how to correctly setup a client that can
accept REST request from a httpclient in keycloak?
For example, I use the admin-access example from keycloak source project and
modify it to do a DELETE action through REST API, however I keep getting the
request Forbidden 403 from keycloak server. I don¹t change any setting of
the admin-client imported from the json file and my code snippet of deleting
user as below:
public static void deleteUser(HttpServletRequest request,
AccessTokenResponse res) throws Failure {
HttpClient client = new DefaultHttpClient();
String userId = "e20277f8-2ebe-4e5e-aa00-0cee9c578249";
try {
HttpDelete delete = new HttpDelete(getBaseUrl(request) +
"/admin/realms/demo/users/" + userId);
delete.addHeader("Authorization", "Bearer " + res.getToken());
HttpResponse response = client.execute(delete);
System.out.println(response.getStatusLine().getReasonPhrase());
if (response.getStatusLine().getStatusCode() != 200) {
throw new Failure(response.getStatusLine().getStatusCode());
}
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
if (is != null)
is.close();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
client.getConnectionManager().shutdown();
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20160113/af585408/attachment.html
More information about the keycloak-user
mailing list