Exception or error:
I’m trying to integrate vanilla forum with my company LDAP server. It’s not successful. I have no idea what’s wrong 🙁
Here’s how I do this:
The flow:
The plugin jsconnect is installed and config as follow:
- ClientID: generated
- Secret: generated
- Authentication URL:LoginController.php
Source of LoginController.php
<?php
include 'ChromePhp.php';
require_once 'functions.jsconnect.php';
// using ldap bind
$user_ = $_POST['user'];
$pass_ = $_POST['pass'];
// $ldaprdn = 'uid=riemann,dc=example,dc=com'; // ldap rdn or dn
// $ldappass = 'password'; // associated password
$ldaprdn = 'uid=';
$ldaprdn.=$user_.',dc=example,dc=com';
$ldappass=$pass_;
ChromePhp::log($ldaprdn);
// connect to ldap server
$ldapconn = ldap_connect("ldap.forumsys.com")
or die("Could not connect to LDAP server.");
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
ChromePhp::log("LDAP bind start...");
$validatedUser= FALSE;
if ($ldapconn) {
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
// echo "LDAP bind successful...";
ChromePhp::log("LDAP bind successful...");
$validatedUser =TRUE;
} else {
// echo "LDAP bind failed...";
ChromePhp::log("LDAP bind failed...");
}
}
$attributes = array('mail','cn');
$accountname = $user_;
$filter_person = "uid={$accountname}";
$search = ldap_search($ldapconn,"DC=example,DC=com",$filter_person , $attributes);
$data = ldap_get_entries($ldapconn, $search);
ChromePhp::log($data);
$fullname= $data[0]['cn'];
$mail= $data[0]['mail'];
ChromePhp::log($fullname);
ChromePhp::log($mail);
#intergrate
$clientID = "string";
$secret = "stringSecret";
$userArray = array();
if ($validatedUser) {
// CHANGE THESE FOUR LINES.
ChromePhp::log("start fill user...");
$userArray['uniqueid'] = $user_;
$userArray['name'] = $fullname['0'];
$userArray['email'] = $mail['0'];
$userArray['photourl'] = '';
}
// 4. Generate the jsConnect string.
// This should be true unless you are testing.
// You can also use a hash name like md5, sha1 etc which must be the name as the connection settings in Vanilla.
ChromePhp::log($userArray);
$secure = false;
WriteJsConnect($userArray, $_GET, $clientID, $secret, $secure);
//header("Location: ../../../v/"); /* Redirect browser */ //somehow add this make the file stop working :p
//exit();
?>
The problem is
- The LoginController output is {“name”:””,”photourl”:””} Seems not
right. - When php jump past
WriteJsConnect($user, $_GET, $clientID,
nothing happen, no new user created, the role is
$secret, $secure);
still guest.
How to solve: