<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">urlForDeleteUser must match the same port the access token was issued for. &nbsp;I’ll just say the token has port 9912 in it. Not sure if your real&nbsp;urlForDeleteUser URL does.<div class=""><br class=""></div><div class="">FYI - you tried to obscure your host info but access tokens are not encrypted.</div><div class=""><br class=""></div><div class="">&nbsp;<br class=""><div apple-content-edited="true" class="">
<div class="">Scott Rossillo</div><div class="">Smartling | Senior Software Engineer</div><div class=""><a href="mailto:srossillo@smartling.com" class="">srossillo@smartling.com</a></div><div class=""><br class=""></div><div class=""><a href="https://app.sigstr.com/uc/55e5d41c6533390d03580000" id="campaignblock" target="_blank" style="box-sizing: border-box; color: rgb(0, 75, 118); outline-offset: -2px; font-family: gesta, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px; widows: 1; background-color: rgb(255, 255, 255); outline: 0px !important;" class=""><img alt="Latest News + Events" border="0" src="https://app.sigstr.com/uc/55e5d41c6533390d03580000/img" style="box-sizing: border-box; border: 0px; vertical-align: top; max-width: 100%; height: auto; width: inherit; color: blue; font-family: Helvetica; font-size: 12px;" class=""></a><span style="color: rgb(169, 169, 169); font-family: gesta, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px; widows: 1; background-color: rgb(255, 255, 255);" class=""></span><div id="watermark" style="box-sizing: border-box; color: rgb(169, 169, 169); font-family: gesta, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 20px; widows: 1; background-color: rgb(255, 255, 255);" class=""><a href="http://www.sigstr.com/" style="box-sizing: border-box; color: rgb(0, 124, 194); text-decoration: none; background-color: transparent; outline: 0px !important;" class=""><img alt="Powered by Sigstr" border="0" src="https://app.sigstr.com/uc/55e5d41c6533390d03580000/watermark" style="box-sizing: border-box; border: 0px; vertical-align: top; max-width: 100%; height: auto; width: inherit; color: rgb(99, 99, 99); font-family: Helvetica; font-size: 11px;" class=""></a></div></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Nov 12, 2015, at 9:16 AM, harsh mahey &lt;<a href="mailto:harshmahey@gmail.com" class="">harshmahey@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">So this is what i see in my header<div class=""><br class=""></div><div class="">********</div><div class=""><p class="">entity:&lt;{Content-Type=[application/json], Authorization=[Bearer eyJhbGciOiJSUzI1NiJ9.eyJqdGkiOiIzYjk2NTI0ZC0yYzY3LTRlY2YtOWRiYS1kMTNiYWZkZDc3OTIiLCJleHAiOjE0NDczMzgwODQsIm5iZiI6MCwiaWF0IjoxNDQ3MzM3Nzg0LCJpc3MiOiJodHRwOi8vc2Vuc2VucmVzcG9uZC5jb206OTkxMi9hdXRoL3JlYWxtcy9TbnJBcHBzUmVhbG0iLCJhdWQiOiJzbnJhcHBzLXdlYiIsInN1YiI6IjU1ODhmOWViLTg5ZDItNGVmMi04ZTM3LWVkM2RkY2RhMDdhMSIsInR5cCI6IkJlYXJlciIsImF6cCI6InNucmFwcHMtd2ViIiwic2Vzc2lvbl9zdGF0ZSI6ImVmZjFlY2Q0LWZjMTUtNGJjMi05MDgxLWM2YTA5NGMxODFmOCIsImNsaWVudF9zZXNzaW9uIjoiN2ZjZWU5ZDItN2I4Yi00ZmVmLTkzYjEtZjAwNzI3YWNkNzA2IiwiYWxsb3dlZC1vcmlnaW5zIjpbIioiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbImFkbWluIiwidXNlciJdfSwicmVzb3VyY2VfYWNjZXNzIjp7InNucmFwcHMtd2ViIjp7InJvbGVzIjpbInVzZXIiXX0sImFjY291bnQiOnsicm9sZXMiOlsidmlldy1wcm9maWxlIiwibWFuYWdlLWFjY291bnQiXX0sInJlYWxtLW1hbmFnZW1lbnQiOnsicm9sZXMiOlsidmlldy1yZWFsbSIsIm1hbmFnZS1jbGllbnRzIiwibWFuYWdlLWV2ZW50cyIsInZpZXctZXZlbnRzIiwidmlldy1pZGVudGl0eS1wcm92aWRlcnMiLCJtYW5hZ2UtaWRlbnRpdHktcHJvdmlkZXJzIiwidmlldy11c2VycyIsInZpZXctY2xpZW50cyIsInJlYWxtLWFkbWluIiwiY3JlYXRlLWNsaWVudCIsImltcGVyc29uYXRpb24iLCJtYW5hZ2UtdXNlcnMiLCJtYW5hZ2UtcmVhbG0iXX19LCJlbWFpbCI6ImhhcnNobWFoZXlAZ21haWwuY29tIiwibmFtZSI6IkNoYXJhbiBTaW5naCIsImZhbWlseV9uYW1lIjoiU2luZ2giLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJzbnJhcHBzLXVzZXIiLCJnaXZlbl9uYW1lIjoiQ2hhcmFuIn0.eyyqyobdaYesLH13zoPSwxd1yj3HE5GsshLXgQIaucJ9uVs7LpoiXedB0NfLf2rMYVHW6Yo0tX9DA2o_tGdlmNnbFnNqh3GDXIIcqQwIrYTGGzTFQo8k-8TzWlg5GXjuc3_b0GRGdbUd_BgbqahcxhHyciXNTzOM9iuzObXwfmKjCTy8FU-QxNntC-yThOidFoUOYxjmUxyfubq13GH0VVm_1obxQcI5_B6WnIubNFBpyjb70SgZZSVjM1-22WDm_TRlqtKomDALqsD6SAep-fV1yAxR9RLXTJzJpMb5a6Zt2PGOiE2G0cBq_KyfEO33v6IsxYTmIke3_2oV939jbA]}&gt;</p></div><div class=""><br class=""></div><div class="">*******</div><div class=""><br class=""></div><div class="">Here is my updated code</div><div class=""><br class=""></div><div class="">*********</div><div class=""><p class=""><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=""><br class=""></p><p class=""><span class="">        </span><span class="">        </span>org.springframework.http.HttpEntity&lt;String&gt; <span class="">entity</span> = <span class="">new</span> org.springframework.http.HttpEntity&lt;String (getHeaders(<span class="">accessTokenResponse</span>.getToken()));</p><div class=""><span class="">        </span><span class="">        </span><br class="webkit-block-placeholder"></div><p class=""><span class="">        </span><span class="">        </span>System.<span class="">out</span>.println(<span class="">"entity:"</span>+<span class="">entity</span>);</p><div class=""><span class="">        </span><span class="">        </span><br class="webkit-block-placeholder"></div><div class=""><span class="">        </span><span class="">        </span><br class="webkit-block-placeholder"></div><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>"<a href="http://xxxx.com:xxx/auth/admin/realms/MyAppsRealm/users/" class="">http://XXXX.com:XXX/auth/admin/realms/MyAppsRealm/users/</a>"<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="">,String.</span><span class="">class</span><span class="">);</span></p><div class=""><span class="">        </span><span class="">        </span><br class="webkit-block-placeholder"></div><p class=""><span class="">        </span><span class="">        </span>System.<span class="">out</span>.println(<span class="">"done"</span>);</p><p class=""><br class=""></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><div class=""><br class=""></div><div class="">********</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Nov 12, 2015 at 1:50 AM, Marek Posolda <span dir="ltr" class="">&lt;<a href="mailto:mposolda@redhat.com" target="_blank" class="">mposolda@redhat.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF" class="">
    <div class="">What's the output of the "System.<span class="">out</span>.println(<span class="">httpHeaders</span>);"
      command?<br class="">
      <br class="">
      Basically you need to include Authorization header with the
      content like: <br class="">
      <br class="">
      Authorization: Bearer your-access-token-here<br class="">
      <br class="">
      TBH I am not familiar with spring http client library you're
      using, so not sure if you're sending headers correctly.<br class="">
      <br class="">
      Marek<br class="">
      <br class="">
      On 12/11/15 01:08, harsh mahey wrote:<br class="">
    </div>
    <blockquote type="cite" class="">
      <div dir="ltr" class=""><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 class="">
        </p><p class="">Thanks</p><p class=""><br class="">
        </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><div class=""><span class="">
          </span><br class="webkit-block-placeholder"></div><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>"<a href="http://xxxxx.com:xxxx/auth/admin/realmsMyAppsRealm/users/" class="">http://XXXXX.com:XXXX/auth/admin/realmsMyAppsRealm/users/</a>"<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><div class=""><span class=""> </span><span class=""> </span><br class="webkit-block-placeholder"></div><div class=""><span class=""> </span><span class=""> </span><br class="webkit-block-placeholder"></div><div class=""><span class=""> </span><span class=""> </span><br class="webkit-block-placeholder"></div><div class=""><span class=""> </span><span class=""> </span><br class="webkit-block-placeholder"></div><p class=""><span class=""> </span><span class=""> </span>System.<span class="">out</span>.println(<span class="">"done"</span>);</p><p class=""><br class="">
        </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 class="">
      <fieldset class=""></fieldset>
      <br class="">
      <pre class="">_______________________________________________
keycloak-user mailing list
<a href="mailto:keycloak-user@lists.jboss.org" target="_blank" class="">keycloak-user@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank" class="">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></pre>
    </blockquote>
    <br class="">
  </div>

</blockquote></div><br class=""></div>
_______________________________________________<br class="">keycloak-user mailing list<br class=""><a href="mailto:keycloak-user@lists.jboss.org" class="">keycloak-user@lists.jboss.org</a><br class="">https://lists.jboss.org/mailman/listinfo/keycloak-user</div></blockquote></div><br class=""></div></body></html>