diff --git a/composer.json b/composer.json index aa86447..650ad6d 100644 --- a/composer.json +++ b/composer.json @@ -11,10 +11,10 @@ "require": { "php": ">=8.2", "stevenmaguire/oauth2-keycloak": "^5.1", - "symfony/routing": "^7.2", - "symfony/security-bundle": "^7.2", - "symfony/http-kernel": "^7.2", - "symfony/framework-bundle": "^7.2", + "symfony/routing": "^6.4 || ^7.2", + "symfony/security-bundle": "^6.4 || ^7.2", + "symfony/http-kernel": "^6.4 || ^7.2", + "symfony/framework-bundle": "^6.4 || ^7.2", "symfony/serializer-pack": "^1.3" }, "require-dev": { diff --git a/src/Interface/IamClientInterface.php b/src/Interface/IamClientInterface.php index 5675df8..f0f2c6c 100644 --- a/src/Interface/IamClientInterface.php +++ b/src/Interface/IamClientInterface.php @@ -15,6 +15,8 @@ public function verifyToken(AccessTokenInterface $token): ?UserRepresentationDTO public function userInfo(AccessTokenInterface $token): ?UserRepresentationDTO; + public function userInfoRaw(AccessTokenInterface $token): ?array; + public function fetchUserFromToken(AccessTokenInterface $token): ?KeycloakResourceOwner; /** diff --git a/src/Provider/KeycloakClient.php b/src/Provider/KeycloakClient.php index 4d066ab..8a8c55a 100644 --- a/src/Provider/KeycloakClient.php +++ b/src/Provider/KeycloakClient.php @@ -151,6 +151,33 @@ public function userInfo(AccessTokenInterface $token): ?UserRepresentationDTO } } + public function userInfoRaw(AccessTokenInterface $token): ?array + { + try { + $this->verifyToken($token); + $accessToken = new AccessTokenLib([ + 'access_token' => $token->getToken(), + 'refresh_token' => $token->getRefreshToken(), + 'expires' => $token->getExpires(), + 'values' => $token->getValues(), + ]); + $resourceOwner = $this->keycloakProvider->getResourceOwner($accessToken); + $user = new KeycloakResourceOwner($resourceOwner->toArray(), $token); + $this->keycloakClientLogger->info('KeycloakClient::userInfoRaw', [ + 'user' => $user->toArray(), + ]); + + return $user->toArray(); + } + catch (\Exception $e) { + $this->keycloakClientLogger->error('KeycloakClient::userInfoRaw', [ + 'error' => $e->getMessage(), + ]); + + return null; + } + } + public function fetchUserFromToken(AccessTokenInterface $token): ?KeycloakResourceOwner { try { diff --git a/src/Service/Service.php b/src/Service/Service.php index d47d1c7..6dbc99e 100644 --- a/src/Service/Service.php +++ b/src/Service/Service.php @@ -51,7 +51,7 @@ protected function executeQuery(string $path, string $returnType, ?Criteria $cri 'response' => $content, ]); - if (empty($content)) { + if ($content === '' || trim($content) === '') { throw new \UnexpectedValueException('Empty response'); }