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/DTO/UserRepresentationDTO.php b/src/DTO/UserRepresentationDTO.php index 9e45d15..43cc971 100644 --- a/src/DTO/UserRepresentationDTO.php +++ b/src/DTO/UserRepresentationDTO.php @@ -18,9 +18,9 @@ public function __construct( public string $id, public string $username, public bool $emailVerified, - public string $name, - public string $firstName, - public string $lastName, + public ?string $name, + public ?string $firstName, + public ?string $lastName, public string $email, public ?bool $enabled, public ?int $createdTimestamp, @@ -85,9 +85,9 @@ public static function fromArray(array $data, ?string $client_id = null): self id: $data['sub'], username: $data['preferred_username'], emailVerified: $data['email_verified'], - name: $data['name'], - firstName: $data['given_name'], - lastName: $data['family_name'], + name: $data['name'] ?? null, + firstName: $data['given_name'] ?? null, + lastName: $data['family_name'] ?? null, email: $data['email'], enabled: $data['enabled'] ?? null, createdTimestamp: $data['createdTimestamp'] ?? null, diff --git a/src/Interface/IamClientInterface.php b/src/Interface/IamClientInterface.php index 5675df8..abdb8a5 100644 --- a/src/Interface/IamClientInterface.php +++ b/src/Interface/IamClientInterface.php @@ -13,7 +13,7 @@ public function refreshToken(AccessTokenInterface $token): ?AccessTokenInterface public function verifyToken(AccessTokenInterface $token): ?UserRepresentationDTO; - public function userInfo(AccessTokenInterface $token): ?UserRepresentationDTO; + public function userInfo(AccessTokenInterface $token, bool $mapToDto = true): null|array|UserRepresentationDTO; public function fetchUserFromToken(AccessTokenInterface $token): ?KeycloakResourceOwner; diff --git a/src/Provider/KeycloakClient.php b/src/Provider/KeycloakClient.php index 4d066ab..9dc9223 100644 --- a/src/Provider/KeycloakClient.php +++ b/src/Provider/KeycloakClient.php @@ -124,7 +124,7 @@ public function verifyToken(AccessTokenInterface $token): ?UserRepresentationDTO } } - public function userInfo(AccessTokenInterface $token): ?UserRepresentationDTO + public function userInfo(AccessTokenInterface $token, bool $mapToDto = true): null|array|UserRepresentationDTO { try { $this->verifyToken($token); @@ -140,6 +140,10 @@ public function userInfo(AccessTokenInterface $token): ?UserRepresentationDTO 'user' => $user->toArray(), ]); + if (!$mapToDto) { + return $user->toArray(); + } + return UserRepresentationDTO::fromArray($user->toArray(), $this->client_id); } catch (\Exception $e) { diff --git a/src/Service/Service.php b/src/Service/Service.php index d47d1c7..6156a83 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 === '' || $content === null) { throw new \UnexpectedValueException('Empty response'); }