PHPackages                             fschmtt/keycloak-rest-api-client-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. fschmtt/keycloak-rest-api-client-php

ActiveLibrary[API Development](/categories/api)

fschmtt/keycloak-rest-api-client-php
====================================

PHP client to interact with Keycloak's Admin REST API.

v0.42.0(2w ago)49108.6k↓40.8%38[3 issues](https://github.com/fschmtt/keycloak-rest-api-client-php/issues)[1 PRs](https://github.com/fschmtt/keycloak-rest-api-client-php/pulls)1mitPHPPHP ^8.2CI passing

Since Apr 2Pushed 2w ago4 watchersCompare

[ Source](https://github.com/fschmtt/keycloak-rest-api-client-php)[ Packagist](https://packagist.org/packages/fschmtt/keycloak-rest-api-client-php)[ RSS](/packages/fschmtt-keycloak-rest-api-client-php/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (50)Versions (73)Used By (1)

[![codecov](https://camo.githubusercontent.com/13a6be1234237c99e75ed9eeb868c7bb0908e9131e56907ba802a6c7eaf36dc9/68747470733a2f2f636f6465636f762e696f2f67682f667363686d74742f6b6579636c6f616b2d726573742d6170692d636c69656e742d7068702f67726170682f62616467652e7376673f746f6b656e3d75446c51647142463556)](https://codecov.io/gh/fschmtt/keycloak-rest-api-client-php)[![PHP Analysis](https://github.com/fschmtt/keycloak-rest-api-client-php/actions/workflows/php-analysis.yml/badge.svg?branch=main)](https://github.com/fschmtt/keycloak-rest-api-client-php/actions/workflows/php-analysis.yml/badge.svg?branch=main)[![PHP Unit](https://github.com/fschmtt/keycloak-rest-api-client-php/actions/workflows/php-unit.yml/badge.svg?branch=main)](https://github.com/fschmtt/keycloak-rest-api-client-php/actions/workflows/php-unit.yml/badge.svg?branch=main)[![PHP Integration (Keycloak compatibility)](https://github.com/fschmtt/keycloak-rest-api-client-php/actions/workflows/php-integration.yml/badge.svg?branch=main)](https://github.com/fschmtt/keycloak-rest-api-client-php/actions/workflows/php-integration.yml/badge.svg?branch=main)

Keycloak Admin REST API Client
==============================

[](#keycloak-admin-rest-api-client)

PHP client to interact with [Keycloak's Admin REST API](https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html).

Inspired by [keycloak/keycloak-nodejs-admin-client](https://github.com/keycloak/keycloak-nodejs-admin-client).

Installation
------------

[](#installation)

Install via Composer:

```
composer require fschmtt/keycloak-rest-api-client-php
```

Usage
-----

[](#usage)

Example:

```
$keycloak = (new \Fschmtt\Keycloak\Builder())
    ->withBaseUrl('http://keycloak:8080')
    ->withGrantType(\Fschmtt\Keycloak\OAuth\GrantType::password('admin', 'admin'))
    ->build();

$serverInfo = $keycloak->serverInfo()->get();

echo sprintf(
    'Keycloak %s is running on %s/%s (%s) with %s/%s since %s and is currently using %s of %s (%s %%) memory.',
    $serverInfo->getSystemInfo()->getVersion(),
    $serverInfo->getSystemInfo()->getOsName(),
    $serverInfo->getSystemInfo()->getOsVersion(),
    $serverInfo->getSystemInfo()->getOsArchitecture(),
    $serverInfo->getSystemInfo()->getJavaVm(),
    $serverInfo->getSystemInfo()->getJavaVersion(),
    $serverInfo->getSystemInfo()->getUptime(),
    $serverInfo->getMemoryInfo()->getUsedFormated(),
    $serverInfo->getMemoryInfo()->getTotalFormated(),
    100 - $serverInfo->getMemoryInfo()->getFreePercentage(),
);
```

will print e.g.

```
Keycloak 26.0.0 is running on Linux/5.10.25-linuxkit (amd64) with OpenJDK 64-Bit Server VM/11.0.11 since 0 days, 2 hours, 37 minutes, 7 seconds and is currently using 139 MB of 512 MB (28 %) memory.

```

You can authenticate against a specific realm by passing it via the `realm` parameter when constructing the `Keycloak` instance.

More examples can be found in the [examples](examples) directory.

Customization
-------------

[](#customization)

### Custom representations &amp; resources

[](#custom-representations--resources)

You can register and use custom resources by providing your own representations and resources, e.g.:

```
class MyCustomRepresentation extends \Fschmtt\Keycloak\Representation\Representation
{
    public function __construct(
        protected ?string $id = null,
        protected ?string $name = null,
    ) {
    }
}

class MyCustomResource extends \Fschmtt\Keycloak\Resource\Resource
{
    public function myCustomEndpoint(): MyCustomRepresentation
    {
        return $this->queryExecutor->executeQuery(
            new \Fschmtt\Keycloak\Http\Query(
                '/my-custom-endpoint',
                MyCustomRepresentation::class,
            )
        );
    }
}
```

By extending the `Resource` class, you have access to both the `QueryExecutor` and `CommandExecutor`. The `CommandExecutor` is designed to run state-changing commands against the server (without returning a response); the `QueryExecutor` allows fetching resources and representations from the server.

To use your custom resource, pass the fully-qualified class name (FQCN) to the `Keycloak::resource()` method. It provides you with an instance of your resource you can then work with:

```
$keycloak = new Keycloak(
    $_SERVER['KEYCLOAK_BASE_URL'] ?? 'http://keycloak:8080',
    'admin',
    'admin',
);

$myCustomResource = $keycloak->resource(MyCustomResource::class);
$myCustomRepresentation = $myCustomResource->myCustomEndpoint();
```

Available Resources
-------------------

[](#available-resources)

### [Attack Detection](https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_attack_detection)

[](#attack-detection)

EndpointResponseAPI`DELETE /admin/realms/{realm}/attack-detection/brute-force/users``n/a`[AttackDetection::clear()](src/Resource/AttackDetection.php)`GET /admin/realms/{realm}/attack-detection/brute-force/users/{userId}`[Map](src/Type/Map.php)[AttackDetection::userStatus()](src/Resource/AttackDetection.php)`DELETE /admin/realms/{realm}/attack-detection/brute-force/users/{userId}``n/a`[AttackDetection::clearUser()](src/Resource/AttackDetection.php)### [Clients](https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_clients)

[](#clients)

EndpointResponseAPI`GET /admin/realms/{realm}/clients`[ClientCollection](src/Collection/ClientCollection.php)[Clients::all()](src/Resource/Clients.php)`GET /admin/realms/{realm}/clients/{client-uuid}`[Client](src/Representation/Client.php)[Clients::get()](src/Resource/Clients.php)`PUT /admin/realms/{realm}/clients/{client-uuid}`[Client](src/Representation/Client.php)[Clients::update()](src/Resource/Clients.php)`POST /admin/realms/{realm}/clients`[Client](src/Representation/Client.php)[Clients::import()](src/Resource/Clients.php)`GET /admin/realms/{realm}/clients/{clientUuid}/client-secret`[Client](src/Representation/Client.php)[Clients::getClientSecret()](src/Resource/Clients.php)### [Groups](https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_clients)

[](#groups)

EndpointResponseAPI`GET /admin/realms/{realm}/groups`[GroupCollection](src/Collection/GroupCollection.php)[Groups::all()](src/Resource/Groups.php)`GET /admin/realms/{realm}/groups/{id}/children`[GroupCollection](src/Collection/GroupCollection.php)[Groups::children()](src/Resource/Groups.php)`GET /admin/realms/{realm}/groups/{id}/members`[UserCollection](src/Collection/UserCollection.php)[Groups::members()](src/Resource/Groups.php)`GET /admin/realms/{realm}/groups/{id}`[Group](src/Representation/Group.php)[Groups::get()](src/Resource/Groups.php)`PUT /admin/realms/{realm}/groups/{id}``n/a`[Groups::update()](src/Resource/Groups.php)`POST /admin/realms/{realm}/groups``n/a`[Groups::create()](src/Resource/Groups.php)`POST /admin/realms/{realm}/groups/{id}/children``n/a`[Groups::create()](src/Resource/Groups.php)`DELETE /admin/realms/{realm}/groups``n/a`[Groups::delete()](src/Resource/Groups.php)`GET /admin/realms/{realm}/group-by-path/{path}`[Group](src/Representation/Group.php)[Groups::byPath()](src/Resource/Groups.php)### [Organizations](https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_organizations)

[](#organizations)

EndpointResponseAPI`GET /admin/realms/{realm}/organizations`[OrganizationCollection](src/Collection/OrganizationCollection.php)[Organizations::all()](src/Resource/Organizations.php)`GET /admin/realms/{realm}/organizations/{id}`[Organization](src/Representation/Organization.php)[Organizations::get()](src/Resource/Organizations.php)`POST /admin/realms/{realm}/organizations``n/a`[Organizations::create()](src/Resource/Organizations.php)`DELETE /admin/realms/{realm}/organizations/{id}``n/a`[Organizations::delete()](src/Resource/Organizations.php)`POST /admin/realms/{realm}/organizations/{id}/members/invite-user``n/a`[Organizations::inviteUser()](src/Resource/Organizations.php)`POST /admin/realms/{realm}/organizations/{id}/members``n/a`[Organizations::addUser()](src/Resource/Organizations.php)`PUT /admin/realms/{realm}/organizations/{id}``n/a`[Organizations::update()](src/Resource/Organizations.php)### [Realms Admin](https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_realms_admin)

[](#realms-admin)

EndpointResponseAPI`POST /admin/realms`[Realm](src/Representation/Realm.php)[Realms::import()](src/Resource/Realms.php)`GET /admin/realms`[RealmCollection](src/Collection/RealmCollection.php)[Realms::all()](src/Resource/Realms.php)`PUT /admin/realms/{realm}`[Realm](src/Representation/Realm.php)[Realms::update()](src/Resource/Realms.php)`DELETE /admin/realms/{realm}``n/a`[Realms::delete()](src/Resource/Realms.php)`GET /admin/realms/{realm}/admin-events``array`[Realms::adminEvents()](src/Resource/Realms.php)`GET /admin/realms/{realm}/keys`[KeysMetadata](src/Representation/KeysMetadata.php)[Realms::keys()](src/Resource/Realms.php)`DELETE /admin/realms/{realm}/admin-events``n/a`[Realms::deleteAdminEvents()](src/Resource/Realms.php)`POST /admin/realms/{realm}/clear-keys-cache``n/a`[Realms::clearKeysCache()](src/Resource/Realms.php)`POST /admin/realms/{realm}/clear-realm-cache``n/a`[Realms::clearRealmCache()](src/Resource/Realms.php)`POST /admin/realms/{realm}/clear-user-cache``n/a`[Realms::clearUserCache()](src/Resource/Realms.php)### [Users](https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_users)

[](#users)

EndpointResponseAPI`GET /admin/realms/{realm}/users`[UserCollection](src/Collection/UserCollection.php)[Users::all()](src/Resource/Users.php)`POST /admin/realms/{realm}/users``n/a`[Users::create()](src/Resource/Users.php)`GET /admin/realms/{realm}/users/{userId}`[User](src/Representation/User.php)[Users::get()](src/Resource/Users.php)`PUT /admin/realms/{realm}/users/{userId}``n/a`[Users::update()](src/Resource/Users.php)`DELETE /admin/realms/{realm}/users/{userId}``n/a`[Users::delete()](src/Resource/Users.php)`GET /admin/realms/{realm}/users`[UserCollection](src/Collection/UserCollection.php)[Users::search()](src/Resource/Users.php)`PUT /admin/realms/{realm}/users/{userId}/groups/{groupId}``n/a`[Users::joinGroup()](src/Resource/Users.php)`DELETE /admin/realms/{realm}/users/{userId}/groups/{groupId}``n/a`[Users::leaveGroup()](src/Resource/Users.php)`GET /admin/realms/{realm}/users/{userId}/groups`[GroupCollection](src/Collection/GroupCollection.php)[Users::retrieveGroups()](src/Resource/Users.php)`GET /admin/realms/{realm}/users/{userId}/role-mappings/realm`[RoleCollection](src/Collection/RoleCollection.php)[Users::retrieveRealmRoles()](src/Resource/Users.php)`GET /admin/realms/{realm}/users/{userId}/role-mappings/realm/available`[RoleCollection](src/Collection/RoleCollection.php)[Users::retrieveAvailableRealmRoles()](src/Resource/Users.php)`POST /admin/realms/{realm}/users/{userId}/role-mappings/realm``n/a`[Users::addRealmRoles()](src/Resource/Users.php)`DELETE /admin/realms/{realm}/users/{userId}/role-mappings/realm``n/a`[Users::removeRealmRoles()](src/Resource/Users.php)`GET /admin/realms/{realm}/users/{userId}/role-mappings/clients/{clientUuid}`[RoleCollection](src/Collection/RoleCollection.php)[Users::retrieveClientRoles()](src/Resource/Users.php)`GET /admin/realms/{realm}/users/{userId}/role-mappings/clients/{clientUuid}/available`[RoleCollection](src/Collection/RoleCollection.php)[Users::retrieveAvailableClientRoles()](src/Resource/Users.php)`POST /admin/realms/{realm}/users/{userId}/role-mappings/clients/{clientUuid}``n/a`[Users::addClientRoles()](src/Resource/Users.php)`DELETE /admin/realms/{realm}/users/{userId}/role-mappings/clients/{clientUuid}``n/a`[Users::removeClientRoles()](src/Resource/Users.php)`PUT /admin/realms/{realm}/users/{userId}/execute-actions-email``n/a`[Users::executeActionsEmail()](src/Resource/Users.php)`GET /admin/realms/{realm}/users/{userId}/credentials`[CredentialCollection](src/Collection/CredentialCollection.php)[Users::credentials()](src/Resource/Users.php)### [Roles](https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_roles)

[](#roles)

EndpointResponseAPI`GET /admin/realms/{realm}/roles`[RoleCollection](src/Collection/RoleCollection.php)[Roles::all()](src/Resource/Roles.php)`GET /admin/realms/{realm}/roles/{roleName}`[Role](src/Representation/Role.php)[Roles::get()](src/Resource/Roles.php)`POST /admin/realms/{realm}/roles``n/a`[Roles::create()](src/Resource/Roles.php)`DELETE /admin/realms/{realm}/roles/{roleName}``n/a`[Roles::delete()](src/Resource/Roles.php)### [Root](https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_root)

[](#root)

EndpointResponseAPI`GET /admin/serverinfo`[ServerInfo](src/Representation/ServerInfo.php)[ServerInfo::get()](src/Resource/ServerInfo.php)Local development and testing
-----------------------------

[](#local-development-and-testing)

Run `docker compose up -d keycloak` to start a local Keycloak instance listening on .

Run your script (e.g. [examples/serverinfo.php](examples/serverinfo.php)) from within the `php` container:

```
docker compose run --rm php php examples/serverinfo.php
```

### Composer scripts

[](#composer-scripts)

- `analyze`: Run phpstan analysis
- `cs`: Check coding style (PHP CS Fixer)
- `cs:fix`: Fix coding style issues (PHP CS Fixer)
- `test`: Run unit and integration tests
- `test:unit`: Run unit tests
- `test:integration`: Run integration tests (requires a fresh and running Keycloak instance)

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance95

Actively maintained with recent releases

Popularity48

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 88.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~39 days

Recently: every ~21 days

Total

58

Last Release

19d ago

PHP version history (4 changes)0.1.0PHP ^7.4

0.2.1PHP ^8.0

v0.6.0PHP ^8.1

v0.21.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/79636454701f057add2affb9f5374eae3422af5c976d2461e3021dfd68f51428?d=identicon)[fschmtt](/maintainers/fschmtt)

---

Top Contributors

[![fschmtt](https://avatars.githubusercontent.com/u/5806324?v=4)](https://github.com/fschmtt "fschmtt (480 commits)")[![daniellienert](https://avatars.githubusercontent.com/u/642226?v=4)](https://github.com/daniellienert "daniellienert (11 commits)")[![garry08](https://avatars.githubusercontent.com/u/2621893?v=4)](https://github.com/garry08 "garry08 (11 commits)")[![leon-manq](https://avatars.githubusercontent.com/u/64958241?v=4)](https://github.com/leon-manq "leon-manq (6 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![p-weisk](https://avatars.githubusercontent.com/u/28752561?v=4)](https://github.com/p-weisk "p-weisk (4 commits)")[![phillipfickl](https://avatars.githubusercontent.com/u/1156835?v=4)](https://github.com/phillipfickl "phillipfickl (4 commits)")[![darthf1](https://avatars.githubusercontent.com/u/17253332?v=4)](https://github.com/darthf1 "darthf1 (3 commits)")[![petski](https://avatars.githubusercontent.com/u/116610?v=4)](https://github.com/petski "petski (3 commits)")[![jprw10](https://avatars.githubusercontent.com/u/91634301?v=4)](https://github.com/jprw10 "jprw10 (3 commits)")[![foliengriller](https://avatars.githubusercontent.com/u/24498435?v=4)](https://github.com/foliengriller "foliengriller (2 commits)")[![LoicComparet](https://avatars.githubusercontent.com/u/3072631?v=4)](https://github.com/LoicComparet "LoicComparet (2 commits)")[![tpokorra](https://avatars.githubusercontent.com/u/357107?v=4)](https://github.com/tpokorra "tpokorra (2 commits)")[![jahrsensetence](https://avatars.githubusercontent.com/u/66826594?v=4)](https://github.com/jahrsensetence "jahrsensetence (1 commits)")[![jaapio](https://avatars.githubusercontent.com/u/1060433?v=4)](https://github.com/jaapio "jaapio (1 commits)")[![ppatrik](https://avatars.githubusercontent.com/u/8960712?v=4)](https://github.com/ppatrik "ppatrik (1 commits)")[![fma-naitways](https://avatars.githubusercontent.com/u/278715104?v=4)](https://github.com/fma-naitways "fma-naitways (1 commits)")[![saibotk](https://avatars.githubusercontent.com/u/10776964?v=4)](https://github.com/saibotk "saibotk (1 commits)")[![tiran133](https://avatars.githubusercontent.com/u/651050?v=4)](https://github.com/tiran133 "tiran133 (1 commits)")[![overtrue](https://avatars.githubusercontent.com/u/1472352?v=4)](https://github.com/overtrue "overtrue (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/fschmtt-keycloak-rest-api-client-php/health.svg)

```
[![Health](https://phpackages.com/badges/fschmtt-keycloak-rest-api-client-php/health.svg)](https://phpackages.com/packages/fschmtt-keycloak-rest-api-client-php)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M738](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k51.2M339](/packages/api-platform-core)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.1k17.8k](/packages/prestashop-prestashop)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
