REST API for accessing token

396 views
Skip to first unread message

Deeps

unread,
Dec 3, 2019, 12:20:36 AM12/3/19
to dcm4che
 Hi,

What is the keycloakID for using the below REST API call for accessing token?

/token/{keycloakID} - Get access token from keycloak

Gunter Zeilinger

unread,
Dec 3, 2019, 3:11:59 AM12/3/19
to dcm...@googlegroups.com
It refers an configured Keyclock Server configuration item. The service is deprecated in favor of  /token2/{webapp}.

Also, both are intended to access a token from a second Keycloak instance for accessing REST Service on another node secured that Keycloak instance. You already need a token from the own Keycloak server using that service!


Sent with ProtonMail Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
--
You received this message because you are subscribed to the Google Groups "dcm4che" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dcm4che+u...@googlegroups.com.

Deeps

unread,
Dec 3, 2019, 4:11:12 AM12/3/19
to dcm4che

Okay.. Thank you for the reply.

Deeps

unread,
Dec 3, 2019, 5:04:39 AM12/3/19
to dcm4che

Actually I am using REST API call for deleting studies and series(for our viewer program in java) for which I am trying to access token. When I tried the curl command for accessing token, that worked fine.

RESULT=`curl --data "grant_type=password&client_id=dcm4chee-arc-ui&username=admin&password=admin" http://<IP:PORT>/auth/realms/dcm4che/protocol/openid-connect/token`

But when trying to access token using java application, I am getting HTTP error code : 400.

String name = "admin";
String password = "admin";
String authString = name + ":" + password;
URL url = new URL(urlString);
HttpURLConnection conn1 = (HttpURLConnection) url.openConnection();
 conn1.setDoOutput(true);
 conn1.setRequestProperty("Authorization", "Basic " + authString);
 conn1.setRequestProperty("grant_type", "password");
 conn1.setRequestProperty("client_id", "dcm4chee-arc-ui");
 conn1.setRequestProperty("Content-Type", "application/json");
 conn1.setRequestMethod("POST");
if (conn1.getResponseCode() != 200)
{
    throw new RuntimeException("Failed to access token: HTTP error code : "
            + conn1.getResponseCode());
}

InputStream is = conn1.getInputStream();
InputStreamReader isr = new InputStreamReader(is);


This is the java segment I am using to get the token. I am getting http error code 400. Could you please help me with this? Do I need to add any more parameters?





On Tuesday, December 3, 2019 at 10:50:36 AM UTC+5:30, Deeps wrote:

Gunter Zeilinger

unread,
Dec 3, 2019, 5:21:00 AM12/3/19
to dcm...@googlegroups.com
Better to use org.keycloak.admin.client.KeycloakBuilder from keycloak-admin-client , which also takes care to renew the token transparently.



Sent with ProtonMail Secure Email.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
--
You received this message because you are subscribed to the Google Groups "dcm4che" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dcm4che+u...@googlegroups.com.

Deeps

unread,
Dec 3, 2019, 5:25:26 AM12/3/19
to dcm4che
Thank you so much. I will try this.


On Tuesday, December 3, 2019 at 10:50:36 AM UTC+5:30, Deeps wrote:
Reply all
Reply to author
Forward
0 new messages