Last Updated on November 30, 2019 by Christopher G Mendla
I use adauth to authenticate users in my Rails apps using their Active Directory information. A model and table called User(s) gets created.
However, the standard setup for Adauth does not grab the user’s email address as it appears in Active Directory. You can grab and store the email using the following method.
- Add a field to the user model called email – varchar
- Add the following to your user model
- Adauth.add_field(Adauth::AdObj
ects ::User, :mail, :mail - :email => :mail
- Adauth.add_field(Adauth::AdObj
This will then cause adauth to grab the user email from active directory and populate the user model when the user logs on.
Your user model will need the following
include Adauth::Rails::ModelBridge
Adauth.add_field(Adauth::AdObjects ::User, :mail, :mail)
AdauthMappings = {
:login => :login, #was login login :group_strings => :cn_groups, :ou_strings => :dn_ous, :email => :mail, :name => :name }
AdauthSearchField = [:login, :login] def groups
group_strings.split(“, “)
end
endend