Retrieving OAuth tokens (on server) from Faraday OAuth module (from client)

一个人想着一个人 提交于 2019-12-13 06:41:19

问题


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?


回答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.


来源:https://stackoverflow.com/questions/4755181/retrieving-oauth-tokens-on-server-from-faraday-oauth-module-from-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!