How to list all scope-permissions for client with java keycloak-admin-client

45 Views Asked by At

I am using keycloak 23.0.6, spring-boot and the keycloak-admin-client maven dependency. keycloak.realm("realm-name").clients().get("client-id").authorization().permissions().scope() only has 3 functions: create, findById and findByName but no list function. The REST endpoint of keycloak is not the limiting factor, you can list all scope-permissions there: GET /admin/realms/<realm>/clients/<client-id>/authz/resource-server/permission/scope so it just seems to be missing in the keycloak-admin-client library. Is there a way I am missing here or do I have manually implement HTTP requests and parse the result?

I've also tried using the keycloak-authz-client, did not find a list function there either.

1

There are 1 best solutions below

0
On

I figured it out:

fun listAllScopedPermissions(): List<ScopePermissionRepresentation> {
    realm().clients().findByClientId(keycloakProperties.client.id).first().id.let { clientId ->
        val uri = URI.create("${keycloakProperties.url}/admin/realms/<realm>/clients/${clientId}/authz/resource-server/permission/scope")
        val proxy = keycloak.proxy(CustomScopePermissionsResource::class.java, uri)
        return proxy.findAll()
    }
}

interface CustomScopePermissionsResource {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    fun findAll(): List<ScopePermissionRepresentation>
}