PHPackages                             dgrevink/php-keycloak-rest-api-client - 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. dgrevink/php-keycloak-rest-api-client

ActiveLibrary[API Development](/categories/api)

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

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

v0.40.0(1mo ago)095↑342.1%mitPHPPHP ^8.2

Since Mar 18Pushed 1mo agoCompare

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

READMEChangelog (1)Dependencies (10)Versions (2)Used By (0)

[![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

41

—

FairBetter than 88% of packages

Maintenance96

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 88.5% 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

Unknown

Total

1

Last Release

52d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d31311c6f206de9386f3ee0bbbe775c172ae4f93068512e7228487ce1eea4a6?d=identicon)[dgrevink](/maintainers/dgrevink)

---

Top Contributors

[![fschmtt](https://avatars.githubusercontent.com/u/5806324?v=4)](https://github.com/fschmtt "fschmtt (470 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)")[![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)")[![darthf1](https://avatars.githubusercontent.com/u/17253332?v=4)](https://github.com/darthf1 "darthf1 (3 commits)")[![dgrevink](https://avatars.githubusercontent.com/u/5262497?v=4)](https://github.com/dgrevink "dgrevink (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)")[![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/dgrevink-php-keycloak-rest-api-client/health.svg)

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

###  Alternatives

[sylius/sylius

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

8.4k5.6M647](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[googleads/googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP

67410.3M25](/packages/googleads-googleads-php-lib)[fschmtt/keycloak-rest-api-client-php

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

4684.7k2](/packages/fschmtt-keycloak-rest-api-client-php)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[concrete5/core

Concrete core subtree split

19159.3k48](/packages/concrete5-core)

PHPackages © 2026

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