erwin32/ldap

Simple lib to authenticate trough ldap with some extra features

1.3 2018-01-26 13:25 UTC

This package is not auto-updated.

Last update: 2024-04-27 12:23:01 UTC


README

class for very simple ldap auth cheks if user exists and if he/she is in given group.

Usage:

$ composer require erwin32/ldap

Init sample

    // Active Directory server
    $ldap_host = "123.123.123.123";//IP adress or url

    // Active Directory DN
    $ldap_dn = 'DC=domain,DC=com';//domain in this example is used "domain.com"

    // Active Directory user group
    $ldap_user_group = "Group Name";

    // Active Directory manager group
    $ldap_manager_group = "Admins";

    // Domain, for purposes of constructing $user
    $ldap_usr_dom = "@domain.com";

    //class inicialization
    $ldap=new \LDAP\auth($ldap_host, $ldap_dn, $ldap_user_group, $ldap_manager_group, $ldap_usr_dom);

For auth use like this(expects inicialized class in $ldap)

first argument is username second is passoword

    try {
        $ldap->authenticate($user, $pass);
    } catch (Exception $exc) {
        $msg=$exc->getMessage();
        $code=$exc->getCode();

        //this is how we can determine if user dont have corect group but exist on LDAP
        if($ldap::ERROR_WRONG_USER_GROUP==$code){
            //custom handling
        }
    }

Thumbnail img retrival example

    try {
        $ldap->userInit($user, $pass);
        //we can display it like this
        echo '<img src="'.$ldap->getLDAPimg().'">';

    } catch (Exception $exc) {
        $msg=$exc->getMessage();
        $code=$exc->getCode();

        //react to problems
    }

Exeptions Error codes

    $ldap::ERROR_WRONG_USER_GROUP

    $ldap::ERROR_CANT_AUTH

    $ldap::ERROR_CANT_SEARCH

    $ldap::ERROR_IMG_DECODE