From 14442273bf1e9fe9bdda49f0c7bbe0cc97637163 Mon Sep 17 00:00:00 2001 From: omar-haris Date: Tue, 22 Oct 2024 21:33:00 +0000 Subject: [PATCH] Fix styling --- config/keycloak.php | 10 +- src/Enums/CredentialType.php | 1 - src/Enums/GrantType.php | 1 - src/Enums/UserActionType.php | 1 - src/Exceptions/KeycloakException.php | 24 +- src/Facades/Keycloak.php | 6 +- src/Keycloak.php | 180 ++++++--------- src/KeycloakInterface.php | 23 +- src/KeycloakServiceProvider.php | 1 - src/KeycloakUrlBuilder.php | 29 +-- src/Representation/AddUserRolesRequest.php | 5 +- .../ClientMappingsRepresentation.php | 9 +- .../CompositesRepresentation.php | 7 +- src/Representation/CountUsersRequest.php | 25 +-- src/Representation/CreateRoleRequest.php | 18 +- .../CredentialRepresentation.php | 205 +++++++++--------- src/Representation/DeleteUserRolesRequest.php | 5 +- src/Representation/GetRolesRequest.php | 7 +- src/Representation/GetUsersRequest.php | 31 ++- src/Representation/MappingsRepresentation.php | 7 +- src/Representation/Representation.php | 14 +- src/Representation/RoleRepresentation.php | 24 +- src/Representation/UpdateRoleRequest.php | 11 +- src/Representation/UserRepresentation.php | 69 +++--- tests/TestCase.php | 2 +- 25 files changed, 330 insertions(+), 385 deletions(-) diff --git a/config/keycloak.php b/config/keycloak.php index 93b8a582..a39ae6ef 100644 --- a/config/keycloak.php +++ b/config/keycloak.php @@ -14,7 +14,7 @@ | Keycloak instance is accessible. | */ - 'base_url' => env('KEYCLOAK_BASE_URL','http://localhost:8080'), + 'base_url' => env('KEYCLOAK_BASE_URL', 'http://localhost:8080'), /* |-------------------------------------------------------------------------- @@ -25,7 +25,7 @@ | the Keycloak API. | */ - 'username' => env('KEYCLOAK_USERNAME','admin'), + 'username' => env('KEYCLOAK_USERNAME', 'admin'), /* |-------------------------------------------------------------------------- @@ -48,7 +48,7 @@ | application will communicate with. | */ - 'realm' => env('KEYCLOAK_REALM','master'), + 'realm' => env('KEYCLOAK_REALM', 'master'), /* |-------------------------------------------------------------------------- @@ -60,7 +60,7 @@ | realm to allow API interactions. | */ - 'client_id' => env('KEYCLOAK_CLIENT_ID','admin-cli'), + 'client_id' => env('KEYCLOAK_CLIENT_ID', 'admin-cli'), /* |-------------------------------------------------------------------------- @@ -84,5 +84,5 @@ | method. Other grant types are available, such as 'client_credentials'. | */ - 'grant_type' => env('KEYCLOAK_GRANT_TYPE','password'), + 'grant_type' => env('KEYCLOAK_GRANT_TYPE', 'password'), ]; diff --git a/src/Enums/CredentialType.php b/src/Enums/CredentialType.php index ab2fc895..6f017ea1 100644 --- a/src/Enums/CredentialType.php +++ b/src/Enums/CredentialType.php @@ -5,7 +5,6 @@ /** * CredentialType enum class. * - * @package OpenSeaWave\Keycloak\Enums * @author Omar Haris */ enum CredentialType: string diff --git a/src/Enums/GrantType.php b/src/Enums/GrantType.php index 11f3ba9b..1200eb4e 100644 --- a/src/Enums/GrantType.php +++ b/src/Enums/GrantType.php @@ -5,7 +5,6 @@ /** * Class GrantType * - * @package OpenSeaWave\Keycloak\Enums * @author Omar Haris */ enum GrantType: string diff --git a/src/Enums/UserActionType.php b/src/Enums/UserActionType.php index 7a1dedd6..2b0e41dd 100644 --- a/src/Enums/UserActionType.php +++ b/src/Enums/UserActionType.php @@ -5,7 +5,6 @@ /** * UserActionType enum class. * - * @package OpenSeaWave\Keycloak\Enums * @author Omar Haris */ enum UserActionType: string diff --git a/src/Exceptions/KeycloakException.php b/src/Exceptions/KeycloakException.php index 63d0ea9b..b55ae213 100644 --- a/src/Exceptions/KeycloakException.php +++ b/src/Exceptions/KeycloakException.php @@ -11,7 +11,6 @@ * * This exception is thrown when an error occurs while interacting with the Keycloak API. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class KeycloakException extends Exception @@ -33,16 +32,16 @@ class KeycloakException extends Exception /** * KeycloakException constructor. * - * @param string $message The exception message. - * @param int|null $statusCode The HTTP status code from Keycloak, if available. - * @param Exception|null $previous The previous exception. - * @param ResponseInterface|null $response The HTTP response object, if available. + * @param string $message The exception message. + * @param int|null $statusCode The HTTP status code from Keycloak, if available. + * @param Exception|null $previous The previous exception. + * @param ResponseInterface|null $response The HTTP response object, if available. */ public function __construct( - string $message = "", - int $statusCode = null, - Exception $previous = null, - ResponseInterface $response = null + string $message = '', + ?int $statusCode = null, + ?Exception $previous = null, + ?ResponseInterface $response = null ) { parent::__construct($message, $statusCode, $previous); $this->statusCode = $statusCode; @@ -51,8 +50,6 @@ public function __construct( /** * Get the HTTP status code from Keycloak. - * - * @return int|null */ public function getStatusCode(): ?int { @@ -71,22 +68,21 @@ public function getResponse() /** * Get the body of the HTTP response as an associative array. - * - * @return array|null */ public function getResponseBody(): ?array { if ($this->response) { $body = (string) $this->response->getBody(); + return json_decode($body, true); } + return null; } /** * Static method to create an exception from a Guzzle RequestException. * - * @param RequestException $exception * @return static */ public static function fromRequestException(RequestException $exception): self diff --git a/src/Facades/Keycloak.php b/src/Facades/Keycloak.php index 2f9df11e..95ac62e3 100644 --- a/src/Facades/Keycloak.php +++ b/src/Facades/Keycloak.php @@ -5,13 +5,13 @@ use Illuminate\Support\Facades\Facade; use OpenSeaWave\Keycloak\Enums\GrantType; use OpenSeaWave\Keycloak\Representation\AddUserRolesRequest; +use OpenSeaWave\Keycloak\Representation\CountUsersRequest; use OpenSeaWave\Keycloak\Representation\CreateRoleRequest; use OpenSeaWave\Keycloak\Representation\DeleteUserRolesRequest; use OpenSeaWave\Keycloak\Representation\GetRolesRequest; use OpenSeaWave\Keycloak\Representation\GetUsersRequest; use OpenSeaWave\Keycloak\Representation\RoleRepresentation; use OpenSeaWave\Keycloak\Representation\UserRepresentation; -use OpenSeaWave\Keycloak\Representation\CountUsersRequest; /** * Class Keycloak @@ -42,15 +42,13 @@ * @method static void changeUserActivationStatus(string $userId, bool $enabled,?string $realm) Change a user's activation status. * * @see \OpenSeaWave\Keycloak\Keycloak - * @package OpenSeaWave\Keycloak + * * @author Omar Haris */ class Keycloak extends Facade { /** * Get the registered name of the component. - * - * @return string */ protected static function getFacadeAccessor(): string { diff --git a/src/Keycloak.php b/src/Keycloak.php index fe87a4f6..3921b427 100755 --- a/src/Keycloak.php +++ b/src/Keycloak.php @@ -6,7 +6,9 @@ use GuzzleHttp\Exception\GuzzleException; use OpenSeaWave\Keycloak\Enums\CredentialType; use OpenSeaWave\Keycloak\Enums\GrantType; +use OpenSeaWave\Keycloak\Exceptions\KeycloakException; use OpenSeaWave\Keycloak\Representation\AddUserRolesRequest; +use OpenSeaWave\Keycloak\Representation\CountUsersRequest; use OpenSeaWave\Keycloak\Representation\CreateRoleRequest; use OpenSeaWave\Keycloak\Representation\CredentialRepresentation; use OpenSeaWave\Keycloak\Representation\DeleteUserRolesRequest; @@ -15,70 +17,51 @@ use OpenSeaWave\Keycloak\Representation\RoleRepresentation; use OpenSeaWave\Keycloak\Representation\UpdateRoleRequest; use OpenSeaWave\Keycloak\Representation\UserRepresentation; -use OpenSeaWave\Keycloak\Representation\CountUsersRequest; -use OpenSeaWave\Keycloak\Exceptions\KeycloakException; /** * Keycloak class. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class Keycloak implements KeycloakInterface { /** * The HTTP client instance. - * - * @var Client */ protected Client $httpClient; /** * The base URL for Keycloak. - * - * @var string */ private string $baseUrl; /** * The username for the keycloak admin. - * - * @var ?string */ private ?string $username; /** * The password for the keycloak admin. - * - * @var ?string */ private ?string $password; /** * The realm for which requests are made. - * - * @var ?string */ private ?string $realm; /** * The client ID. - * - * @var ?string */ protected ?string $clientId; /** * The client secret. - * - * @var ?string */ protected ?string $clientSecret; /** * The grant type. - * - * @var ?GrantType */ protected ?GrantType $grantType; @@ -95,8 +78,7 @@ public function __construct( ?string $clientId = null, ?string $clientSecret = null, ?string $grantType = null - ) - { + ) { $this->username = $username ?? config('keycloak.username'); $this->password = $password ?? config('keycloak.password'); $this->baseUrl = $baseUrl ?? config('keycloak.base_url'); @@ -109,15 +91,14 @@ public function __construct( 'base_uri' => $this->baseUrl, 'headers' => [ 'Content-Type' => 'application/json', - ] + ], ]); } /** * Set base URL for the Keycloak client. * - * @param string $baseUrl The base URL to set. - * @return Keycloak + * @param string $baseUrl The base URL to set. */ public function setBaseUrl(string $baseUrl): Keycloak { @@ -129,8 +110,7 @@ public function setBaseUrl(string $baseUrl): Keycloak /** * Set realm for the Keycloak client. * - * @param string $realm The realm to set. - * @return Keycloak + * @param string $realm The realm to set. */ public function setRealm(string $realm): Keycloak { @@ -142,8 +122,7 @@ public function setRealm(string $realm): Keycloak /** * Set grantType for the Keycloak client. * - * @param GrantType $grantType The grant type to set. - * @return Keycloak + * @param GrantType $grantType The grant type to set. */ public function setGrantType(GrantType $grantType): Keycloak { @@ -155,8 +134,7 @@ public function setGrantType(GrantType $grantType): Keycloak /** * Set Client ID for the Keycloak client. * - * @param string $clientId The client ID to set. - * @return Keycloak + * @param string $clientId The client ID to set. */ public function setClientId(string $clientId): Keycloak { @@ -168,8 +146,7 @@ public function setClientId(string $clientId): Keycloak /** * Set Client secret for the Keycloak client. * - * @param string $clientSecret The client secret to set. - * @return Keycloak + * @param string $clientSecret The client secret to set. */ public function setClientSecret(string $clientSecret): Keycloak { @@ -181,8 +158,7 @@ public function setClientSecret(string $clientSecret): Keycloak /** * Set a username for the Keycloak client. * - * @param string $username The username to set. - * @return Keycloak + * @param string $username The username to set. */ public function setUsername(string $username): Keycloak { @@ -194,8 +170,7 @@ public function setUsername(string $username): Keycloak /** * Set a password for the Keycloak client. * - * @param string $password The password to set. - * @return Keycloak + * @param string $password The password to set. */ public function setPassword(string $password): Keycloak { @@ -207,8 +182,9 @@ public function setPassword(string $password): Keycloak /** * Retrieve an access token from Keycloak. * - * @param ?string $realm The realm for which to retrieve the token. + * @param ?string $realm The realm for which to retrieve the token. * @return object the token object. + * * @throws GuzzleException If the HTTP request fails. */ public function getToken(?string $realm = null): object @@ -239,12 +215,13 @@ public function getToken(?string $realm = null): object /** * Count the total number of users in a realm based on filters. * - * @param ?CountUsersRequest $query An object representing the query parameters. - * @param ?string $realm The realm for which to count users. + * @param ?CountUsersRequest $query An object representing the query parameters. + * @param ?string $realm The realm for which to count users. * @return int The number of users matching the criteria. + * * @throws GuzzleException If the HTTP request fails. */ - public function countUsers(?string $realm = null,?CountUsersRequest $query = null): int + public function countUsers(?string $realm = null, ?CountUsersRequest $query = null): int { // Create a new instance of the KeycloakUrlBuilder $urlBuilder = new KeycloakUrlBuilder( @@ -269,12 +246,13 @@ public function countUsers(?string $realm = null,?CountUsersRequest $query = nul /** * Retrieve a list of users based on filters. * - * @param ?GetUsersRequest $query An object representing the query parameters. - * @param ?string $realm The realm for which to retrieve users. + * @param ?GetUsersRequest $query An object representing the query parameters. + * @param ?string $realm The realm for which to retrieve users. * @return array An array of user objects. + * * @throws GuzzleException If the HTTP request fails. */ - public function getUsers(?string $realm = null,?GetUsersRequest $query = null): array + public function getUsers(?string $realm = null, ?GetUsersRequest $query = null): array { // Create a new instance of the KeycloakUrlBuilder $urlBuilder = new KeycloakUrlBuilder( @@ -287,7 +265,7 @@ public function getUsers(?string $realm = null,?GetUsersRequest $query = null): 'headers' => [ 'Authorization' => "Bearer {$this->getToken()->access_token}", ], - 'query' => $query?->toArray() + 'query' => $query?->toArray(), ]); return json_decode( @@ -298,12 +276,13 @@ public function getUsers(?string $realm = null,?GetUsersRequest $query = null): /** * Retrieve user details by user ID. * - * @param string $id The UUID of the user to retrieve. - * @param ?string $realm The realm for which to retrieve the user. + * @param string $id The UUID of the user to retrieve. + * @param ?string $realm The realm for which to retrieve the user. * @return UserRepresentation A user representation. + * * @throws GuzzleException If the HTTP request fails. */ - public function getUser(string $id,?string $realm = null): UserRepresentation + public function getUser(string $id, ?string $realm = null): UserRepresentation { // Create a new instance of the KeycloakUrlBuilder $urlBuilder = new KeycloakUrlBuilder( @@ -327,12 +306,13 @@ public function getUser(string $id,?string $realm = null): UserRepresentation /** * Retrieve user details by username. * - * @param string $username The username of the user to retrieve. - * @param ?string $realm The realm for which to retrieve the user. + * @param string $username The username of the user to retrieve. + * @param ?string $realm The realm for which to retrieve the user. * @return object A user representation. + * * @throws GuzzleException|KeycloakException If the HTTP request fails. */ - public function getUserByUsername(string $username,?string $realm = null): object + public function getUserByUsername(string $username, ?string $realm = null): object { // Retrieve the user by username $users = $this->getUsers( @@ -344,7 +324,7 @@ public function getUserByUsername(string $username,?string $realm = null): objec ); // Throw an exception if the user is not found - if(count($users) === 0) { + if (count($users) === 0) { throw new KeycloakException('User not found', 0); } @@ -355,9 +335,10 @@ public function getUserByUsername(string $username,?string $realm = null): objec /** * Create a new user in the realm. * - * @param UserRepresentation $data The user data for creating a new user. - * @param ?string $realm The realm for which to create the user. + * @param UserRepresentation $data The user data for creating a new user. + * @param ?string $realm The realm for which to create the user. * @return UserRepresentation The user object that was created. + * * @throws KeycloakException If the API request fails. * @throws GuzzleException */ @@ -378,7 +359,7 @@ public function createUser(UserRepresentation $data, ?string $realm = null): Use ]); // Check if the response is successful - if (!$this->isSuccessfulResponse($response)) { + if (! $this->isSuccessfulResponse($response)) { throw new KeycloakException('Failed to create user', 0); } @@ -392,9 +373,10 @@ public function createUser(UserRepresentation $data, ?string $realm = null): Use /** * Update an existing user in the realm. * - * @param UserRepresentation $data The user data for creating a new user. - * @param ?string $realm The realm for which to create the user. + * @param UserRepresentation $data The user data for creating a new user. + * @param ?string $realm The realm for which to create the user. * @return UserRepresentation The user object that was created. + * * @throws KeycloakException If the API request fails. * @throws GuzzleException */ @@ -415,7 +397,7 @@ public function updateUser(string $id, UserRepresentation $data, ?string $realm ]); // Return the user object - if (!$this->isSuccessfulResponse($response)) { + if (! $this->isSuccessfulResponse($response)) { throw new KeycloakException('Failed to update user', 0); } @@ -425,13 +407,14 @@ public function updateUser(string $id, UserRepresentation $data, ?string $realm /** * Delete a user in the realm. * - * @param string $id The UUID of the user to delete. - * @param string|null $realm The realm for which to delete the user. + * @param string $id The UUID of the user to delete. + * @param string|null $realm The realm for which to delete the user. * @return bool True if the user was deleted successfully. + * * @throws GuzzleException If the HTTP request fails. * @throws KeycloakException If the API request fails. */ - public function deleteUser(string $id,?string $realm = null): bool + public function deleteUser(string $id, ?string $realm = null): bool { $urlBuilder = new KeycloakUrlBuilder( baseUrl: $this->baseUrl, @@ -444,7 +427,7 @@ public function deleteUser(string $id,?string $realm = null): bool ], ]); - if (!$this->isSuccessfulResponse($response)) { + if (! $this->isSuccessfulResponse($response)) { throw new KeycloakException('Failed to delete user', 0); } @@ -454,9 +437,10 @@ public function deleteUser(string $id,?string $realm = null): bool /** * Retrieve a role by name. * - * @param string $roleName The role name of the role to retrieve. - * @param string|null $realm The realm for which to retrieve the role. + * @param string $roleName The role name of the role to retrieve. + * @param string|null $realm The realm for which to retrieve the role. * @return RoleRepresentation A role representation. + * * @throws GuzzleException * @throws KeycloakException */ @@ -470,10 +454,10 @@ public function getRoleByName(string $roleName, ?string $realm = null): RoleRepr $response = $this->httpClient->get($urlBuilder->getRoleByNameUrl($roleName), [ 'headers' => [ 'Authorization' => "Bearer {$this->getToken()->access_token}", - ] + ], ]); - if (!$this->isSuccessfulResponse($response)) { + if (! $this->isSuccessfulResponse($response)) { throw new KeycloakException('Failed to retrieve roles', 0); } @@ -485,13 +469,14 @@ public function getRoleByName(string $roleName, ?string $realm = null): RoleRepr /** * Retrieve a list of roles from the realm. * - * @param string|null $realm The realm for which to retrieve roles. - * @param GetRolesRequest|null $request An object representing the query parameters. + * @param string|null $realm The realm for which to retrieve roles. + * @param GetRolesRequest|null $request An object representing the query parameters. * @return array An array of role objects. + * * @throws GuzzleException If the HTTP request fails. * @throws KeycloakException If the API request fails. */ - public function getRoles(?GetRolesRequest $request,string $realm = null): array + public function getRoles(?GetRolesRequest $request, ?string $realm = null): array { $urlBuilder = new KeycloakUrlBuilder( baseUrl: $this->baseUrl, @@ -502,10 +487,10 @@ public function getRoles(?GetRolesRequest $request,string $realm = null): array 'headers' => [ 'Authorization' => "Bearer {$this->getToken()->access_token}", ], - 'query' => $request?->toArray() + 'query' => $request?->toArray(), ]); - if (!$this->isSuccessfulResponse($response)) { + if (! $this->isSuccessfulResponse($response)) { throw new KeycloakException('Failed to retrieve roles', 0); } @@ -517,9 +502,10 @@ public function getRoles(?GetRolesRequest $request,string $realm = null): array /** * Create a new role in the realm. * - * @param CreateRoleRequest $data The role data for creating a new role. - * @param string|null $realm The realm for which to create the role. + * @param CreateRoleRequest $data The role data for creating a new role. + * @param string|null $realm The realm for which to create the role. * @return RoleRepresentation True if the role was created successfully. + * * @throws GuzzleException If the HTTP request fails. * @throws KeycloakException If the API request fails. */ @@ -537,7 +523,7 @@ public function createRole(CreateRoleRequest $data, ?string $realm = null): Role ], ]); - if (!$this->isSuccessfulResponse($response)) { + if (! $this->isSuccessfulResponse($response)) { throw new KeycloakException('Failed to create role', 0); } @@ -550,10 +536,6 @@ public function createRole(CreateRoleRequest $data, ?string $realm = null): Role /** * Update an existing role in the realm. * - * @param string $roleName - * @param UpdateRoleRequest $data - * @param string|null $realm - * @return bool * @throws GuzzleException * @throws KeycloakException */ @@ -571,7 +553,7 @@ public function updateRole(string $roleName, UpdateRoleRequest $data, ?string $r ], ]); - if (!$this->isSuccessfulResponse($response)) { + if (! $this->isSuccessfulResponse($response)) { throw new KeycloakException('Failed to update role', 0); } @@ -581,13 +563,10 @@ public function updateRole(string $roleName, UpdateRoleRequest $data, ?string $r /** * Delete a role from the realm. * - * @param string $roleName - * @param string|null $realm - * @return bool * @throws GuzzleException * @throws KeycloakException */ - public function deleteRole(string $roleName,?string $realm = null): bool + public function deleteRole(string $roleName, ?string $realm = null): bool { $urlBuilder = new KeycloakUrlBuilder( baseUrl: $this->baseUrl, @@ -600,7 +579,7 @@ public function deleteRole(string $roleName,?string $realm = null): bool ], ]); - if (!$this->isSuccessfulResponse($response)) { + if (! $this->isSuccessfulResponse($response)) { throw new KeycloakException('Failed to delete role', 0); } @@ -610,12 +589,9 @@ public function deleteRole(string $roleName,?string $realm = null): bool /** * Retrieve a list of realm roles assigned to a user. * - * @param string $userId - * @param ?string $realm - * @return array * @throws GuzzleException */ - public function getUserRealmRoles(string $userId,?string $realm = null): array + public function getUserRealmRoles(string $userId, ?string $realm = null): array { return $this->getUser( $userId, $realm @@ -625,10 +601,6 @@ public function getUserRealmRoles(string $userId,?string $realm = null): array /** * Assign realm roles to a user * - * @param string $userId - * @param AddUserRolesRequest $roles - * @param string|null $realm - * @return object * @throws GuzzleException * @throws KeycloakException */ @@ -646,7 +618,7 @@ public function addUserRealmRoles(string $userId, AddUserRolesRequest $roles, ?s ], ]); - if (!$this->isSuccessfulResponse($response)) { + if (! $this->isSuccessfulResponse($response)) { throw new KeycloakException('Failed to assign roles', 0); } @@ -658,10 +630,6 @@ public function addUserRealmRoles(string $userId, AddUserRolesRequest $roles, ?s /** * Remove realm roles from a user. * - * @param string $userId - * @param DeleteUserRolesRequest $roles - * @param string|null $realm - * @return bool * @throws GuzzleException * @throws KeycloakException */ @@ -679,7 +647,7 @@ public function deleteUserRealmRoles(string $userId, DeleteUserRolesRequest $rol ], ]); - if (!$this->isSuccessfulResponse($response)) { + if (! $this->isSuccessfulResponse($response)) { throw new KeycloakException('Failed to remove roles', 0); } @@ -689,14 +657,10 @@ public function deleteUserRealmRoles(string $userId, DeleteUserRolesRequest $rol /** * Change a user's password. * - * @param string $userId - * @param string $password - * @param string|null $realm - * @return void * @throws GuzzleException * @throws KeycloakException */ - public function changeUserPassword(string $userId, string $password,?string $realm = null): void + public function changeUserPassword(string $userId, string $password, ?string $realm = null): void { $this->updateUser( $userId, @@ -706,7 +670,7 @@ public function changeUserPassword(string $userId, string $password,?string $rea type: CredentialType::PASSWORD, value: $password, temporary: false - ) + ), ] ), $realm @@ -716,14 +680,10 @@ public function changeUserPassword(string $userId, string $password,?string $rea /** * Change a user's activation status. * - * @param string $userId - * @param bool $enabled - * @param string|null $realm - * @return void * @throws GuzzleException * @throws KeycloakException */ - public function changeUserActivationStatus(string $userId, bool $enabled,?string $realm = null): void + public function changeUserActivationStatus(string $userId, bool $enabled, ?string $realm = null): void { $this->updateUser( $userId, @@ -736,13 +696,9 @@ public function changeUserActivationStatus(string $userId, bool $enabled,?string /** * Check if the response is successful. - * - * @param $response - * @return bool */ private function isSuccessfulResponse($response): bool { return $response->getStatusCode() === 201 || $response->getStatusCode() === 200 || $response->getStatusCode() === 204 || $response->getStatusCode() === 202; } } - diff --git a/src/KeycloakInterface.php b/src/KeycloakInterface.php index 73ad8fda..2a39a62b 100644 --- a/src/KeycloakInterface.php +++ b/src/KeycloakInterface.php @@ -4,6 +4,7 @@ use OpenSeaWave\Keycloak\Enums\GrantType; use OpenSeaWave\Keycloak\Representation\AddUserRolesRequest; +use OpenSeaWave\Keycloak\Representation\CountUsersRequest; use OpenSeaWave\Keycloak\Representation\CreateRoleRequest; use OpenSeaWave\Keycloak\Representation\DeleteUserRolesRequest; use OpenSeaWave\Keycloak\Representation\GetRolesRequest; @@ -11,12 +12,10 @@ use OpenSeaWave\Keycloak\Representation\RoleRepresentation; use OpenSeaWave\Keycloak\Representation\UpdateRoleRequest; use OpenSeaWave\Keycloak\Representation\UserRepresentation; -use OpenSeaWave\Keycloak\Representation\CountUsersRequest; /** * Interface KeycloakInterface * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ interface KeycloakInterface @@ -64,22 +63,22 @@ public function getToken(?string $realm = null): object; /** * Count the total number of users in a realm. */ - public function countUsers(?string $realm = null,?CountUsersRequest $query = null): int; + public function countUsers(?string $realm = null, ?CountUsersRequest $query = null): int; /** * Retrieve a list of users from Keycloak. */ - public function getUsers(?string $realm = null,?GetUsersRequest $query = null): array; + public function getUsers(?string $realm = null, ?GetUsersRequest $query = null): array; /** * Retrieve a specific user by their ID. */ - public function getUser(string $id,?string $realm = null): UserRepresentation; + public function getUser(string $id, ?string $realm = null): UserRepresentation; /** * Retrieve a specific user by their username. */ - public function getUserByUsername(string $username,?string $realm = null): object; + public function getUserByUsername(string $username, ?string $realm = null): object; /** * Create a new user in Keycloak. @@ -94,12 +93,12 @@ public function updateUser(string $id, UserRepresentation $data, ?string $realm /** * Delete a user from Keycloak. */ - public function deleteUser(string $id,?string $realm = null): bool; + public function deleteUser(string $id, ?string $realm = null): bool; /** * Retrieve a list of roles from the realm. */ - public function getRoles(?GetRolesRequest $request,?string $realm = null): array; + public function getRoles(?GetRolesRequest $request, ?string $realm = null): array; /** * Create a new role in the realm. @@ -114,12 +113,12 @@ public function updateRole(string $roleName, UpdateRoleRequest $data, ?string $r /** * Delete a role from the realm. */ - public function deleteRole(string $roleName,?string $realm = null): bool; + public function deleteRole(string $roleName, ?string $realm = null): bool; /** * Retrieve realm roles assigned to a specific user. */ - public function getUserRealmRoles(string $userId,?string $realm = null): array; + public function getUserRealmRoles(string $userId, ?string $realm = null): array; /** * Assign roles to a user. @@ -134,10 +133,10 @@ public function deleteUserRealmRoles(string $userId, DeleteUserRolesRequest $rol /** * Change user password. */ - public function changeUserPassword(string $userId, string $password,?string $realm = null): void; + public function changeUserPassword(string $userId, string $password, ?string $realm = null): void; /** * Change user activation status. */ - public function changeUserActivationStatus(string $userId, bool $enabled,?string $realm = null): void; + public function changeUserActivationStatus(string $userId, bool $enabled, ?string $realm = null): void; } diff --git a/src/KeycloakServiceProvider.php b/src/KeycloakServiceProvider.php index 65770416..ab65eecd 100644 --- a/src/KeycloakServiceProvider.php +++ b/src/KeycloakServiceProvider.php @@ -8,7 +8,6 @@ /** * KeycloakServiceProvider service provider class. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class KeycloakServiceProvider extends PackageServiceProvider diff --git a/src/KeycloakUrlBuilder.php b/src/KeycloakUrlBuilder.php index 05705c3d..4f2aa332 100644 --- a/src/KeycloakUrlBuilder.php +++ b/src/KeycloakUrlBuilder.php @@ -5,30 +5,25 @@ /** * Class KeycloakUrlBuilder * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class KeycloakUrlBuilder { /** * The base URL for Keycloak. - * - * @var string */ private string $baseUrl; /** * The realm for which requests are made. - * - * @var ?string */ private ?string $realm; /** * KeycloakUrlBuilder constructor. * - * @param string $baseUrl The base URL of the Keycloak server. - * @param ?string $realm The realm to be used for the API calls. + * @param string $baseUrl The base URL of the Keycloak server. + * @param ?string $realm The realm to be used for the API calls. */ public function __construct(string $baseUrl, ?string $realm) { @@ -39,8 +34,6 @@ public function __construct(string $baseUrl, ?string $realm) /** * Get the URL for obtaining a token. - * - * @return string */ public function getTokenUrl(): string { @@ -49,8 +42,6 @@ public function getTokenUrl(): string /** * Get the URL for counting users in a realm. - * - * @return string */ public function getCountUsersUrl(): string { @@ -59,8 +50,6 @@ public function getCountUsersUrl(): string /** * Get the URL for retrieving users in a realm. - * - * @return string */ public function getUsersUrl(): string { @@ -70,8 +59,7 @@ public function getUsersUrl(): string /** * Get the URL for a specific user by ID. * - * @param string $userId The ID of the user. - * @return string + * @param string $userId The ID of the user. */ public function getUserByIdUrl(string $userId): string { @@ -80,8 +68,6 @@ public function getUserByIdUrl(string $userId): string /** * Get the URL for managing roles in a realm. - * - * @return string */ public function getRolesUrl(): string { @@ -91,8 +77,7 @@ public function getRolesUrl(): string /** * Get the URL for a specific role by role name. * - * @param string $roleName The name of the role. - * @return string + * @param string $roleName The name of the role. */ public function getRoleByNameUrl(string $roleName): string { @@ -101,11 +86,9 @@ public function getRoleByNameUrl(string $roleName): string /** * Get the URL for role mappings in the realm. - * - * @param $userId - * @return string */ - public function getRealmRoleMappingsUrl($userId): string { + public function getRealmRoleMappingsUrl($userId): string + { return "{$this->baseUrl}/admin/realms/{$this->realm}/users/{$userId}/role-mappings/realm"; } } diff --git a/src/Representation/AddUserRolesRequest.php b/src/Representation/AddUserRolesRequest.php index 49c38a6d..21586351 100644 --- a/src/Representation/AddUserRolesRequest.php +++ b/src/Representation/AddUserRolesRequest.php @@ -7,7 +7,6 @@ /** * AddUserRolesRequest data transfer object class. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class AddUserRolesRequest extends Representation @@ -15,12 +14,12 @@ class AddUserRolesRequest extends Representation /** * AddUserRolesRequest constructor. * - * @param RoleRepresentation[] $roles An array of RoleRepresentation objects to assign to the user. + * @param RoleRepresentation[] $roles An array of RoleRepresentation objects to assign to the user. */ public function __construct( /** * @var RoleRepresentation[] A list of role representations to assign to the user. */ public array $roles, - ){} + ) {} } diff --git a/src/Representation/ClientMappingsRepresentation.php b/src/Representation/ClientMappingsRepresentation.php index 83aaa557..50c0ef54 100644 --- a/src/Representation/ClientMappingsRepresentation.php +++ b/src/Representation/ClientMappingsRepresentation.php @@ -7,7 +7,6 @@ /** * ClientMappingsRepresentation data transfer object class. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class ClientMappingsRepresentation extends Representation @@ -15,13 +14,13 @@ class ClientMappingsRepresentation extends Representation /** * ClientMappingsRepresentation constructor. * - * @param string|null $id The ID of the client. - * @param string|null $client The client ID. - * @param array|null $mappings A list of mappings. + * @param string|null $id The ID of the client. + * @param string|null $client The client ID. + * @param array|null $mappings A list of mappings. */ public function __construct( public ?string $id = null, public ?string $client = null, public ?array $mappings = null, - ){} + ) {} } diff --git a/src/Representation/CompositesRepresentation.php b/src/Representation/CompositesRepresentation.php index bcb4ee4b..163d23ec 100644 --- a/src/Representation/CompositesRepresentation.php +++ b/src/Representation/CompositesRepresentation.php @@ -7,7 +7,6 @@ /** * CompositesRepresentation data transfer object class. * - * @package OpenSeaWave\Keycloak\Representation * @author Omar Haris */ class CompositesRepresentation extends Representation @@ -15,6 +14,7 @@ class CompositesRepresentation extends Representation public function __construct( /** * @var string[]|null A list of realm-level roles. + * * @example ['admin', 'user', 'manager'] */ public ?array $realm = null, @@ -22,6 +22,7 @@ public function __construct( /** * @var array|null A mapping of client IDs to an array of client-level roles. * Each client ID maps to a list of role names. + * * @example ['client-id-1' => ['role1', 'role2'], 'client-id-2' => ['role3']] */ public ?array $client = null, @@ -29,9 +30,11 @@ public function __construct( /** * @var array|null A mapping of application IDs to an array of application-level roles (deprecated). * Each application ID maps to a list of role names. + * * @example ['app-id-1' => ['app-role1', 'app-role2']] + * * @deprecated */ public ?array $application = null, - ){} + ) {} } diff --git a/src/Representation/CountUsersRequest.php b/src/Representation/CountUsersRequest.php index 86f240a2..fdd54e48 100644 --- a/src/Representation/CountUsersRequest.php +++ b/src/Representation/CountUsersRequest.php @@ -7,7 +7,6 @@ /** * CountUsersRequest data transfer object class. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class CountUsersRequest extends Representation @@ -15,17 +14,17 @@ class CountUsersRequest extends Representation /** * CountUsersRequest constructor. * - * @param string|null $email Filter users by email address. - * @param bool|null $emailVerified Filter users by whether their email has been verified. - * @param bool|null $enabled Filter users based on whether they are enabled or disabled. - * @param string|null $firstName Filter users by their first name. - * @param string|null $lastName Filter users by their last name. - * @param string|null $q A general search filter applied across multiple fields such as username, firstName, lastName, and email. - * @param string|null $search A search string applied to fields such as username, firstName, lastName, or email. - * @param string|null $username Filter users by their username. - * @param bool|null $briefRepresentation If true, returns only basic user information. - * @param int|null $first The starting index of the result set (for pagination). - * @param int|null $max The maximum number of results to return (for pagination). + * @param string|null $email Filter users by email address. + * @param bool|null $emailVerified Filter users by whether their email has been verified. + * @param bool|null $enabled Filter users based on whether they are enabled or disabled. + * @param string|null $firstName Filter users by their first name. + * @param string|null $lastName Filter users by their last name. + * @param string|null $q A general search filter applied across multiple fields such as username, firstName, lastName, and email. + * @param string|null $search A search string applied to fields such as username, firstName, lastName, or email. + * @param string|null $username Filter users by their username. + * @param bool|null $briefRepresentation If true, returns only basic user information. + * @param int|null $first The starting index of the result set (for pagination). + * @param int|null $max The maximum number of results to return (for pagination). */ public function __construct( /** @@ -105,5 +104,5 @@ public function __construct( * @var int|null The maximum number of results to return (for pagination). */ public ?int $max = null, - ){} + ) {} } diff --git a/src/Representation/CreateRoleRequest.php b/src/Representation/CreateRoleRequest.php index 5ef1ad54..aa783912 100644 --- a/src/Representation/CreateRoleRequest.php +++ b/src/Representation/CreateRoleRequest.php @@ -7,7 +7,6 @@ /** * CreateRoleRequest data transfer object class. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class CreateRoleRequest extends Representation @@ -15,12 +14,12 @@ class CreateRoleRequest extends Representation /** * CreateRoleRequest constructor. * - * @param string|null $id The unique identifier of the role. - * @param string $name The name of the role. - * @param string|null $description The description of the role. - * @param bool|null $composite Whether the role is composite. - * @param bool|null $clientRole Whether the role is a client role. - * @param string|null $containerId The container ID of the role. + * @param string|null $id The unique identifier of the role. + * @param string $name The name of the role. + * @param string|null $description The description of the role. + * @param bool|null $composite Whether the role is composite. + * @param bool|null $clientRole Whether the role is a client role. + * @param string|null $containerId The container ID of the role. */ public function __construct( /** @@ -30,6 +29,7 @@ public function __construct( /** * @var string|null The unique identifier of the role (optional). + * * @example 'c1e9b67f-67d9-47e9-9e69-8c9b0a9e2c98' */ public ?string $id = null, @@ -41,6 +41,7 @@ public function __construct( /** * @var bool|null Whether the role is a default role (optional). + * * @deprecated */ public ?bool $scopeParamRequired = null, @@ -62,6 +63,7 @@ public function __construct( /** * @var string|null The client ID of the client that the role belongs to (optional). + * * @example 'c1e9b67f-67d9-47e9-9e69-8c9b0a9e2c98' */ public ?string $containerId = null, @@ -70,5 +72,5 @@ public function __construct( * @var array|null A list of attributes associated with the role (optional). */ public ?array $attributes = null, - ){} + ) {} } diff --git a/src/Representation/CredentialRepresentation.php b/src/Representation/CredentialRepresentation.php index 05d4c539..35ec5be4 100644 --- a/src/Representation/CredentialRepresentation.php +++ b/src/Representation/CredentialRepresentation.php @@ -9,7 +9,6 @@ /** * CredentialRepresentation data transfer object class. * - * @package OpenSeaWave\Keycloak\Representation * @author Omar Haris */ class CredentialRepresentation extends Representation @@ -17,125 +16,135 @@ class CredentialRepresentation extends Representation /** * CredentialRepresentation constructor. * - * @param string|null $id The unique ID of the credential. - * @param CredentialType|null $type The type of the credential (e.g., ' - * @param string|null $userLabel The user-defined label for the credential. - * @param int|null $createdDate The date the credential was created (in milliseconds since epoch). - * @param string|null $secretData Secret data for the credential (optional). - * @param string|null $credentialData CredentialRepresentation data for the credential (optional). - * @param int|null $priority The priority of the credential. - * @param string|null $value The value for the credential. - * @param bool|null $temporary Whether the credential is temporary. - * @param string|null $device The device associated with the credential (deprecated). - * @param string|null $hashedSaltedValue The hashed salted value (deprecated). - * @param string|null $salt The salt for hashing (deprecated). - * @param int|null $hashIterations The number of hash iterations (deprecated). - * @param int|null $counter The counter for the credential (deprecated). - * @param string|null $algorithm The algorithm used (deprecated). - * @param int|null $digits The number of digits (deprecated). - * @param int|null $period The time period (deprecated). - * @param array|null $config Configuration object for the credential (deprecated). + * @param string|null $id The unique ID of the credential. + * @param CredentialType|null $type The type of the credential (e.g., ' + * @param string|null $userLabel The user-defined label for the credential. + * @param int|null $createdDate The date the credential was created (in milliseconds since epoch). + * @param string|null $secretData Secret data for the credential (optional). + * @param string|null $credentialData CredentialRepresentation data for the credential (optional). + * @param int|null $priority The priority of the credential. + * @param string|null $value The value for the credential. + * @param bool|null $temporary Whether the credential is temporary. + * @param string|null $device The device associated with the credential (deprecated). + * @param string|null $hashedSaltedValue The hashed salted value (deprecated). + * @param string|null $salt The salt for hashing (deprecated). + * @param int|null $hashIterations The number of hash iterations (deprecated). + * @param int|null $counter The counter for the credential (deprecated). + * @param string|null $algorithm The algorithm used (deprecated). + * @param int|null $digits The number of digits (deprecated). + * @param int|null $period The time period (deprecated). + * @param array|null $config Configuration object for the credential (deprecated). */ public function __construct( /** * @var string|null The unique ID of the credential. + * * @example 'c1e9b67f-67d9-47e9-9e69-8c9b0a9e2c98' */ public ?string $id = null, - /** - * @var CredentialType|null The type of the credential (e.g., 'password', 'otp', 'secret'). - */ - public ?CredentialType $type = null, + /** + * @var CredentialType|null The type of the credential (e.g., 'password', 'otp', 'secret'). + */ + public ?CredentialType $type = null, - /** - * @var string|null The user-defined label for the credential. - */ - public ?string $userLabel = null, + /** + * @var string|null The user-defined label for the credential. + */ + public ?string $userLabel = null, - /** - * @var int|null The date the credential was created (in milliseconds since epoch). - */ - public ?int $createdDate = null, + /** + * @var int|null The date the credential was created (in milliseconds since epoch). + */ + public ?int $createdDate = null, - /** - * @var string|null Secret data for the credential (optional). - */ - public ?string $secretData = null, + /** + * @var string|null Secret data for the credential (optional). + */ + public ?string $secretData = null, - /** - * @var string|null CredentialRepresentation data for the credential (optional). - */ - public ?string $credentialData = null, + /** + * @var string|null CredentialRepresentation data for the credential (optional). + */ + public ?string $credentialData = null, - /** - * @var int|null The priority of the credential. - */ - public ?int $priority = null, + /** + * @var int|null The priority of the credential. + */ + public ?int $priority = null, - /** - * @var string|null The value for the credential. - */ - public ?string $value = null, + /** + * @var string|null The value for the credential. + */ + public ?string $value = null, - /** - * @var bool|null Whether the credential is temporary. - */ - public ?bool $temporary = null, + /** + * @var bool|null Whether the credential is temporary. + */ + public ?bool $temporary = null, - // Deprecated fields are included for backward compatibility. - /** - * @var string|null The device associated with the credential (deprecated). - * @deprecated - */ - public ?string $device = null, + // Deprecated fields are included for backward compatibility. + /** + * @var string|null The device associated with the credential (deprecated). + * + * @deprecated + */ + public ?string $device = null, - /** - * @var string|null The hashed salted value (deprecated). - * @deprecated - */ - public ?string $hashedSaltedValue = null, + /** + * @var string|null The hashed salted value (deprecated). + * + * @deprecated + */ + public ?string $hashedSaltedValue = null, - /** - * @var string|null The salt for hashing (deprecated). - * @deprecated - */ - public ?string $salt = null, + /** + * @var string|null The salt for hashing (deprecated). + * + * @deprecated + */ + public ?string $salt = null, - /** - * @var int|null The number of hash iterations (deprecated). - * @deprecated - */ - public ?int $hashIterations = null, + /** + * @var int|null The number of hash iterations (deprecated). + * + * @deprecated + */ + public ?int $hashIterations = null, - /** - * @var int|null The counter for the credential (deprecated). - * @deprecated - */ - public ?int $counter = null, + /** + * @var int|null The counter for the credential (deprecated). + * + * @deprecated + */ + public ?int $counter = null, - /** - * @var string|null The algorithm used (deprecated). - * @deprecated - */ - public ?string $algorithm = null, + /** + * @var string|null The algorithm used (deprecated). + * + * @deprecated + */ + public ?string $algorithm = null, - /** - * @var int|null The number of digits (deprecated). - * @deprecated - */ - public ?int $digits = null, + /** + * @var int|null The number of digits (deprecated). + * + * @deprecated + */ + public ?int $digits = null, - /** - * @var int|null The time period (deprecated). - * @deprecated - */ - public ?int $period = null, + /** + * @var int|null The time period (deprecated). + * + * @deprecated + */ + public ?int $period = null, - /** - * @var array|null Configuration object for the credential (deprecated). - * @deprecated - */ - public ?array $config = null, - ){} + /** + * @var array|null Configuration object for the credential (deprecated). + * + * @deprecated + */ + public ?array $config = null, + ) {} } diff --git a/src/Representation/DeleteUserRolesRequest.php b/src/Representation/DeleteUserRolesRequest.php index de8b6b3e..e8201def 100644 --- a/src/Representation/DeleteUserRolesRequest.php +++ b/src/Representation/DeleteUserRolesRequest.php @@ -7,7 +7,6 @@ /** * DeleteUserRolesRequest data transfer object class. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class DeleteUserRolesRequest extends Representation @@ -15,12 +14,12 @@ class DeleteUserRolesRequest extends Representation /** * DeleteUserRolesRequest constructor. * - * @param RoleRepresentation[] $roles An array of RoleRepresentation objects to remove from the user. + * @param RoleRepresentation[] $roles An array of RoleRepresentation objects to remove from the user. */ public function __construct( /** * @var RoleRepresentation[] A list of role representations to remove from the user. */ public array $roles - ){} + ) {} } diff --git a/src/Representation/GetRolesRequest.php b/src/Representation/GetRolesRequest.php index 9ee4da7a..796815f9 100644 --- a/src/Representation/GetRolesRequest.php +++ b/src/Representation/GetRolesRequest.php @@ -5,11 +5,10 @@ /** * Class GetRolesRequest * - * @package OpenSeaWave\Keycloak\Representation * @author Omar Haris */ -class GetRolesRequest extends Representation { - +class GetRolesRequest extends Representation +{ /* * GetRolesRequest constructor. * @@ -23,5 +22,5 @@ public function __construct( public ?int $first = null, public ?int $max = null, public ?string $search = null, - ){} + ) {} } diff --git a/src/Representation/GetUsersRequest.php b/src/Representation/GetUsersRequest.php index aae2db91..35651d1a 100644 --- a/src/Representation/GetUsersRequest.php +++ b/src/Representation/GetUsersRequest.php @@ -7,7 +7,6 @@ /** * GetUsersRequest data transfer object class. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class GetUsersRequest extends Representation @@ -15,20 +14,20 @@ class GetUsersRequest extends Representation /** * GetUsersRequest constructor. * - * @param bool|null $briefRepresentation Defines whether brief representations are returned. - * @param string|null $email A string contained in email, or the complete email, if 'exact' is true. - * @param bool|null $emailVerified Whether the email has been verified. - * @param bool|null $enabled Boolean representing if the user is enabled or not. - * @param bool|null $exact Defines whether 'firstName', 'lastName', 'email', and 'username' must match exactly. - * @param int|null $first Pagination offset. - * @param string|null $firstName A string contained in the first name, or the complete first name if 'exact' is true. - * @param string|null $idpAlias The alias of an Identity Provider linked to the user. - * @param string|null $idpUserId The userId at an Identity Provider linked to the user. - * @param string|null $lastName A string contained in the last name, or the complete last name if 'exact' is true. - * @param int|null $max Maximum results size (pagination). - * @param string|null $q A query to search for custom attributes, in the format 'key1:value1 key2:value2'. - * @param string|null $search A string contained in username, first name, last name, or email. - * @param string|null $username A string contained in the username, or the complete username if 'exact' is true. + * @param bool|null $briefRepresentation Defines whether brief representations are returned. + * @param string|null $email A string contained in email, or the complete email, if 'exact' is true. + * @param bool|null $emailVerified Whether the email has been verified. + * @param bool|null $enabled Boolean representing if the user is enabled or not. + * @param bool|null $exact Defines whether 'firstName', 'lastName', 'email', and 'username' must match exactly. + * @param int|null $first Pagination offset. + * @param string|null $firstName A string contained in the first name, or the complete first name if 'exact' is true. + * @param string|null $idpAlias The alias of an Identity Provider linked to the user. + * @param string|null $idpUserId The userId at an Identity Provider linked to the user. + * @param string|null $lastName A string contained in the last name, or the complete last name if 'exact' is true. + * @param int|null $max Maximum results size (pagination). + * @param string|null $q A query to search for custom attributes, in the format 'key1:value1 key2:value2'. + * @param string|null $search A string contained in username, first name, last name, or email. + * @param string|null $username A string contained in the username, or the complete username if 'exact' is true. */ public function __construct( /** @@ -129,5 +128,5 @@ public function __construct( * @var string|null A string contained in the username, or the complete username if 'exact' is true. */ public ?string $username = null, - ){} + ) {} } diff --git a/src/Representation/MappingsRepresentation.php b/src/Representation/MappingsRepresentation.php index 8312856d..faba86e0 100644 --- a/src/Representation/MappingsRepresentation.php +++ b/src/Representation/MappingsRepresentation.php @@ -7,7 +7,6 @@ /** * MappingsRepresentation data transfer object class. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class MappingsRepresentation extends Representation @@ -15,11 +14,11 @@ class MappingsRepresentation extends Representation /** * MappingsRepresentation constructor. * - * @param RoleRepresentation[] $realmMappings A list of realm roles associated with the client (optional). - * @param ClientMappingsRepresentation[] $clientMappings A list of client roles associated with the client (optional). + * @param RoleRepresentation[] $realmMappings A list of realm roles associated with the client (optional). + * @param ClientMappingsRepresentation[] $clientMappings A list of client roles associated with the client (optional). */ public function __construct( public ?array $realmMappings = null, public ?array $clientMappings = null, - ){} + ) {} } diff --git a/src/Representation/Representation.php b/src/Representation/Representation.php index af0aea07..d7a3691f 100644 --- a/src/Representation/Representation.php +++ b/src/Representation/Representation.php @@ -7,14 +7,12 @@ /** * Representation data transfer object class. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ -class Representation { +class Representation +{ /** * Convert the Dto object to an associative array. - * - * @return array */ public function toArray(): array { @@ -22,23 +20,21 @@ public function toArray(): array // Loop through all the properties of the object. foreach (get_object_vars($this) as $key => $value) { - if (!is_null($value)) { + if (! is_null($value)) { $array[$key] = $this->optimize($value); } } // Remove all the null values from the array. return array_filter($array, function ($value) { - return !is_null($value); + return ! is_null($value); }); } /** * Optimize the value for serialization. * - * @param mixed $value The value to optimize. - * - * @return mixed + * @param mixed $value The value to optimize. */ private function optimize(mixed $value): mixed { diff --git a/src/Representation/RoleRepresentation.php b/src/Representation/RoleRepresentation.php index a0493b4d..21320c3f 100644 --- a/src/Representation/RoleRepresentation.php +++ b/src/Representation/RoleRepresentation.php @@ -7,7 +7,6 @@ /** * RoleRepresentation data transfer object class. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class RoleRepresentation extends Representation @@ -15,19 +14,20 @@ class RoleRepresentation extends Representation /** * RoleRepresentation constructor. * - * @param string $id The unique ID of the role. - * @param string $name The name of the role. - * @param string|null $description A description of the role. - * @param bool|null $scopeParamRequired Whether the role is a default role. - * @param bool|null $composite Whether the role is a composite role. - * @param CompositesRepresentation|null $composites A list of composite roles if this role is a composite. - * @param bool|null $clientRole Whether the role is a client role. - * @param string|null $containerId The client ID of the client that the role belongs to. - * @param array|null $attributes A list of attributes associated with the role. + * @param string $id The unique ID of the role. + * @param string $name The name of the role. + * @param string|null $description A description of the role. + * @param bool|null $scopeParamRequired Whether the role is a default role. + * @param bool|null $composite Whether the role is a composite role. + * @param CompositesRepresentation|null $composites A list of composite roles if this role is a composite. + * @param bool|null $clientRole Whether the role is a client role. + * @param string|null $containerId The client ID of the client that the role belongs to. + * @param array|null $attributes A list of attributes associated with the role. */ public function __construct( /** * @var string The unique ID of the role. + * * @example 'b8f2d5a1-d123-4567-a456-426614174000' */ public string $id, @@ -44,6 +44,7 @@ public function __construct( /** * @var bool|null Whether the role is a default role. + * * @deprecated */ public ?bool $scopeParamRequired = null, @@ -65,6 +66,7 @@ public function __construct( /** * @var string|null The client ID of the client that the role belongs to. + * * @example 'b8f2d5a1-d123-4567-a456-426614174000' */ public ?string $containerId = null, @@ -73,5 +75,5 @@ public function __construct( * @var array|null A list of attributes associated with the role. */ public ?array $attributes = null, - ){} + ) {} } diff --git a/src/Representation/UpdateRoleRequest.php b/src/Representation/UpdateRoleRequest.php index 8e32cf1b..dd2d1954 100644 --- a/src/Representation/UpdateRoleRequest.php +++ b/src/Representation/UpdateRoleRequest.php @@ -7,7 +7,6 @@ /** * UpdateRoleRequest data transfer object class. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class UpdateRoleRequest extends Representation @@ -15,10 +14,10 @@ class UpdateRoleRequest extends Representation /** * UpdateRoleRequest constructor. * - * @param string|null $name The new name of the role (optional). - * @param string|null $description A new description of the role (optional). - * @param bool|null $composite Whether the role is a composite role (optional). - * @param array|null $composites A list of composite roles if this role is a composite (optional). + * @param string|null $name The new name of the role (optional). + * @param string|null $description A new description of the role (optional). + * @param bool|null $composite Whether the role is a composite role (optional). + * @param array|null $composites A list of composite roles if this role is a composite (optional). */ public function __construct( /** @@ -60,5 +59,5 @@ public function __construct( * @var array|null A list of attributes for the role (optional). */ public ?array $attributes = null, - ){} + ) {} } diff --git a/src/Representation/UserRepresentation.php b/src/Representation/UserRepresentation.php index d90f3cdb..767bc1ab 100644 --- a/src/Representation/UserRepresentation.php +++ b/src/Representation/UserRepresentation.php @@ -9,7 +9,6 @@ /** * UserRepresentation data transfer object class. * - * @package OpenSeaWave\Keycloak * @author Omar Haris */ class UserRepresentation extends Representation @@ -17,36 +16,37 @@ class UserRepresentation extends Representation /** * UserRepresentation constructor. * - * @param string|null $id The unique identifier of the user (optional). - * @param string|null $username The user's username (optional). - * @param bool|null $enabled Whether the user is enabled or not (optional). - * @param string|null $email The user's email address (optional). - * @param bool|null $emailVerified Whether the user's email is verified (optional). - * @param string|null $firstName The user's first name (optional). - * @param string|null $lastName The user's last name (optional). - * @param array|null $attributes An array of user attributes (optional). - * @param CredentialRepresentation[]|null $credentials The user's credentials (optional). - * @param UserActionType[]|null $requiredActions A list of actions required by the user on the next login (optional). - * @param array|null $groups A list of groups the user belongs to (optional). - * @param array|null $realmRoles A list of realm roles assigned to the user (optional). - * @param array|null $federatedIdentities Federated identities associated with the user from external identity providers (optional). - * @param array|null $clientRoles A list of client roles assigned to the user (optional). - * @param array|null $disableableCredentialTypes Types of credentials that are disabled for the user (optional). - * @param array|null $access Access level control for the user (optional). - * @param array|null $userProfileMetadata The user's profile metadata (optional). - * @param int|null $createdTimestamp The timestamp when the user was created (optional). - * @param array|null $applicationRoles A list of application roles assigned to the user (optional). - * @param array|null $socialLinks A list of social links associated with the user (optional). - * @param bool|null $totp Whether the user has time-based OTP enabled (optional). - * @param string|null $serviceAccountClientId The client ID for the service account associated with the user (optional). - * @param array|null $clientConsents A list of client consents granted by the user (optional). - * @param int|null $notBefore The "not before" timestamp for the user (optional). - * @param string|null $self The self-link for the user (optional). - * @param string|null $origin The origin of the user (optional). + * @param string|null $id The unique identifier of the user (optional). + * @param string|null $username The user's username (optional). + * @param bool|null $enabled Whether the user is enabled or not (optional). + * @param string|null $email The user's email address (optional). + * @param bool|null $emailVerified Whether the user's email is verified (optional). + * @param string|null $firstName The user's first name (optional). + * @param string|null $lastName The user's last name (optional). + * @param array|null $attributes An array of user attributes (optional). + * @param CredentialRepresentation[]|null $credentials The user's credentials (optional). + * @param UserActionType[]|null $requiredActions A list of actions required by the user on the next login (optional). + * @param array|null $groups A list of groups the user belongs to (optional). + * @param array|null $realmRoles A list of realm roles assigned to the user (optional). + * @param array|null $federatedIdentities Federated identities associated with the user from external identity providers (optional). + * @param array|null $clientRoles A list of client roles assigned to the user (optional). + * @param array|null $disableableCredentialTypes Types of credentials that are disabled for the user (optional). + * @param array|null $access Access level control for the user (optional). + * @param array|null $userProfileMetadata The user's profile metadata (optional). + * @param int|null $createdTimestamp The timestamp when the user was created (optional). + * @param array|null $applicationRoles A list of application roles assigned to the user (optional). + * @param array|null $socialLinks A list of social links associated with the user (optional). + * @param bool|null $totp Whether the user has time-based OTP enabled (optional). + * @param string|null $serviceAccountClientId The client ID for the service account associated with the user (optional). + * @param array|null $clientConsents A list of client consents granted by the user (optional). + * @param int|null $notBefore The "not before" timestamp for the user (optional). + * @param string|null $self The self-link for the user (optional). + * @param string|null $origin The origin of the user (optional). */ public function __construct( /** * @var string|null The unique identifier of the user (optional). + * * @example 'c1e9b67f-67d9-47e9-9e69-8c9b0a9e2c98' */ public ?string $id = null, @@ -83,6 +83,7 @@ public function __construct( /** * @var array|null An array of user attributes (optional). + * * @example ['phone' => '1234567890', 'address' => '123 Baghdad St'] */ public ?array $attributes = null, @@ -94,42 +95,49 @@ public function __construct( /** * @var UserActionType[]|null A list of actions required by the user on the next login (optional). + * * @example ['UPDATE_PASSWORD'] */ public ?array $requiredActions = null, /** * @var array|null A list of groups the user belongs to (optional). + * * @example ['/developers', '/admin'] */ public ?array $groups = null, /** * @var array|null A list of realm roles assigned to the user (optional). + * * @example ['offline_access', 'uma_authorization'] */ public ?array $realmRoles = null, /** * @var array|null Federated identities associated with the user from external identity providers (optional). + * * @example [['identityProvider' => 'google', 'userId' => '1234567890', 'userName' => 'googleuser@example.com']] */ public ?array $federatedIdentities = null, /** * @var array|null A list of client roles assigned to the user (optional). + * * @example ['client-id' => ['role1', 'role2']] */ public ?array $clientRoles = null, /** * @var array|null Types of credentials that are disabled for the user (optional). + * * @example ['password', 'otp'] */ public ?array $disableableCredentialTypes = null, /** * @var array|null Access level control for the user (optional). + * * @example ['manageGroupMembership' => true, 'view' => true, 'mapRoles' => true, 'impersonate' => false] */ public ?array $access = null, @@ -141,24 +149,28 @@ public function __construct( /** * @var int|null The timestamp when the user was created (optional). + * * @example 1631234567 */ public ?int $createdTimestamp = null, /** * @var array|null A list of application roles assigned to the user (optional). + * * @deprecated */ public ?array $applicationRoles = null, /** * @var array|null A list of social links associated with the user (optional). + * * @deprecated */ public ?array $socialLinks = null, /** * @var bool|null Whether the user has time-based OTP enabled (optional). + * * @example false */ public ?bool $totp = null, @@ -175,6 +187,7 @@ public function __construct( /** * @var int|null The "not before" timestamp for the user (optional). + * * @example 1627683600 */ public ?int $notBefore = null, @@ -188,5 +201,5 @@ public function __construct( * @var string|null The origin of the user (optional). */ public ?string $origin = null, - ){} + ) {} } diff --git a/tests/TestCase.php b/tests/TestCase.php index 5d778b01..6d04e1b9 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,8 +3,8 @@ namespace OpenSeaWave\Keycloak\Tests; use Illuminate\Database\Eloquent\Factories\Factory; -use Orchestra\Testbench\TestCase as Orchestra; use OpenSeaWave\Keycloak\KeycloakServiceProvider; +use Orchestra\Testbench\TestCase as Orchestra; class TestCase extends Orchestra {