Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devise with ActiveLDAP #1

Open
unixmechanic opened this issue Aug 11, 2012 · 1 comment
Open

Devise with ActiveLDAP #1

unixmechanic opened this issue Aug 11, 2012 · 1 comment

Comments

@unixmechanic
Copy link

Hi Kou,

is this active work? I would like to enable authentication/authorization in my project which uses ActiveLdap for the models. I would like to authenticate against the corporate ActiveDirectory servers, which are different from the servers used to store the model data. What options do I have here?

@kou
Copy link
Member

kou commented Aug 12, 2012

It is not active. :<
But I will show you an example.

First, implement LdapUser.authenticate like https://github.com/activeldap/al-admin/blob/rails2/app/models/ldap_user.rb and User.authenticate like https://github.com/activeldap/al-admin/blob/rails2/app/models/user.rb.

Then, define a new Warden strategy:

Warden::Strategies.add(:ldap) do
  def valid?
    params[:username] || params[:password]
  end

  def authenticate!
    u = User.authenticate(params[:username], params[:password])
    u.nil? ? fail!("Could not log in") : success!(u)
  end
end

The strategy implementation is derived from https://github.com/hassox/warden/wiki/Strategies.

Finally, use the strategy in Devise:

Device.setup do |config|
  # ...
  config.warden do |manager|
    manager.default_strategies(:scope => :use).unshift(:ldap)
  end
end

Note that I don't try the example. Sorry. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants