Skip to content

Commit

Permalink
Send internal id not client id to fetch client
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Eelen committed Jun 7, 2024
1 parent ada312e commit 62cc202
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/Keycloak/Client/KeycloakApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function createClient(
ClientIdFactory $clientIdFactory
): Client {
$clientId = $clientIdFactory->create();
$id = Uuid::uuid4();

try {
$response = $this->client->sendWithBearer(
Expand All @@ -44,7 +45,7 @@ public function createClient(
sprintf('admin/realms/%s/clients', $realm->internalName),
[],
Json::encode(IntegrationToKeycloakClientConverter::convert(
Uuid::uuid4(),
$id,
$integration,
$clientId
))
Expand All @@ -61,7 +62,7 @@ public function createClient(

$this->logger->info(sprintf('Client %s for realm %s created with client id %s', $integration->name, $realm->publicName, $clientId));

return $this->fetchClient($realm, $integration, $clientId);
return $this->fetchClient($realm, $integration, $id->toString());
}

/**
Expand Down Expand Up @@ -111,13 +112,13 @@ public function deleteScopes(Client $client): void
/**
* @throws KeyCloakApiFailed
*/
private function fetchClient(Realm $realm, Integration $integration, string $clientId): Client
private function fetchClient(Realm $realm, Integration $integration, string $id): Client
{
try {
$response = $this->client->sendWithBearer(
new Request(
'GET',
sprintf('admin/realms/%s/clients/%s', $realm->internalName, $clientId)
sprintf('admin/realms/%s/clients/%s', $realm->internalName, $id)
),
$realm
);
Expand All @@ -129,7 +130,7 @@ private function fetchClient(Realm $realm, Integration $integration, string $cli
}

return Client::createFromJson($realm, $integration->id, Json::decodeAssociatively($body));
} catch (Throwable $e) {
} catch (KeyCloakApiFailed $e) {
throw KeyCloakApiFailed::failedToFetchClient($realm, $e->getMessage());
}
}
Expand Down

0 comments on commit 62cc202

Please sign in to comment.