I am trying to find the best way to access the UsersResource.java Rest services outside the keycloak admin application to get a user's information. How do I make a request using just the client's credentials?
I currently use something like this but I get a 401 because I am using a user's oauth token and they only have user privileges:
SkeletonKeySession session = (SkeletonKeySession) request
.getAttribute(SkeletonKeySession.class.getName());
ResteasyClient client = new ResteasyClientBuilder()
.trustStore(session.getMetadata().getTruststore())
.hostnameVerification(
ResteasyClientBuilder.HostnameVerificationPolicy.ANY)
.build();
String username = request.getRemoteUser();
Profile profile = null;
try {
Response response = client
.path(username)
.request()
.header(HttpHeaders.AUTHORIZATION,
"Bearer " + session.getTokenString()).get();
// Get the existing entry if there is one. Otherwise, just return
// the regular
// entity retrieved from the remote system.
try {
profile = profileRepository
.findByRegistrationId(member.getId());
} catch (NoResultException e) {
// ignore
}
} finally {
client.close();
}
Is there a way for the application to make a request directly as an admin without giving the user admin privileges?