I wanted to provide our CRM users an alternate way of logging to the system using their Zimbra email authentication and there is a really easy way of doing it which I have figured out in little while with googling. Definitely PHP online help docs and Zimbra forums both came to help and found a correct options to use from Zimbra Forums which is powered by it's USERS.
Just make sure to enable php_ldap extension before you move further.
// Uncomment following line from php.ini extension=php_ldap.dll
Following code snippet could be used to authenticate and find out whether provided Username and Password belongs to valid Zimbra User or not by authenticating it with Zimbra's LDAP (Light-weight Directory Access Protocol) server. So this way if you want you can provide your intranet/business application users an ability to use their Zimbra (mail/collaboration system) password to be used as an optional way to authenticate themselves.
<?php // Domain to be authenticated when your zimbra mail server is setup like "zimbra.domain.com" $Domain = 'digitss'; // Username to be authenticated $Username = 'guest'; // Password; these username and password could be passed from login form $Password = 'password'; $IsValidUser = FALSE; try { // Just in case your Zimbra server is setup in a format like "zimbra.domain.com" $LDAPConnection = ldap_connect("zimbra.".$Domain.".com",389); } catch(Exception $e) { $error = "Can't connect to LDAP server." . $e->getMessage(); } // Set LDAP protocol version to 3: not being able to set will cause an error and can't continue further if (!ldap_set_option($LDAPConnection,LDAP_OPT_PROTOCOL_VERSION,3)) { $error = "LDAP Server protocol error."; } // Authenticate Username and Password using ldap_bind function try { $LDAPbind = @ldap_bind($LDAPConnection,'uid='.$Username.',ou=people,dc='.$Domain.',dc=com' , $Password); if($LDAPbind) { $IsValidUser = TRUE; } } catch(Exception $e) { $error = "Unable to bind: " . $e->getMessage(); } ?>
Above code snippet can be molded as a function which could optionally authenticate and users with Zimbra or any other LDAP authentication with little modification.
References:
http://us2.php.net/manual/en/book.ldap.php
http://www.zimbra.com/forums/21931-post1.html
http://wiki.zimbra.com/index.php?title=LDAP_Authentication
#1 by Matthew Shahi on January 19, 2010 - 6:40 pm
Quote
I have for month looked for this script, thank God for people like you, you have my solution
#2 by Yogesh on February 2, 2011 - 12:47 pm
Quote
Hi Matthew,
Thanks for giving this script. But this time I want to authenticate wordpress from my zimbra email server. I want that any user who will contribute to my wordpress official blogs must enter the email id and password to continue to wordpress blog