Params inside of Warden's strategy is empty when I try to authenticate through ajax

I'm trying to use Warden for authentication in my rails app. And it works fine if I use it with regular form via POST request. But when I moved it to Backbone.js I found that authenticate! method always calls my failure app.

I put some logging inside of authenticate! method and found that params hash is empty. Like that:

def authenticate!
    Rails.logger.debug "Parameters inside of Warden: #{params}"
    user = User.find_by_email(params['email'])
    if user && user.authenticate(params['password'])
      success! user
    else
      fail "Invalid email #{request.params['email']} or password #{request.params['password']}!"
    end
end

It generates an empty output: Parameters inside of Warden: {}

At the same time I can see params in controller before env['warden'].authenticate! is called. I can only guess where my parameters gone. What am I doing wrong?

Answers


I'm kind a new to Rails so my solution could be trivial. But as I didn't find anything related to it, It may be useful for somebody.

The point is that Warden instantiate Rack::Request to get an access to params hash. And it only supports 'application/x-www-form-urlencoded' and 'multipart/form-data'. http://rack.rubyforge.org/doc/classes/Rack/Request.html#M000275

Probably there is a different parser used in controller that's why I was confused. Finally I fixed it with external Rack-based Parser: https://github.com/achiu/rack-parser


Need Your Help

Grails 2.3.4 Database View as Domain Class

grails gorm

I am trying to use database view as domain class, following steps from Burt Beckwith slide.

How to get access token from FB.login method in javascript SDK

facebook facebook-javascript-sdk

I need to get the access token from FB.login method in Javascript SDK. My login code is