bob1de / ldap-auth-sh

A simple but configurable shell script to authenticate against LDAP
GNU General Public License v3.0
79 stars 21 forks source link

Identification via attribute (e.g. email address) #2

Open lorenzschmid opened 5 years ago

lorenzschmid commented 5 years ago

Currently, authentication is only possible via the uid of the user. Thereby, the uid of the user as well as his password are used to make an authentication call to the LDAP server.

For my setup I wanted authentication to work with the user's mail attribute instead. Thereby, two authentication calls are necessary:

  1. Authentication via BIND DN (i.e. an admin account) which fetches the user's uid based on the given mail
  2. User authentiaction with the obtained uid

I modified the script accordingly but since I am not fluent in bash I prefer to write it down in this issue instead of a PR. Maybe there is a way to merge it with the existing code? Following my modifications:

You can find my update script here (breaking the original functionality of direct authentication). Following an example of the configuration file for the updated script:

SERVER="ldap://ldap.domain.com:389"
USERDN="uid=root,cn=users,dc=ldap,dc=domain,dc=com"
PW="[secret]"

BASEDN="cn=users,dc=ldap,dc=domain,dc=com"
SCOPE="one"
FILTER="(&(objectClass=person)(mail=$(ldap_dn_escape "$username")))"

NAME_ATTR="cn"
ATTRS="$ATTRS $NAME_ATTR"

USERNAME_PATTERN='^[a-z|A-Z|0-9|_|-|.|@]+$'
polcape commented 4 years ago

Hi @lorenzschmid ,

thanks for the work! I modified a bit your script and finally work the authetication by active directory!!

joshuaboniface commented 3 years ago

I ran into this same issue, and generalized the solution a bit more.

The updated code is in my fork: https://github.com/joshuaboniface/ldap-auth-sh