Omniauth.params are empty hash (api_only)

Viewed 132

Environment

  • Ruby 2.7.4 (Rails API only)
  • Rails 6.0.4.1
  • Devise 4.8.0
  • Omniauth1.8.1

Current behavior

Getting omniauth missing_credentials? error. The request.params is always an empty hash even though I provide username and password in the request body via POST method. I can see the body params when debugging actual controller, but it looks like those params are not passed to omniauth request.

enter image description here

screen1

screen2

Controller:

module Api
  module V1
    module Auth
      class OmniauthCallbacksController < Devise::OmniauthCallbacksController #< ApplicationController#
        include ActionController::Cookies
     
        def ldap
          puts request.env['omniauth.auth'] # => NULL

        end

        def failure
          puts "request.env['omniauth.auth']: #{request.env['omniauth.auth']}" # => NULL
          puts "request.env['omniauth.params']: #{request.env['omniauth.params']}" # => {}
          puts "params: #{params}" # => { "username": "myusername", "password": "mypassword" }

          render json: { status: "fail" }
        end
      end
    end
  end
end

Application.rb:

    config.api_only = true
    config.session_store :cookie_store, key: '_interslice_session'
    config.middleware.use ActionDispatch::Cookies
    config.middleware.use config.session_store, config.session_options

Routes.rb: devise_for :users, controllers: { omniauth_callbacks: 'api/v1/auth/omniauth_callbacks' }

Devise.rb:

config.omniauth :ldap, :host => 'XXX.com',
                :port => 389,
                :method => :plain,
                :base => 'cn=accounts,dc=int,dc=dostack,dc=io',
                :uid => 'uid',
                :try_sasl => false,
                :bind_dn => "uid=XXX,cn=users,cn=accounts,dc=int,dc=dostack,dc=io",
                :password => "xxxxxxxx"

Response: image

Expected behavior

Authenticate using omniauth (LDAP or using any other omniauth provider)

0 Answers
Related