1

I'm using Faraday to communicate between two web apps that I am developing (background and a related question). I'm using OAuth Tokens as part of the upload/connection form the client app to the server app.

However, I can't seem to find the OAuth tokens in the header or action_dispatch hashes, etc.

Any suggestions?

Community
  • 1
  • 1
cbrulak
  • 15,436
  • 20
  • 61
  • 101

1 Answers1

1

I found the answer here: https://github.com/technoweenie/faraday/issues#issue/12

Hi there, I ran into the same problem and found that it was because I used the Faraday.default_adapter before my middleware (in a Faraday::Connection contructor block).

Maybe this can help as I see the issue is still open.

Going from:

@connection ||= Faraday::Connection.new(:url => "http://...") do |builder|
  builder.adapter Faraday.default_adapter
  builder.use CookieAuth
end
to

@connection ||= Faraday::Connection.new(:url => "http://...") do |builder|
  builder.use CookieAuth
  builder.adapter Faraday.default_adapter
end
solved the problem for me.

What happens is that when any http method of Connection is called (falling back to Faraday::Connection#run_request), the default_adapter actually performs the request (like in Faraday::Adapter::NetHttp#call:45) before the middleware and so the modified headers are not sent to the server.

Yet the test case passes because the middeware is called (after the request) and updates the request_headers in the env.

To sums things up, just be sure to configure any "request modifier" middleware before any adapter that actually performs the request.
cbrulak
  • 15,436
  • 20
  • 61
  • 101
  • A bit off topic, but is there a CookieAuth middleware for Faraday? – madh Feb 20 '12 at 19:21
  • @madh not sure actually. If find out please do post. – cbrulak Feb 22 '12 at 17:24
  • So some Google Fu led me here: https://github.com/wtn/bullion_vault/blob/master/lib/faraday/cookie_auth.rb I have not tried it though. – madh Feb 23 '12 at 19:02
  • I'm sure `CookieAuth` is just a self written middleware. You can make any class a middleware if you subclass it with any exisiting middleware, such as `Faraday::Response::Middleware`, for example. – Janko Apr 25 '12 at 19:13