问题描述
所以,我有一个设置了 Okta 的 LDAP 目录。我无法使用 PHP 连接到它。这是我的代码:
$domain = 'phishingBoxdecember15thaccount.ldap.okta.com';
$username = 'USERNAME';
$password = 'PASSWORD';
$ldapconfig['host'] = '44.234.52.17'; // I got this by pinging the domain. I guess that's correct?
$ldapconfig['port'] = 636;
$ldapconfig['basedn'] = 'dc=phishingBoxdecember15thaccount,dc=okta,dc=com';
$ds=ldap_connect($ldapconfig['host'],$ldapconfig['port']);
ldap_set_option($ds,LDAP_OPT_PROTOCOL_VERSION,3);
ldap_set_option($ds,LDAP_OPT_REFERRALS,0);
$dn="ou=users,".$ldapconfig['basedn'];
$bind=ldap_bind($ds,$username .'@' .$domain,$password);
print_r($bind);
$isITuser = ldap_search($bind,$dn,'(&(objectClass=User)(sAMAccountName=' . $username. '))');
if ($isITuser) {
echo("Login correct");
} else {
echo("Login incorrect");
}
然而这永远行不通。总是得到“登录不正确”,我确定我使用的是正确的密码(虽然,我不确定用户名部分 - 我只是使用我输入的用户名登录到我的 Okta 管理员帐户,我假设这是正确的?)。
您对我如何使用 PHP 连接到 Okta LDAP 有任何想法/提示吗?
解决方法
您需要的设置在文档 here 中。对我来说跳出来的是主机应该是
我认为您的搜索需要调整为:ldap_search($bind,$dn,'(&(objectClass=inetOrgPerson)(uid=' . $username. '))');
但这不会停止您的登录。