Keycloak: retrieve all available client sessions

為{幸葍}努か 提交于 2019-12-11 22:06:01

问题


I'm using Keycloak to secure my Spring app (which is registered in Keycloak as my_app client). Now I want to retrieve all active sessions of that client. Would be great if I could do it using keycloak-admin-client, because I couldn't figure out how to use Admin Rest API in java...

So far I've tried this:

Keycloak keycloak=KeycloakBuilder.builder()
    .serverUrl("http://localhost:8180/auth")
    .realm("master")
    .username("admin")
    .password("admin")
    .clientId("admin-cli")
    .resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build()).build();

ClientResource client=keycloak.realm("MY_REALM").clients().get("my_app").getUserSessions(1,100);

But it throws 404 error.


回答1:


List clientRepresentations=keycloak.realm("MY_REALM").clients().findByClientId("my_app"); ClientRepresentation representation=clientRepresentations.get(0); ClientResource resource=keycloak.realm("MY_REALM").clients().get(representation.getId());

did the trick.

And this retrieves all active sessions in client:

List sessions=resource.getUserSessions(0,1000);



来源:https://stackoverflow.com/questions/50869055/keycloak-retrieve-all-available-client-sessions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!