<div dir="ltr">Yes, I did realize my stupid mistake right after I sent the e-mail.  It is working as you say.  Thank you, very much for all the help!</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Mar 6, 2014 at 5:31 AM, Stian Thorgersen <span dir="ltr">&lt;<a href="mailto:stian@redhat.com" target="_blank">stian@redhat.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You don&#39;t need to add keycloak-services to your application. It doesn&#39;t actually return AccountService object, AccountService is JAX-RS sub-resource that handles all requests to &#39;account&#39;. Assuming that you&#39;ve looked at the source, have a peak inside AccountService.accountPage that&#39;s what actually handles the request.<br>

<br>
The 406 is caused by missing Accept header. Try adding:<br>
<br>
.header(HttpHeaders.ACCEPT, &quot;application/json&quot;)<br>
<br>
Cheers,<br>
Stian<br>
<div class="im HOEnZb"><br>
----- Original Message -----<br>
&gt; From: &quot;Dean Peterson&quot; &lt;<a href="mailto:peterson.dean@gmail.com">peterson.dean@gmail.com</a>&gt;<br>
</div><div class="HOEnZb"><div class="h5">&gt; To: &quot;Stian Thorgersen&quot; &lt;<a href="mailto:stian@redhat.com">stian@redhat.com</a>&gt;<br>
&gt; Cc: <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
&gt; Sent: Wednesday, 5 March, 2014 8:28:53 PM<br>
&gt; Subject: Re: [keycloak-user] How to access realms/{realm}/users/{user} with Application<br>
&gt;<br>
&gt; Thank you.  I tried what you said.  I am able access that REST service on<br>
&gt; the Keycloak server but it returns an AccountService object.  Actually, I<br>
&gt; get a 406 error response on my end.  I think it is because I did not have<br>
&gt; the keycloak-services dependency in my application&#39;s pom.  However, when I<br>
&gt; add it and I try to start the server, I get the error: Could not find<br>
&gt; constructor for class: org.keycloak.services.resources.RealmsResource.<br>
&gt;  Should I make my own local version of AccountService and not add<br>
&gt; keycloak-services to my application?  What is the best approach?  Any ideas<br>
&gt; why I might be getting a 406 error?<br>
&gt;<br>
&gt; SkeletonKeySession session = (SkeletonKeySession) request<br>
&gt;                 .getAttribute(SkeletonKeySession.class.getName());<br>
&gt;         ResteasyClient client = new ResteasyClientBuilder()<br>
&gt;                 .trustStore(session.getMetadata().getTruststore())<br>
&gt;                 .hostnameVerification(<br>
&gt;<br>
&gt; ResteasyClientBuilder.HostnameVerificationPolicy.ANY)<br>
&gt;                 .build();<br>
&gt;<br>
&gt;         String username = request.getRemoteUser();<br>
&gt;<br>
&gt;         Profile profile = null;<br>
&gt;<br>
&gt;         try {<br>
&gt;<br>
&gt;             Response response = client<br>
&gt;                     .target(&quot;<br>
&gt; <a href="http://server:8080/auth/rest/realms/myrealm/account" target="_blank">http://server:8080/auth/rest/realms/myrealm/account</a>&quot;)<br>
&gt;                     .request()<br>
&gt;                     .header(HttpHeaders.AUTHORIZATION,<br>
&gt;                             &quot;Bearer &quot; + session.getTokenString()).get();<br>
&gt;<br>
&gt; .<br>
&gt; .<br>
&gt; .<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Mar 5, 2014 at 3:09 AM, Stian Thorgersen &lt;<a href="mailto:stian@redhat.com">stian@redhat.com</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; There&#39;s also a Keycloak specific mechanism for accessing the account of<br>
&gt; &gt; the user associated with the token.<br>
&gt; &gt;<br>
&gt; &gt; To do this open the scope mappings for your app/client, and select<br>
&gt; &gt; &#39;account&#39; in the application roles, select &#39;view-profile&#39; and click the<br>
&gt; &gt; right-arrow. This will allow your app/client to view the profile of the<br>
&gt; &gt; current user.<br>
&gt; &gt;<br>
&gt; &gt; Then you can make a request (with bearer token) to:<br>
&gt; &gt;<br>
&gt; &gt; /auth/rest/realms/myrealm/account<br>
&gt; &gt;<br>
&gt; &gt; In the future we&#39;ll add support to do all account specific things through<br>
&gt; &gt; these REST endpoints to support all operations provided by the account<br>
&gt; &gt; management application.<br>
&gt; &gt;<br>
&gt; &gt; ----- Original Message -----<br>
&gt; &gt; &gt; From: &quot;Dean Peterson&quot; &lt;<a href="mailto:peterson.dean@gmail.com">peterson.dean@gmail.com</a>&gt;<br>
&gt; &gt; &gt; To: <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
&gt; &gt; &gt; Sent: Tuesday, 4 March, 2014 7:15:31 PM<br>
&gt; &gt; &gt; Subject: [keycloak-user] How to access realms/{realm}/users/{user} with<br>
&gt; &gt;       Application<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Hello,<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; I am trying to find the best way to access the UsersResource.java Rest<br>
&gt; &gt; &gt; services outside the keycloak admin application to get a user&#39;s<br>
&gt; &gt; information.<br>
&gt; &gt; &gt; How do I make a request using just the client&#39;s credentials?<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; I currently use something like this but I get a 401 because I am using a<br>
&gt; &gt; &gt; user&#39;s oauth token and they only have user privileges:<br>
&gt; &gt; &gt; SkeletonKeySession session = (SkeletonKeySession) request<br>
&gt; &gt; &gt; .getAttribute(SkeletonKeySession.class.getName());<br>
&gt; &gt; &gt; ResteasyClient client = new ResteasyClientBuilder()<br>
&gt; &gt; &gt; .trustStore(session.getMetadata().getTruststore())<br>
&gt; &gt; &gt; .hostnameVerification(<br>
&gt; &gt; &gt; ResteasyClientBuilder.HostnameVerificationPolicy.ANY)<br>
&gt; &gt; &gt; .build();<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; String username = request.getRemoteUser();<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Profile profile = null;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; try {<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Response response = client<br>
&gt; &gt; &gt; .target(&quot; <a href="http://server:8080/auth/rest/admin/realms/myrealm/users/" target="_blank">http://server:8080/auth/rest/admin/realms/myrealm/users/</a> &quot;)<br>
&gt; &gt; &gt; .path(username)<br>
&gt; &gt; &gt; .request()<br>
&gt; &gt; &gt; .header(HttpHeaders.AUTHORIZATION,<br>
&gt; &gt; &gt; &quot;Bearer &quot; + session.getTokenString()).get();<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; // Get the existing entry if there is one. Otherwise, just return<br>
&gt; &gt; &gt; // the regular<br>
&gt; &gt; &gt; // entity retrieved from the remote system.<br>
&gt; &gt; &gt; try {<br>
&gt; &gt; &gt; profile = profileRepository<br>
&gt; &gt; &gt; .findByRegistrationId(member.getId());<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; } catch (NoResultException e) {<br>
&gt; &gt; &gt; // ignore<br>
&gt; &gt; &gt; }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; } finally {<br>
&gt; &gt; &gt; client.close();<br>
&gt; &gt; &gt; }<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Is there a way for the application to make a request directly as an admin<br>
&gt; &gt; &gt; without giving the user admin privileges?<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; _______________________________________________<br>
&gt; &gt; &gt; keycloak-user mailing list<br>
&gt; &gt; &gt; <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
&gt; &gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
&gt; &gt;<br>
&gt;<br>
</div></div></blockquote></div><br></div>