fschmtt / keycloak-rest-api-client-php Goto Github PK
View Code? Open in Web Editor NEWPHP client to interact with Keycloak's Admin REST API.
License: MIT License
PHP client to interact with Keycloak's Admin REST API.
License: MIT License
According to the REST API documentation, GET /admin/realms/{realm}/users
should include list of credentials users possess. But it is not in the response even for users with credentials. I am not sure if this is an intentional restriction from Keycloak or an oversight in the client, but unfortunately, there is no support for GET /admin/realms/{realm}/users/{user-id}/credentials
endpoint at all to rely on as an alternative solution. Having an access to credentials data would particularly helpful to get information on password renewals, account activation time.
We try to setup a new realm using this library. However this fails because the Resource representation api doesn't accept the id
field when creating a resource. We get the error:
Client error: POST http://.../admin/realms/.../clients resulted in a 400 Bad Request response:\n
{"error":"Unrecognized field "id" (class org.keycloak.representations.idm.authorization.ResourceRepresentation), not m (truncated...).
Suggestion is to filter the id field when it's not set. So on fetch the object will contain an id, but when posting a new resource to create one it will not error. I saw that a feature exists to filter properties with a certain attribute. Would this be a useful approach for the resource id as well? So the code would look like this:
class Resource extends Representation
{
public function __construct(
#[OmmitNull]
protected ?string $id,
//....
Implementing it this way would allow us to reuse the behavior on other fields of representations, in the same way.
This issue relates to #93
Hi! This file was not checked into the repository.
PHP Fatal error: Uncaught Error: Class 'Fschmtt\Keycloak\Representation\PasswordPolicyType' not found in /root/migration/vendor/fschmtt/keycloak-rest-api-client-php/src/Mapper/JsonToServerInfoMapper.php:86
Thanks, Sven
I believe that returning information about the created entity is very useful for several use cases
Keycloak v23
Hello! A new problem seem to appears with new Keycloak version
17:42:25 ERROR [app] Property "features" does not exist in "Fschmtt\Keycloak\Representation\ServerInfo"
Related to this feature: keycloak/keycloak#17733
Hi there! Thanks for this awesome Keycloak PHP client.
I don't think it's currently possible, but I have to ask: is there a way to override the default master
Realm and specify my own Realm when creating the Keycloak client? I have a use case where I'd like to authenticate Clients/Users on the Realm level. I believe this is possible in the official Keycloak Admin Client. Something like this should do it:
// Fschmtt\Keycloak\Http\Client.php
public function __construct(
private readonly Keycloak $keycloak,
private readonly ClientInterface $httpClient,
private readonly TokenStorageInterface $tokenStorage,
private readonly ?string $realmName = null
) {}
...
/**
* @return array{access_token: string, refresh_token: string}
*/
private function fetchTokens(): array
{
try {
$response = $this->httpClient->request(
'POST',
$this->keycloak->getBaseUrl() . sprintf('/realms/%s/protocol/openid-connect/token', $this->realmName ?? 'master'),
[
'form_params' => [
...
],
],
);
} catch (ClientException $e) {
$response = $this->httpClient->request(
'POST',
$this->keycloak->getBaseUrl() . sprintf('/realms/%s/protocol/openid-connect/token', $this->realmName ?? 'master'),
[
'form_params' => [
...
],
]
);
}
...
}
...
What do you think? π
It is not straightforward to create a credential representation out of an existing bcrypt hash value due to the lack of hashedSaltedValue
.
A user would need to decompose the hash manually before making a Credential representation.
The official REST API expects the body of the POST /realms request to be a file, while the implemented client receives a representation. This approach makes sense, but can we modify the method to work with both a direct file path and a representation?
This can even be extended to accept a directory of dissected import data generated by Keycloak's export command:
bin/kc.sh export --dir data
This would likely be the primary use case for consumers. One could store a default realm configuration in a specific location within the project and import it programmatically, instead of manually building a representation of an entire realm from multiple files in the code.
Hi,
Reading the code of executeActionsEmail() I don't see any options to send a body containing the list of actions.
Do I miss something?
For me we should be able to send a body parameter containing a JSON array of string + optionally a client_id, lifespan and redirect_uri.
If you are open to contributions we could maybe contribute to the project.
Jean
I have noticed that retrieving clients by client ID is not possible. The confusion is compounded by naming the client UUID parameter as client ID, leading developers to mistakenly believe that the library expects a client ID for resource retrieval.
Adding a method at least like users()->search(['clientId' => 'client-id']) would simplify the process.
My use case:
I added custom APIs to Keycloak, and through your library I canβt access them (without forking)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.