<div dir="ltr">Thank you.  I tried what you said.  I am able access that REST service on the Keycloak server but it returns an AccountService object.  Actually, I get a 406 error response on my end.  I think it is because I did not have the keycloak-services dependency in my application&#39;s pom.  However, when I add it and I try to start the server, I get the error: Could not find constructor for class: org.keycloak.services.resources.RealmsResource.  Should I make my own local version of AccountService and not add keycloak-services to my application?  What is the best approach?  Any ideas why I might be getting a 406 error?  <div>
<br></div><div><div>SkeletonKeySession session = (SkeletonKeySession) request</div><div>                .getAttribute(SkeletonKeySession.class.getName());</div><div>        ResteasyClient client = new ResteasyClientBuilder()</div>
<div>                .trustStore(session.getMetadata().getTruststore())</div><div>                .hostnameVerification(</div><div>                        ResteasyClientBuilder.HostnameVerificationPolicy.ANY)</div><div>                .build();</div>
<div><br></div><div>        String username = request.getRemoteUser();</div><div><br></div><div>        Profile profile = null;</div><div><br></div><div>        try {</div><div>        </div><div>            Response response = client</div>
<div>                    .target(&quot;<a href="http://server:8080/auth/rest/realms/myrealm/account">http://server:8080/auth/rest/realms/myrealm/account</a>&quot;)</div><div>                    .request()</div><div>                    .header(HttpHeaders.AUTHORIZATION,</div>
<div>                            &quot;Bearer &quot; + session.getTokenString()).get();</div></div><div><br></div><div>.</div><div>.</div><div>.</div><div>  </div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Wed, Mar 5, 2014 at 3:09 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">
There&#39;s also a Keycloak specific mechanism for accessing the account of the user associated with the token.<br>
<br>
To do this open the scope mappings for your app/client, and select &#39;account&#39; in the application roles, select &#39;view-profile&#39; and click the right-arrow. This will allow your app/client to view the profile of the current user.<br>

<br>
Then you can make a request (with bearer token) to:<br>
<br>
/auth/rest/realms/myrealm/account<br>
<br>
In the future we&#39;ll add support to do all account specific things through these REST endpoints to support all operations provided by the account management application.<br>
<div><div class="h5"><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>
&gt; To: <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
&gt; Sent: Tuesday, 4 March, 2014 7:15:31 PM<br>
&gt; Subject: [keycloak-user] How to access realms/{realm}/users/{user} with       Application<br>
&gt;<br>
&gt; Hello,<br>
&gt;<br>
&gt; I am trying to find the best way to access the UsersResource.java Rest<br>
&gt; services outside the keycloak admin application to get a user&#39;s information.<br>
&gt; How do I make a request using just the client&#39;s credentials?<br>
&gt;<br>
&gt; I currently use something like this but I get a 401 because I am using a<br>
&gt; user&#39;s oauth token and they only have user privileges:<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; 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; <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; .path(username)<br>
&gt; .request()<br>
&gt; .header(HttpHeaders.AUTHORIZATION,<br>
&gt; &quot;Bearer &quot; + session.getTokenString()).get();<br>
&gt;<br>
&gt; // Get the existing entry if there is one. Otherwise, just return<br>
&gt; // the regular<br>
&gt; // entity retrieved from the remote system.<br>
&gt; try {<br>
&gt; profile = profileRepository<br>
&gt; .findByRegistrationId(member.getId());<br>
&gt;<br>
&gt; } catch (NoResultException e) {<br>
&gt; // ignore<br>
&gt; }<br>
&gt;<br>
&gt; } finally {<br>
&gt; client.close();<br>
&gt; }<br>
&gt;<br>
&gt; Is there a way for the application to make a request directly as an admin<br>
&gt; without giving the user admin privileges?<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; keycloak-user mailing list<br>
&gt; <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
</blockquote></div><br></div>