从 Faraday OAuth 模块(从客户端)检索 OAuth 令牌(在服务器上) [英] Retrieving OAuth tokens (on server) from Faraday OAuth module (from client)

查看:59
本文介绍了从 Faraday OAuth 模块(从客户端)检索 OAuth 令牌(在服务器上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Faraday 在我正在开发的两个网络应用程序之间进行通信(背景相关问题).我使用 OAuth 令牌作为从客户端应用程序到服务器应用程序的上传/连接的一部分.

但是,我似乎无法在标头或 action_dispatch 哈希等中找到 OAuth 令牌.

有什么建议吗?

解决方案

我在这里找到了答案:https://github.com/technoweenie/faraday/issues#issue/12

<前>您好,我遇到了同样的问题,发现这是因为我在中间件之前使用了 Faraday.default_adapter(在 Faraday::Connection 构造函数块中).也许这会有所帮助,因为我看到问题仍然存在.从:@connection ||= Faraday::Connection.new(:url => "http://...") 做 |builder|builder.adapter Faraday.default_adapterbuilder.use CookieAuth结尾至@connection ||= Faraday::Connection.new(:url => "http://...") 做 |builder|builder.use CookieAuthbuilder.adapter Faraday.default_adapter结尾为我解决了这个问题.发生的情况是,当调用 Connection 的任何 http 方法时(回退到 Faraday::Connection#run_request),default_adapter 实际上在中间件之前执行请求(如 Faraday::Adapter::NetHttp#call:45),等等修改后的标头不会发送到服务器.然而,测试用例通过了,因为中间件被调用(在请求之后)并更新了 env 中的 request_headers.总而言之,只需确保在实际执行请求的任何适配器之前配置任何请求修饰符"中间件.

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?

解决方案

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.

这篇关于从 Faraday OAuth 模块(从客户端)检索 OAuth 令牌(在服务器上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆