Authenticating on external Zimbra LDAP using PHP

Have a great idea for extending Zimbra? Share ideas, ask questions, contribute, and get feedback.
Post Reply
Xinit
Posts: 9
Joined: Wed May 11, 2016 10:30 am

Authenticating on external Zimbra LDAP using PHP

Post by Xinit »

I need to be able to authenticate for a PHP-based service using an external email server run using Zimbra 8.6 (open source version). I have been trying to figure out a way to do that, and it seems the general approach is to use SoAP based queries. I am not conversant with SoAP, I know that LDAP is a normal service and should be able to directly bind to the port and authenticate like with any other LDAP service, say as follows:

Code: Select all

function authenticate($uid, $pwd) {
    if ($pwd) {
        $ds = ldap_connect("zimbra.server");
        $ds = ldap_connect("x.y.z.a");
        ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
        $a = ldap_search($ds, "dc=FOO1,dc=FOO2,dc=FOO3", "uid=$uid");
        $b = ldap_get_entries($ds, $a);
        $dn = $b[0]["dn"];
        if (ldap_bind($ds, $dn, $pwd)) {
            ldap_close($ds);
            return TRUE;
        }
    }
    return FALSE;
} 
Though I was able to find PHP wrappers for the same, they provide more capabilities and for reasons of security, I do not wish to enable them, instead using the LDAP service directly as only authentication is required. Also I see that the SoAP versions change between releases. Does this approach work with ZCS?
Post Reply