From 901c50067b866b2e50d5a9ac4567550cd94a48a1 Mon Sep 17 00:00:00 2001 From: Mehran Niknafs Date: Mon, 4 Nov 2024 17:25:56 +0100 Subject: [PATCH 1/3] Update README to reflect correct configuration structure for Keycloak client --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b0a0d84..d4f89ea 100644 --- a/README.md +++ b/README.md @@ -253,8 +253,9 @@ First you need to add a new section to the bundle configuration file: ```yaml # config/packages/mainick_keycloak_client.yaml -security: - default_target_route_name: '%env(TARGET_ROUTE_NAME)%' +mainick_keycloak_client: + security: + default_target_route_name: '%env(TARGET_ROUTE_NAME)%' ``` Then you need to configure the Keycloak redirect uri to the `mainick_keycloak_security_auth_connect_check` bundle route, which redirects to the default route or referer route after successful login. @@ -286,8 +287,8 @@ mainick_keycloak_client: encryption_key: '%env(IAM_ENCRYPTION_KEY)%' encryption_key_path: '%env(IAM_ENCRYPTION_KEY_PATH)%' version: '%env(IAM_VERSION)%' -security: - default_target_route_name: '%env(TARGET_ROUTE_NAME)%' + security: + default_target_route_name: '%env(TARGET_ROUTE_NAME)%' ``` ### Route configuration From dcf70fb42f46e94c8589ae79d67a7b286f0c10ba Mon Sep 17 00:00:00 2001 From: Mehran Niknafs Date: Tue, 5 Nov 2024 15:29:29 +0100 Subject: [PATCH 2/3] Refactor getClientRoles method to ensure it always returns an array --- src/Token/KeycloakResourceOwner.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Token/KeycloakResourceOwner.php b/src/Token/KeycloakResourceOwner.php index 3f5429d..b3d6f49 100644 --- a/src/Token/KeycloakResourceOwner.php +++ b/src/Token/KeycloakResourceOwner.php @@ -94,7 +94,7 @@ private function getRealRoles(): ?array * * @return array|null */ - private function getClientRoles(?string $client_id = null): ?array + private function getClientRoles(?string $client_id = null): array { $roles = []; @@ -110,6 +110,10 @@ private function getClientRoles(?string $client_id = null): ?array $roles = $this->response['resource_access'][$client_id]['roles'] ?? []; } + if (!$roles) { + return []; + } + return $roles; } From 7b0dbfd849166e303c527f50a83dbd655bd6b886 Mon Sep 17 00:00:00 2001 From: Mehran Niknafs Date: Tue, 5 Nov 2024 17:20:13 +0100 Subject: [PATCH 3/3] Revert "Refactor getClientRoles method to ensure it always returns an array" This reverts commit dcf70fb42f46e94c8589ae79d67a7b286f0c10ba. --- src/Token/KeycloakResourceOwner.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Token/KeycloakResourceOwner.php b/src/Token/KeycloakResourceOwner.php index b3d6f49..3f5429d 100644 --- a/src/Token/KeycloakResourceOwner.php +++ b/src/Token/KeycloakResourceOwner.php @@ -94,7 +94,7 @@ private function getRealRoles(): ?array * * @return array|null */ - private function getClientRoles(?string $client_id = null): array + private function getClientRoles(?string $client_id = null): ?array { $roles = []; @@ -110,10 +110,6 @@ private function getClientRoles(?string $client_id = null): array $roles = $this->response['resource_access'][$client_id]['roles'] ?? []; } - if (!$roles) { - return []; - } - return $roles; }