<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">What's the output of the "System.<span
        class="">out</span>.println(<span class="">httpHeaders</span>);"
      command?<br>
      <br>
      Basically you need to include Authorization header with the
      content like: <br>
      <br>
      Authorization: Bearer your-access-token-here<br>
      <br>
      TBH I am not familiar with spring http client library you're
      using, so not sure if you're sending headers correctly.<br>
      <br>
      Marek<br>
      <br>
      On 12/11/15 01:08, harsh mahey wrote:<br>
    </div>
    <blockquote
cite="mid:CA+YyFz5qRtH+sJEOYetV6Jze7LVSPzeMwkXaZ47tBP93gtA_iw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <p class="">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.</p>
        <p class="">Can you guide what am i doing wrong here.</p>
        <p class=""><br>
        </p>
        <p class="">Thanks</p>
        <p class=""><br>
        </p>
        <p class="">*****************ERROR***********************************************************</p>
        <p class=""><span class="">org.springframework.web.client.HttpClientErrorException</span><span
            class="">: 401 Unauthorized</span></p>
        <p class=""><span class=""> </span>at
          org.springframework.web.client.DefaultResponseErrorHandler.handleError(<span
            class="">DefaultResponseErrorHandler.java:91</span>)</p>
        <p class=""><span class=""> </span>at
          org.springframework.web.client.RestTemplate.handleResponse(<span
            class="">RestTemplate.java:641</span>)</p>
        <p class=""><span class=""> </span>at
          org.springframework.web.client.RestTemplate.doExecute(<span
            class="">RestTemplate.java:597</span>)</p>
        <p class=""><span class=""> </span>at
          org.springframework.web.client.RestTemplate.execute(<span
            class="">RestTemplate.java:557</span>)</p>
        <p class=""><span class=""> </span>at
          org.springframework.web.client.RestTemplate.delete(<span
            class="">RestTemplate.java:429</span>)</p>
        <p class=""><span class=""> </span>at
          com.snrapps.mwp.domain.security.KeyCloakAdminAdapter.deleteUser(<span
            class="">KeyCloakAdminAdapter.java:256</span>)</p>
        <p class=""><span class="">
          </span></p>
        <p class=""><span class=""> </span>at
          com.snrapps.mwp.domain.security.KeyCloakAdminAdapter.main(<span
            class="">KeyCloakAdminAdapter.java:55</span>)</p>
        <p class=""><span class="">*****************CODE**************************************************************</span></p>
        <p class=""><span class=""> </span><span class="">public</span>
          <span class="">boolean</span> deleteUser(String <span
            class="">userId</span>) {</p>
        <p class=""><span class=""> </span><span class=""> </span>AccessTokenResponse
          <span class="">accessTokenResponse</span> = getToken();</p>
        <p class="">org.springframework.http.HttpEntity&lt;String&gt; <span
            class="">entity</span> = <span class="">new</span>
          org.springframework.http.HttpEntity&lt;String&gt;(getHeaders(<span
            class="">accessTokenResponse</span>.getToken()));</p>
        <p class=""><span class=""> </span><span class=""> </span>HttpHeaders
          <span class="">httpHeaders</span>=<span class="">entity</span>.getHeaders();</p>
        <p class=""><span class=""> </span><span class=""> </span>System.<span
            class="">out</span>.println(<span class="">httpHeaders</span>);</p>
        <p class=""><span class=""> </span><span class=""> </span>RestTemplate
          <span class="">restTemplate</span> = <span class="">new</span>
          RestTemplate();</p>
        <p class=""><span class=""><span class=""> </span><span
              class=""> </span>String </span><span class="">urlForDeleteUser</span><span
            class=""> = </span>"http://XXXXX.com:XXXX/auth/admin/realmsMyAppsRealm/users/"<span
            class=""> + </span><span class="">userId</span><span
            class="">;</span></p>
        <p class=""><span class=""> </span><span class=""> </span>System.<span
            class="">out</span>.println(<span class="">urlForDeleteUser</span>);</p>
        <p class=""><span class=""><span class=""> </span><span
              class=""> </span></span>restTemplate<span class="">.delete(</span>urlForDeleteUser<span
            class="">, </span>entity<span class="">);</span></p>
        <p class=""><span class=""> </span><span class=""> </span></p>
        <p class=""><span class=""> </span><span class=""> </span></p>
        <p class=""><span class=""> </span><span class=""> </span></p>
        <p class=""><span class=""> </span><span class=""> </span></p>
        <p class=""><span class=""> </span><span class=""> </span>System.<span
            class="">out</span>.println(<span class="">"done"</span>);</p>
        <p class=""><br>
        </p>
        <p class=""><span class=""><span class=""> </span><span
              class=""> </span></span>return<span class=""> </span>true<span
            class="">;</span></p>
        <p class=""><span class=""> </span>}</p>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
keycloak-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/keycloak-user">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></pre>
    </blockquote>
    <br>
  </body>
</html>