Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring routes in devise when only using omniauth for authentication

I have built an application which allows a user to authenticate against Active Directory using omniauth-ldap. If this is a new user, the successful authentication creates a user for them based on information returned from AD. If the user already exists, it just logs them in. Users do not register for the application, they just log in with AD credentials. And I never want the user to log in with database credentials.

I can't figure out how to get rid of or change around some of the routes. For example if a user visits /sign_in they get the database authentication. And if the user visits sign_up they are taken to a page to register for the site. I would like for users that visit /sign_in to be taken to the LDAP login which is /users/auth/ldap. I think I need to make a custom route, but I'm not sure which controller I need to direct the user to. And I want to make the sign_up page go away entirely.

Right now I have a link that allows users to log in using ldap, and the path for that is user_omniauth_authorize_path(:ldap). I'm just not sure how to translate that into something that my config/routes.rb file understands. This is what I have in routes right now.

   devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }  do  
      get 'sign_in', :to => 'devise/sessions#new', :as => :new_user_session
      get 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session
  end 

When I run rake routes I do not see any route for user_omniauth_authorize_path which I presume is because that route is being generated by devise. So I think I need to have my routes point to a devise controller, but I can't seem to find the right path.

like image 435
Kevin Thompson Avatar asked Dec 21 '11 21:12

Kevin Thompson


1 Answers

Try to add

:skip => [:sessions, :registrations] to your routes.rb

Something like this:

devise_for :users, :skip => [:sessions, :registrations]

This How To article might be helpful, and also here is one more link to go through.

like image 88
Bob Avatar answered Oct 05 '22 23:10

Bob