[keycloak-user] can not delete user using REST API -401 unauthorized.
Marek Posolda
mposolda at redhat.com
Thu Nov 12 03:50:23 EST 2015
What's the output of the "System.out.println(httpHeaders);" command?
Basically you need to include Authorization header with the content like:
Authorization: Bearer your-access-token-here
TBH I am not familiar with spring http client library you're using, so
not sure if you're sending headers correctly.
Marek
On 12/11/15 01:08, harsh mahey wrote:
>
> I am getting 401 unAuthorized when im trying to delete a user.I was
> able to create the user with this id.And i am able to delete the user
> using Advanced REST Chrome client using same DELETE URL.
>
> Can you guide what am i doing wrong here.
>
>
> Thanks
>
>
> *****************ERROR***********************************************************
>
> org.springframework.web.client.HttpClientErrorException: 401 Unauthorized
>
> at
> org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
>
> at
> org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:641)
>
> at
> org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:597)
>
> at
> org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557)
>
> at
> org.springframework.web.client.RestTemplate.delete(RestTemplate.java:429)
>
> at
> com.snrapps.mwp.domain.security.KeyCloakAdminAdapter.deleteUser(KeyCloakAdminAdapter.java:256)
>
> at
> com.snrapps.mwp.domain.security.KeyCloakAdminAdapter.main(KeyCloakAdminAdapter.java:55)
>
> *****************CODE**************************************************************
>
> public boolean deleteUser(String userId) {
>
> AccessTokenResponse accessTokenResponse = getToken();
>
> org.springframework.http.HttpEntity<String> entity = new
> org.springframework.http.HttpEntity<String>(getHeaders(accessTokenResponse.getToken()));
>
> HttpHeaders httpHeaders=entity.getHeaders();
>
> System.out.println(httpHeaders);
>
> RestTemplate restTemplate = new RestTemplate();
>
> String urlForDeleteUser=
> "http://XXXXX.com:XXXX/auth/admin/realmsMyAppsRealm/users/"+ userId;
>
> System.out.println(urlForDeleteUser);
>
> restTemplate.delete(urlForDeleteUser, entity);
>
> System.out.println("done");
>
>
> returntrue;
>
> }
>
>
>
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20151112/4647bc8b/attachment.html
More information about the keycloak-user
mailing list