forked from fschmtt/keycloak-rest-api-client-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroups-all.php
More file actions
32 lines (23 loc) · 813 Bytes
/
Copy pathgroups-all.php
File metadata and controls
32 lines (23 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
declare(strict_types=1);
use Fschmtt\Keycloak\Builder;
use Fschmtt\Keycloak\OAuth\GrantType;
use Fschmtt\Keycloak\Representation\Group;
require_once __DIR__ . '/../vendor/autoload.php';
$keycloak = (new Builder())
->withBaseUrl($_SERVER['KEYCLOAK_BASE_URL'] ?? 'http://keycloak:8080')
->withGrantType(GrantType::password('admin', 'admin'))
->build();
$realm = 'master';
$groups = $keycloak->groups()->all($realm);
echo sprintf('Realm "%s" has the following groups:%s', $realm, PHP_EOL);
foreach ($groups as $group) {
echoGroup($group);
}
function echoGroup(Group $group, int $level = 1): void
{
echo sprintf('%s> Group "%s"%s', str_repeat('-', $level), $group->getName(), PHP_EOL);
foreach ($group->getSubGroups() as $group) {
echoGroup($group, $level + 1);
}
}