3

I work with Devise token_authentication service and ActiveResource client. I wish set automatically :auth_token params in every requests !

I tried this, but this doesn't work...

class AuthApp

    def initialize(app)
        @app = app
    end

    def call(env)
        status, headers, response = @app.call(env)

        request = Rack::Request.new(env)
        request.params[:auth_token] = 'jCxKPj8wJJdOnQJB8ERy'

        [status, headers, response]
    end

end

Any idea ?

Alec Sanger
  • 4,442
  • 1
  • 33
  • 53
Joel AZEMAR
  • 2,506
  • 25
  • 31
  • I'm having the exact same issue. In fact, I had it working in Rails 3.0.7 and an older version of Rack. Now, broken. I can see in the Rack app that the newly merged params are there, but they're not hanging out for the ride into Rails. – Chuck Bergeron Sep 16 '11 at 18:48

1 Answers1

4

If you have a recent copy of rack that includes this pull request, you can use Rack::Request#update_param:

request = Rack::Request.new(env)
request.update_param :auth_token, 'jCxKPj8wJJdOnQJB8ERy'

That will persist in the env that is passed among middlewares (and to Rails).

Seamus Abshere
  • 8,326
  • 4
  • 44
  • 61
  • This doesn't seem to be in the gem released version, both master and the gem released are at 1.4.1 and only master has this? Am I missing something? – Inc1982 Dec 06 '12 at 21:36
  • You're correct - this feature is not in 1.4.1. Hopefully they release 1.5 soon... it's been a **long** time. – Seamus Abshere Dec 06 '12 at 21:45
  • Thanks for the quick heads up.. that said your code and the reference still helped me get my answer, so thanks. – Inc1982 Dec 06 '12 at 22:03