adauth undefined method `return_and_create_from_adauth' forAsk Question


i am trying to use adauth to integrate a rails app with active directory. I am getting

undefined method `return_and_create_from_adauth' for #

app/controllers/sessions_controller.rb:9:in `create'

class SessionsController < ApplicationController
def new
    redirect_to 'home' if current_user # home was /adauth
def create
    ldap_user = Adauth.authenticate(params[:username], params[:password])
    if ldap_user
    #   user = User.return_and_create_with_adauth(ldap_user)
        user = User.return_and_create_from_adauth(ldap_user)
        session[:user_id] =
        redirect_to 'home'
        redirect_to '/sessions/new', :error => "Invalid Login"

def destroy
    session[:user_id] = nil
    redirect_to '/sessions/new'

Note - I saw a post that said use create_from_adauth instead of create_with_adauth so I tried it both ways and got the same error.

Note If I login with good active directory credentials, I get the error. If I log in with bad active directory credentials, I get redirected to the login screen. That seems to indicate that the problem might be with the user model?

schema for users:

create_table "users", force: :cascade do |t|
t.string   "login"
t.text     "group_strings"
t.string   "name"
t.string   "ou_strings"
t.datetime "created_at",    null: false
t.datetime "updated_at",    null: false

Server Log

Started POST "/adauth" for at 2015-10-28 09:29:00 -0400
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"√",         "authenticity_token"=> j  
REMOVED BY    MEQ==",        
"username"=>"cmendla", "password"=>"[FILTERED]", "commit"=>"Login!"}
Completed 500 Internal Server Error in 12ms (ActiveRecord: 0.0ms)

NoMethodError (undefined method `return_and_create_with_adauth' 
for #      <Class:0x5163510>):
 app/controllers/sessions_controller.rb:8:in `create'

I want to add that I was having problems with the match lines so I used separate get/put lines in routes.rb. I'm not sure if that could be an issue here. The match statements that were throwing errors are commented out here.

  resources :users
# match \"/adauth\" => \"sessions#create\"
#  match \"/signout\" => \"sessions#destroy\"
get   "/adauth"   => "sessions#create"
 post  "/adauth"   => "sessions#create"
get   "/signout"  => "sessions#destroy"
post  "/signout"  => "sessions#destroy"

#  #match "/signout" => "sessions#destroy, via: [:get, :post]"
#  #match "/adauth" => "sessions#create, via: [:get, :post]"
resources :sessions
#  match "/signout" => "sessions#destroy"
#  match "/adauth" => "sessions#create"
#  resources :sessions
resources :searches
resources :attachments
mount Ckeditor::Engine => '/ckeditor'
resources :documents
resources :reviewers
resources :tags
resources :authors
resources :tags
resources :categories
resources :help_requests

get 'home' => 'home_page#home'
get 'help/uploads' => 'about_and_help#upload_help'
get 'about' => 'about_and_help#about'
get 'attachments' => 'attachments#index'
# get 'login' => 'sessions#create'
# post 'login' => 'sessions#create'
get 'login' => 'sessions#new'
post 'login' => 'sessions#new'


You need to change the method name from return_and_create_with_adauth to return_and_create_from_adauth. The correction would be:

user = User.return_and_create_from_adauth(ldap_user)

Here's a link to the new model:


You did not show your User model. I believe you may have omitted include Adauth::Rails::ModelBridge

标签: ruby authentication
© 2014 TuiCode, Inc.