1. Go to this page and download the library: Download gathern/casdoor-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gathern / casdoor-api example snippets
$connector = new \Gathern\CasdoorAPI\CasdoorConnector();
// Create a new user
$response = $connector->userApi()->apiControllerAddUser(
name: 'username'
);
// Update user password
$response = $connector->userApi()->apiControllerSetUserPassword(
userName: 'username',
newPassword: 'new_password'
);
// 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
);
// 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'
);
// 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'
);
// 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;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.