Получение токенов OAuth (на сервере) из модуля Faraday OAuth (от клиента)

Я использую Faraday для связи между двумя веб-приложениями, которые я разрабатываю (background и связанный вопрос). Я использую токены OAuth как часть формы загрузки/подключения клиентского приложения к серверному приложению.

Однако я не могу найти токены OAuth в хэшах заголовка или action_dispatch и т. д.

Какие-либо предложения?


person cbrulak    schedule 21.01.2011    source источник


Ответы (1)


Я нашел ответ здесь: 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.
person cbrulak    schedule 02.02.2011
comment
Немного не по теме, но есть ли промежуточное ПО CookieAuth для Faraday? - person madh; 20.02.2012
comment
@madh на самом деле не уверен. Если узнаешь, отпишись. - person cbrulak; 22.02.2012
comment
Я уверен, что CookieAuth — это просто самописное промежуточное ПО. Вы можете сделать любой класс промежуточным программным обеспечением, если вы подклассируете его с любым существующим промежуточным программным обеспечением, таким как, например, Faraday::Response::Middleware. - person janko-m; 25.04.2012