简体   繁体   English

在ActiveResource中使用OAuth的最简单方法是什么?

[英]What's the easiest way to use OAuth with ActiveResource?

I'm working with some old code and using ActiveResource for a very basic Twitter integration. 我正在使用一些旧代码并使用ActiveResource进行非常基本的Twitter集成。 I'd like to touch the app code as little as possible and just bring OAuth in while still using ActiveResource. 我想尽可能少地触摸应用代码,并在使用ActiveResource的同时将OAuth引入。

Unfortunately I'm finding no easy way to do this. 不幸的是,我发现没有简单的方法来做到这一点。 I did run into the oauth-active-resource gem , but it's not exactly documented and it appears to be designed for creating full-on API wrapper libraries. 我确实遇到了oauth-active-resource gem ,但它没有完全记录,似乎是为创建完整的API包装库而设计的。 As you can imagine, I'd like to avoid creating a whole Twitter ActiveResource API wrapper for this one legacy change. 可以想象,我想避免为这一个遗留变化创建一个完整的Twitter ActiveResource API包装器。

Any success stories out there? 那里有成功案例吗? In my instance, it might be quicker to just leave ActiveResource rather than get this working. 在我的实例中,离开ActiveResource可能会更快,而不是让它工作。 I'm happy to be proven wrong! 我很高兴被证明是错的!

I had the same problem and built this simple gem to handle it: 我有同样的问题,并构建这个简单的宝石来处理它:

https://github.com/albertopq/oauth-activeresource https://github.com/albertopq/oauth-activeresource

You just need to use the oauth gem to retrieve the access token, and assign the final http object to your model. 您只需要使用oauth gem来检索访问令牌,并将最终的http对象分配给您的模型。 It will use that object instead the ActiveResource::Connection one. 它将使用该对象而不是ActiveResource :: Connection。

Hope it helps. 希望能帮助到你。

I just did this with omniauth and it was surprisingly easy. 我只是用omn​​iauth这样做,这简直太容易了。 This screencast and a subsequent one walks you through it. 这个截屏视频和随后的视频直播将引导您完成它。 All I needed was an initializer, a controller with login/logout actions and some attributes on my user model to store the Twitter id and screen name. 我需要的只是一个初始化程序,一个具有登录/注销操作的控制器以及我的用户模型上的一些属性来存储Twitter ID和屏幕名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM