gathern / casdoor-api
A skeleton repository for my packages
v0.3.0
2025-06-17 16:18 UTC
Requires
- php: ^8.1.0
- eventsauce/object-hydrator: ^1.6
- saloonphp/saloon: ^3.0
Requires (Dev)
- laravel/pint: ^1.18.1
- pestphp/pest: ^3.5.1
- pestphp/pest-plugin-type-coverage: ^3.1
- phpstan/phpstan: ^1.12.7
- rector/rector: ^1.2.8
- symfony/var-dumper: ^7.1.6
README
This package provides a wonderful Casdoor-api integration for PHP projects.
Requires PHP 8.1+
Installation
You can install the package via composer:
composer require gathern/casdoor-api
Usage
$connector = new \Gathern\CasdoorAPI\CasdoorConnector();
Available Endpoints
User API
// Create a new user $response = $connector->userApi()->apiControllerAddUser( name: 'username' ); // Update user password $response = $connector->userApi()->apiControllerSetUserPassword( userName: 'username', newPassword: 'new_password' );
Login API
// Login with username and password $response = $connector->loginApi()->apiControllerLogin( application: 'your-app-name', username: 'username', signinMethod: \Gathern\CasdoorAPI\Enum\SignInMethod::PASSWORD, password: 'password' ); // Get JWT token using client credentials $response = $connector->TokenApi()->apiControllerGetOauthToken( clientId: 'your-client-id', clientSecret: 'your-client-secret', grantType: \Gathern\CasdoorAPI\Enum\GrantType::CLIENT_CREDENTIALS );
Role API
// Get all roles $response = $connector->roleApi()->apiControllerGetRoles(); // Get role details $response = $connector->roleApi()->apiControllerGetRole(id: 'role-name'); // Add a new role $response = $connector->roleApi()->apiControllerAddRole( name: 'new-role', displayName: 'New Role' ); // Update a role $response = $connector->roleApi()->apiControllerUpdateRole( id: 'role-name', displayName: 'Updated Role Name' ); // Update role from role data object $roleDetails = $connector->roleApi()->apiControllerGetRole(id: 'role-name')->dto(); $response = $connector->roleApi()->apiControllerUpdateRoleFromRoleData( $roleDetails->data, displayName: 'Updated Role Name' );
Group API
// Get all groups $response = $connector->groupApi()->apiControllerGetGroups('organization-name'); // Get group details $response = $connector->groupApi()->apiControllerGetGroup(id: 'group-name'); // Add a new group $response = $connector->groupApi()->apiControllerAddGroup( name: 'new-group' ); // Update a group $response = $connector->groupApi()->apiControllerUpdateGroup( id: 'group-name', name: 'updated-group-name' );
Handling Responses
All API methods return a response object with the following methods:
// Get the response as a DTO $responseDto = $response->dto(); // Check the status of the response if ($responseDto->status === \Gathern\CasdoorAPI\Enum\ResponseStatus::OK) { // Success $data = $responseDto->data; } else { // Error $errorMessage = $responseDto->msg; }
๐งน Keep a modern codebase with Pint:
composer lint
โ Run refactors using Rector
composer refacto
โ๏ธ Run static analysis using PHPStan:
composer test:types
โ Run unit tests using PEST
composer test:unit
๐ Run the entire test suite:
composer test