1. Go to this page and download the library: Download foglcz/ldap-authenticator 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/ */
foglcz / ldap-authenticator example snippets
/**
* Success handler for LDAP authenticator - loads the ID in database
*
* @param \Toyota\Component\Ldap\Core\Manager $ldap
* @param array $userData
* @throws Security\AuthenticationException
* @return int
*/
public function getAuthId(\Toyota\Component\Ldap\Core\Manager $ldap, array $userData)
{
$username = 'ldap/' . $userData['username'];
if($user = $this->database->table('user')->where('username = ?', $username)->fetch()) {
return $user->id;
}
return $this->database->table('user')->insert(array('username' => $username));
}
public function createIdentity(Toyota\Component\Ldap\Core\Manager $ldap, array $userData)
{
$roles = array();
if(!isset($userData['memberOf'])) {
throw new PossibleConfigurationErrorException('User\'s memberOf index is not set; maybe reset default groups handler?');
}
// Load roles based on membership if needed
if(isset($this->config['loadRolesAsMailGroups'])) {
$roles = array_merge($roles, $this->loadRoleMailsFromGroups($userData));
}
// Load roles mapping if set
if(isset($this->config['rolesMap'])) {
$roles = array_merge($roles, $this->loadRoleMapping($userData));
}
// In-load admin groups if requested
if(isset($this->config['adminGroups']) && !in_array('admin', $roles) && $this->loadIsAdminMember($userData)) {
$roles[] = 'admin';
}
// Create identity & return
return new Identity(isset($userData['id']) ? $userData['id'] : $userData['username'], $roles, $userData);
}
public function createUsername(Manager $ldap, $username)
{
return 'yourdomain\\' . $username;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.