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

ActiveLibrary[API Development](/categories/api)

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

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

0.1.10(7mo ago)24.7k↓26.9%31mitPHPPHP ^8.4CI passing

Since Mar 11Pushed 7mo agoCompare

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

READMEChangelog (10)Dependencies (14)Versions (12)Used By (1)

[![codecov](https://camo.githubusercontent.com/98b151c4cdcc6cb8c5daffeddf70bfc68cd1ffd9ff9c7b7d622037f830fd1c44/68747470733a2f2f636f6465636f762e696f2f67682f6f766572747275652f6b6579636c6f616b2d726573742d6170692d636c69656e742d7068702f67726170682f62616467652e7376673f746f6b656e3d4a535031544231325544)](https://codecov.io/gh/overtrue/keycloak-rest-api-client-php)[![PHP Analysis](https://github.com/overtrue/keycloak-rest-api-client-php/actions/workflows/php-analysis.yml/badge.svg?branch=main)](https://github.com/overtrue/keycloak-rest-api-client-php/actions/workflows/php-analysis.yml/badge.svg?branch=main)[![PHP Unit](https://github.com/overtrue/keycloak-rest-api-client-php/actions/workflows/php-unit.yml/badge.svg?branch=main)](https://github.com/overtrue/keycloak-rest-api-client-php/actions/workflows/php-unit.yml/badge.svg?branch=main)[![PHP Integration (Keycloak compatibility)](https://github.com/overtrue/keycloak-rest-api-client-php/actions/workflows/php-integration.yml/badge.svg?branch=main)](https://github.com/overtrue/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).

> This is a fork of [fschmtt/keycloak-rest-api-client-php](https://github.com/fschmtt/keycloak-rest-api-client-php)

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

[](#installation)

Install via Composer:

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

Usage
-----

[](#usage)

Example:

```
$keycloak = new \Overtrue\Keycloak\Keycloak(
    baseUrl: 'http://keycloak:8080',
    username: 'admin',
    password: 'admin'
);

$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.

```

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

Caching
-------

[](#caching)

The Keycloak client supports powerful caching based on PSR-16 (Simple Cache) standard:

```
use DateInterval;
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\Cache\Psr16Cache;

$keycloak = new \Overtrue\Keycloak\Keycloak(
    baseUrl: 'http://keycloak:8080',
    username: 'admin',
    password: 'admin',
    cache: new Psr16Cache(new RedisAdapter($redis)),
    cacheConfig: [
        'prefix' => 'myapp_',
        'ttl' => [
            'version' => new DateInterval('PT6H'),
            'server_info' => new DateInterval('PT1H'),
            'access_token' => new DateInterval('PT1H'),
            'refresh_token' => new DateInterval('P1D'),
        ]
    ]
);
```

For detailed caching configuration and usage, see [CACHE.md](CACHE.md).

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 \Overtrue\Keycloak\Representation\Representation
{
    public function __construct(
        protected ?string $id = null,
        protected ?string $name = null,
    ) {
    }
}

class MyCustomResource extends \Overtrue\Keycloak\Resource\Resource
{
    public function myCustomEndpoint(): MyCustomRepresentation
    {
        return $this->queryExecutor->executeQuery(
            new \Overtrue\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`ResponseInterface[AttackDetection::clear()](src/Resource/AttackDetection.php)`GET /admin/realms/{realm}/attack-detection/brute-force/users/{userId}`[StringMap](src/Type/StringMap.php)[AttackDetection::userStatus()](src/Resource/AttackDetection.php)`DELETE /admin/realms/{realm}/attack-detection/brute-force/users/{userId}`ResponseInterface[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/{clientUuid}`[ClientRepresentation](src/Representation/ClientRepresentation.php)[Clients::get()](src/Resource/Clients.php)`POST /admin/realms/{realm}/clients`[ClientRepresentation](src/Representation/ClientRepresentation.php)[Clients::import()](src/Resource/Clients.php)`PUT /admin/realms/{realm}/clients/{clientUuid}`[ClientRepresentation](src/Representation/ClientRepresentation.php)[Clients::update()](src/Resource/Clients.php)`DELETE /admin/realms/{realm}/clients/{clientUuid}`ResponseInterface[Clients::delete()](src/Resource/Clients.php)`GET /admin/realms/{realm}/clients/{clientUuid}/user-sessions`array[Clients::getUserSessions()](src/Resource/Clients.php)`GET /admin/realms/{realm}/clients/{clientUuid}/client-secret`Credential[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}/group-by-path/{path}`[Group](src/Representation/Group.php)[Groups::byPath()](src/Resource/Groups.php)`GET /admin/realms/{realm}/groups/{groupId}/children`[GroupCollection](src/Collection/GroupCollection.php)[Groups::children()](src/Resource/Groups.php)`GET /admin/realms/{realm}/groups/{groupId}/members`[UserCollection](src/Collection/UserCollection.php)[Groups::members()](src/Resource/Groups.php)`GET /admin/realms/{realm}/groups/{groupId}`[Group](src/Representation/Group.php)[Groups::get()](src/Resource/Groups.php)`POST /admin/realms/{realm}/groups`[Group](src/Representation/Group.php)[Groups::create()](src/Resource/Groups.php)`POST /admin/realms/{realm}/groups/{groupId}/children`[Group](src/Representation/Group.php)[Groups::createChild()](src/Resource/Groups.php)`PUT /admin/realms/{realm}/groups/{groupId}`ResponseInterface[Groups::update()](src/Resource/Groups.php)`DELETE /admin/realms/{realm}/groups/{groupId}`ResponseInterface[Groups::delete()](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`[Organization](src/Representation/Organization.php)[Organizations::create()](src/Resource/Organizations.php)`PUT /admin/realms/{realm}/organizations/{id}`[Organization](src/Representation/Organization.php)[Organizations::update()](src/Resource/Organizations.php)`DELETE /admin/realms/{realm}/organizations/{id}`ResponseInterface[Organizations::delete()](src/Resource/Organizations.php)`GET /admin/realms/{realm}/organizations/{orgId}/members`[MemberCollection](src/Collection/MemberCollection.php)[Organizations::members()](src/Resource/Organizations.php)`GET /admin/realms/{realm}/organizations/{orgId}/members/count`int[Organizations::membersCount()](src/Resource/Organizations.php)`GET /admin/realms/{realm}/organizations/{orgId}/members/{memberId}`Member[Organizations::member()](src/Resource/Organizations.php)`POST /admin/realms/{realm}/organizations/{orgId}/members`ResponseInterface[Organizations::addMember()](src/Resource/Organizations.php)`DELETE /admin/realms/{realm}/organizations/{orgId}/members/{memberId}`ResponseInterface[Organizations::deleteMember()](src/Resource/Organizations.php)`GET /admin/realms/{realm}/organizations/members/{memberId}/organizations`[OrganizationCollection](src/Collection/OrganizationCollection.php)[Organizations::memberOrganizations()](src/Resource/Organizations.php)`GET /admin/realms/{realm}/organizations/{orgId}/members/{memberId}/organizations`[OrganizationCollection](src/Collection/OrganizationCollection.php)[Organizations::orgMemberOrganizations()](src/Resource/Organizations.php)`POST /admin/realms/{realm}/organizations/{id}/members/invite-user`ResponseInterface[Organizations::inviteUser()](src/Resource/Organizations.php)`POST /admin/realms/{realm}/organizations/{id}/members/invite-existing-user`ResponseInterface[Organizations::inviteExistingUser()](src/Resource/Organizations.php)`POST /admin/realms/{realm}/organizations/{id}/identity-providers`ResponseInterface[Organizations::linkIdp()](src/Resource/Organizations.php)`DELETE /admin/realms/{realm}/organizations/{id}/identity-providers/{alias}`ResponseInterface[Organizations::unlinkIdp()](src/Resource/Organizations.php)### [Realms Admin](https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_realms_admin)

[](#realms-admin)

EndpointResponseAPI`GET /admin/realms`[RealmCollection](src/Collection/RealmCollection.php)[Realms::all()](src/Resource/Realms.php)`GET /admin/realms/{realm}`[Realm](src/Representation/Realm.php)[Realms::get()](src/Resource/Realms.php)`POST /admin/realms`[Realm](src/Representation/Realm.php)[Realms::import()](src/Resource/Realms.php)`PUT /admin/realms/{realm}`[Realm](src/Representation/Realm.php)[Realms::update()](src/Resource/Realms.php)`DELETE /admin/realms/{realm}`ResponseInterface[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[Realms::keys()](src/Resource/Realms.php)`DELETE /admin/realms/{realm}/admin-events`ResponseInterface[Realms::deleteAdminEvents()](src/Resource/Realms.php)`POST /admin/realms/{realm}/clear-keys-cache`ResponseInterface[Realms::clearKeysCache()](src/Resource/Realms.php)`POST /admin/realms/{realm}/clear-realm-cache`ResponseInterface[Realms::clearRealmCache()](src/Resource/Realms.php)`POST /admin/realms/{realm}/clear-user-cache`ResponseInterface[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)`GET /admin/realms/{realm}/users/{userId}`[UserRepresentation](src/Representation/UserRepresentation.php)[Users::get()](src/Resource/Users.php)`POST /admin/realms/{realm}/users`[UserRepresentation](src/Representation/UserRepresentation.php)[Users::create()](src/Resource/Users.php)`PUT /admin/realms/{realm}/users/{userId}`[UserRepresentation](src/Representation/UserRepresentation.php)[Users::update()](src/Resource/Users.php)`DELETE /admin/realms/{realm}/users/{userId}`ResponseInterface[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}`ResponseInterface[Users::joinGroup()](src/Resource/Users.php)`DELETE /admin/realms/{realm}/users/{userId}/groups/{groupId}`ResponseInterface[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`ResponseInterface[Users::addRealmRoles()](src/Resource/Users.php)`DELETE /admin/realms/{realm}/users/{userId}/role-mappings/realm`ResponseInterface[Users::removeRealmRoles()](src/Resource/Users.php)`PUT /admin/realms/{realm}/users/{userId}/execute-actions-email`ResponseInterface[Users::executeActionsEmail()](src/Resource/Users.php)`POST /admin/realms/{realm}/users/{userId}/federated-identity/{provider}`ResponseInterface[Users::addFederatedIdentity()](src/Resource/Users.php)`DELETE /admin/realms/{realm}/users/{userId}/federated-identity/{provider}`ResponseInterface[Users::removeFederatedIdentity()](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`[Role](src/Representation/Role.php)[Roles::create()](src/Resource/Roles.php)`DELETE /admin/realms/{realm}/roles/{roleName}`ResponseInterface[Roles::delete()](src/Resource/Roles.php)`PUT /admin/realms/{realm}/roles/{roleName}`[Role](src/Representation/Role.php)[Roles::update()](src/Resource/Roles.php)### [Root](https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_root)

[](#root)

EndpointResponseAPI`GET /admin/serverinfo`[ServerInfoRepresentation](src/Representation/ServerInfoRepresentation.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
- `fix`: Fix coding style issues (Laravel pint)
- `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

43

—

FairBetter than 91% of packages

Maintenance62

Regular maintenance activity

Popularity27

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.1% 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 ~20 days

Total

11

Last Release

232d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c507e57eab402e81335012357b7d7df6c5cafda3073adcc94b475037127d263f?d=identicon)[overtrue](/maintainers/overtrue)

---

Top Contributors

[![fschmtt](https://avatars.githubusercontent.com/u/5806324?v=4)](https://github.com/fschmtt "fschmtt (433 commits)")[![overtrue](https://avatars.githubusercontent.com/u/1472352?v=4)](https://github.com/overtrue "overtrue (30 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)")[![wjfz](https://avatars.githubusercontent.com/u/3372236?v=4)](https://github.com/wjfz "wjfz (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)")[![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)")[![saibotk](https://avatars.githubusercontent.com/u/10776964?v=4)](https://github.com/saibotk "saibotk (1 commits)")[![jaapio](https://avatars.githubusercontent.com/u/1060433?v=4)](https://github.com/jaapio "jaapio (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sylius/sylius

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

8.4k5.6M651](/packages/sylius-sylius)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-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.0k15.4k](/packages/prestashop-prestashop)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[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)

PHPackages © 2026

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