Skip to content

Commit

Permalink
Keycloak 23 support
Browse files Browse the repository at this point in the history
Fixes #77

Fixes #78
  • Loading branch information
fschmtt committed Nov 29, 2023
1 parent 176cb89 commit 7088797
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
keycloak: [17.0.0, 18.0.0, 19.0.0, 20.0.0, 21.0.0, 22.0.0, 22.0.5]
keycloak: [17.0.0, 18.0.0, 19.0.0, 20.0.0, 21.0.0, 22.0.0, 22.0.5, 23.0.0]

env:
KEYCLOAK_VERSION: ${{ matrix.keycloak }}
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
![PHP Legacy (Keycloak compatibility)](https://github.com/fschmtt/keycloak-rest-api-client-php/actions/workflows/php-integration-legacy.yml/badge.svg?branch=main)

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

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

Expand Down Expand Up @@ -43,28 +43,28 @@ echo sprintf(
```
will print e.g.
```text
Keycloak 22.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.
Keycloak 23.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.

## Available Resources
### [Attack Detection](https://www.keycloak.org/docs-api/22.0.0/rest-api/index.html#_attack_detection_resource)
### [Attack Detection](https://www.keycloak.org/docs-api/23.0.0/rest-api/index.html#_attack_detection_resource)
| Endpoint | Response | API |
|----------|----------|-----|
| `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/22.0.0/rest-api/index.html#_clients_resource)
### [Clients](https://www.keycloak.org/docs-api/23.0.0/rest-api/index.html#_clients_resource)
| Endpoint | Response | API |
|----------|----------|-----|
| `GET /admin/realms/{realm}/clients` | [ClientCollection](src/Collection/ClientCollection.php) | [Clients::all()](src/Resource/Clients.php) |
| `GET /admin/realms/{realm}/clients/{id}` | [Client](src/Representation/Client.php) | [Clients::get()](src/Resource/Clients.php) |
| `PUT /admin/realms/{realm}/clients/{id}` | [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) |

### [Groups](https://www.keycloak.org/docs-api/22.0.0/rest-api/index.html#_clients_resource)
### [Groups](https://www.keycloak.org/docs-api/23.0.0/rest-api/index.html#_clients_resource)
| Endpoint | Response | API |
|----------|----------|-----|
| `GET /admin/realms/{realm}/groups` | [GroupCollection](src/Collection/GroupCollection.php) | [Groups::all()](src/Resource/Groups.php) |
Expand All @@ -73,7 +73,7 @@ More examples can be found in the [examples](examples) directory.
| `POST /admin/realms/{realm}/groups` | `n/a` | [Groups::import()](src/Resource/Groups.php) |
| `DELETE /admin/realms/{realm}/groups` | `n/a` | [Groups::delete()](src/Resource/Groups.php) |

### [Realms Admin](https://www.keycloak.org/docs-api/22.0.0/rest-api/index.html#_realms_admin_resource)
### [Realms Admin](https://www.keycloak.org/docs-api/23.0.0/rest-api/index.html#_realms_admin_resource)
| Endpoint | Response | API |
|----------|----------|-----|
| `POST /admin/realms` | [Realm](src/Representation/Realm.php) | [Realms::import()](src/Resource/Realms.php) |
Expand All @@ -86,7 +86,7 @@ More examples can be found in the [examples](examples) directory.
| `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/22.0.0/rest-api/index.html#_users_resource)
### [Users](https://www.keycloak.org/docs-api/23.0.0/rest-api/index.html#_users_resource)
| Endpoint | Response | API |
|----------|----------|-----|
| `GET /admin/realms/{realm}/users` | [UserCollection](src/Collection/UserCollection.php) | [Users::all()](src/Resource/Users.php) |
Expand All @@ -104,15 +104,15 @@ More examples can be found in the [examples](examples) directory.
| `DELETE /{realm}/users/{id}/role-mappings/realm` | `n/a` | [Users::removeRealmRoles()](src/Resource/Users.php) |
| `PUT /{realm}/users/{id}/execute-actions-email` | `n/a` | [Users::executeActionsEmail()](src/Resource/Users.php) |

### [Roles](https://www.keycloak.org/docs-api/22.0.0/rest-api/index.html#_roles_resource)
### [Roles](https://www.keycloak.org/docs-api/23.0.0/rest-api/index.html#_roles_resource)
| Endpoint | Response | API |
|----------|----------|-----|
| `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/22.0.0/rest-api/index.html#_root_resource)
### [Root](https://www.keycloak.org/docs-api/23.0.0/rest-api/index.html#_root_resource)
| Endpoint | Response | API |
|----------|----------|-----|
| `GET /admin/serverinfo` | [ServerInfo](src/Representation/ServerInfo.php) | [ServerInfo::get()](src/Resource/ServerInfo.php) |
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
working_dir: /app

keycloak:
image: quay.io/keycloak/keycloak:22.0.0
image: quay.io/keycloak/keycloak:23.0.0
command: start-dev
environment:
KEYCLOAK_ADMIN: admin
Expand Down
2 changes: 1 addition & 1 deletion docker/keycloak/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG KEYCLOAK_VERSION=22.0.0
ARG KEYCLOAK_VERSION=23.0.0
FROM quay.io/keycloak/keycloak:${KEYCLOAK_VERSION}

ENTRYPOINT [ "/opt/keycloak/bin/kc.sh", "start-dev" ]
5 changes: 5 additions & 0 deletions src/Representation/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Fschmtt\Keycloak\Representation;

use Fschmtt\Keycloak\Attribute\Since;
use Fschmtt\Keycloak\Collection\GroupCollection;
use Fschmtt\Keycloak\Type\Map;

Expand All @@ -15,6 +16,7 @@
* @method string|null getName()
* @method string|null getPath()
* @method string[]|null getRealmRoles()
* @method int|null getSubGroupCount()
* @method Group[]|null getSubGroups()
* @method self withAccess(?Map $access)
* @method self withAttributes(?Map $attributes)
Expand All @@ -23,6 +25,7 @@
* @method self withName(?string $name)
* @method self withPath(?string $path)
* @method self withRealmRoles(?array $realmRoles)
* @method self withSubGroupCount(?int $subGroupCount)
* @method self withSubGroups(?array $subGroups)
*
* @codeCoverageIgnore
Expand All @@ -38,6 +41,8 @@ public function __construct(
protected ?string $path = null,
/** @var string[]|null */
protected ?array $realmRoles = null,
#[Since('23.0.0')]
protected ?int $subGroupCount = null,
protected ?GroupCollection $subGroups = null,
) {
}
Expand Down
10 changes: 10 additions & 0 deletions src/Representation/Realm.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@
* @method string|null getWebAuthnPolicyAuthenticatorAttachment()
* @method bool|null getWebAuthnPolicyAvoidSameAuthenticatorRegister()
* @method int|null getWebAuthnPolicyCreateTimeout()
* @method string[]|null getWebAuthnPolicyExtraOrigins()
* @method array|null getWebAuthnPolicyPasswordlessAcceptableAaguids()
* @method string|null getWebAuthnPolicyPasswordlessAttestationConveyancePreference()
* @method string|null getWebAuthnPolicyPasswordlessAuthenticatorAttachment()
* @method bool|null getWebAuthnPolicyPasswordlessAvoidSameAuthenticatorRegister()
* @method int|null getWebAuthnPolicyPasswordlessCreateTimeout()
* @method string[]|null getWebAuthnPolicyPasswordlessPolicyExtraOrigins()
* @method string|null getWebAuthnPolicyPasswordlessRequireResidentKey()
* @method string|null getWebAuthnPolicyPasswordlessRpEntityName()
* @method string|null getWebAuthnPolicyPasswordlessRpId()
Expand Down Expand Up @@ -252,11 +254,13 @@
* @method self withWebAuthnPolicyAuthenticatorAttachment(?string $value)
* @method self withWebAuthnPolicyAvoidSameAuthenticatorRegister(?bool $value)
* @method self withWebAuthnPolicyCreateTimeout(?int $value)
* @method self withWebAuthnPolicyExtraOrigins(?array $value)
* @method self withWebAuthnPolicyPasswordlessAcceptableAaguids(?array $value)
* @method self withWebAuthnPolicyPasswordlessAttestationConveyancePreference(?string $value)
* @method self withWebAuthnPolicyPasswordlessAuthenticatorAttachment(?string $value)
* @method self withWebAuthnPolicyPasswordlessAvoidSameAuthenticatorRegister(?bool $value)
* @method self withWebAuthnPolicyPasswordlessCreateTimeout(?int $value)
* @method self withWebAuthnPolicyPasswordlessExtraOrigins(?array $value)
* @method self withWebAuthnPolicyPasswordlessRequireResidentKey(?string $value)
* @method self withWebAuthnPolicyPasswordlessRpEntityName(?string $value)
* @method self withWebAuthnPolicyPasswordlessRpId(?string $value)
Expand Down Expand Up @@ -392,11 +396,17 @@ public function __construct(
protected ?bool $webAuthnPolicyAvoidSameAuthenticatorRegister = null,
protected ?int $webAuthnPolicyCreateTimeout = null,
/** @var string[]|null */
#[Since('23.0.0')]
protected ?array $webAuthnPolicyExtraOrigins = null,
/** @var string[]|null */
protected ?array $webAuthnPolicyPasswordlessAcceptableAaguids = null,
protected ?string $webAuthnPolicyPasswordlessAttestationConveyancePreference = null,
protected ?string $webAuthnPolicyPasswordlessAuthenticatorAttachment = null,
protected ?bool $webAuthnPolicyPasswordlessAvoidSameAuthenticatorRegister = null,
protected ?int $webAuthnPolicyPasswordlessCreateTimeout = null,
/** @var string[]|null */
#[Since('23.0.0')]
protected ?array $webAuthnPolicyPasswordlessExtraOrigins = null,
protected ?string $webAuthnPolicyPasswordlessRequireResidentKey = null,
protected ?string $webAuthnPolicyPasswordlessRpEntityName = null,
protected ?string $webAuthnPolicyPasswordlessRpId = null,
Expand Down
9 changes: 5 additions & 4 deletions tests/Unit/Http/PropertyFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testDoesNotFilterPropertiesIfVersionIsNotProvided(): void
}

/**
* @dataProvider keycloakVersions
* @dataProvider supportedKeycloakVersions
*/
public function testFiltersOutPropertyWhichHasNotYetBeenIntroduced(string $version): void
{
Expand All @@ -42,7 +42,7 @@ public function testFiltersOutPropertyWhichHasNotYetBeenIntroduced(string $versi
}

/**
* @dataProvider keycloakVersions
* @dataProvider supportedKeycloakVersions
*/
public function testFiltersOutPropertyWhichHasBeenRemoved(string $version): void
{
Expand All @@ -57,7 +57,7 @@ public function testFiltersOutPropertyWhichHasBeenRemoved(string $version): void
}

/**
* @dataProvider keycloakVersions
* @dataProvider supportedKeycloakVersions
*/
public function testFiltersOutPropertyWhichHasBeenIntroducedAndRemoved(string $version): void
{
Expand Down Expand Up @@ -89,7 +89,7 @@ public function testMemoizesFilteredPropertiesOfRepresentation(): void
static::assertArrayHasKey($representation::class, $memoizedFilteredProperties);
}

public static function keycloakVersions(): Generator
public static function supportedKeycloakVersions(): Generator
{
yield ['13.0.0'];
yield ['14.0.0'];
Expand All @@ -101,5 +101,6 @@ public static function keycloakVersions(): Generator
yield ['20.0.0'];
yield ['21.0.0'];
yield ['22.0.0'];
yield ['23.0.0'];
}
}

0 comments on commit 7088797

Please sign in to comment.