Ruby on rails 从Faraday OAuth模块(从客户端)检索OAuth令牌(在服务器上)

Ruby on rails 从Faraday OAuth模块(从客户端)检索OAuth令牌(在服务器上),ruby-on-rails,ruby,oauth,faraday-oauth,Ruby On Rails,Ruby,Oauth,Faraday Oauth,我用它在我正在开发的两个web应用程序(和一个)之间进行通信。我使用OAuth令牌作为从客户端应用程序到服务器应用程序的上传/连接的一部分 然而,我似乎无法在标头或action_dispatch哈希等中找到OAuth标记 有什么建议吗 我在这里找到了答案: 您好,我遇到了同样的问题,并发现这是因为我在中间件之前使用了Faraday.default_适配器(在Faraday::Connection constructor块中)。 也许这会有所帮助,因为我看到问题仍然悬而未决。 从: @connec

我用它在我正在开发的两个web应用程序(和一个)之间进行通信。我使用OAuth令牌作为从客户端应用程序到服务器应用程序的上传/连接的一部分

然而,我似乎无法在标头或action_dispatch哈希等中找到OAuth标记

有什么建议吗

我在这里找到了答案:

您好,我遇到了同样的问题,并发现这是因为我在中间件之前使用了Faraday.default_适配器(在Faraday::Connection constructor块中)。 也许这会有所帮助,因为我看到问题仍然悬而未决。 从: @connection | |=法拉第::connection.new(:url=>)http://...)do | builder| builder.adapter Faraday.default_适配器 builder.use CookieAuth 结束 到 @connection | |=法拉第::connection.new(:url=>)http://...)do | builder| builder.use CookieAuth builder.adapter Faraday.default_适配器 结束 帮我解决了这个问题。 发生的情况是,当调用任何http连接方法时(回到Faraday::Connection#run#请求),默认的#u适配器实际上会在中间件之前执行请求(如Faraday::adapter::NetHttp#call:45),因此修改后的头不会发送到服务器。 然而,测试用例通过了,因为调用了middware(在请求之后)并更新了env中的请求_头。 总之,只需确保在任何适配器实际执行请求之前配置任何“请求修改器”中间件。
有点离题,但法拉第是否有CookieAuth中间件?@madh实际上并不确定。如果发现了,请发帖子。所以一些Google Fu引导我到这里:我还没有尝试过。我确信
CookieAuth
只是一个自行编写的中间件。如果使用任何现有的中间件(例如
Faraday::Response::middleware
)对任何类进行子类化,则可以将其作为任何类a中间件。 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.