如何在Rails 2中正确使用OmniAuth [英] How to Use OmniAuth Properly with Rails 2

查看:72
本文介绍了如何在Rails 2中正确使用OmniAuth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对我的应用程序使用OmniAuth(0.2.6)策略.该体系结构是Rails 2.3.10,而Rack是1.1版(OmniAuth需要此版本或更高版本).发生的问题是Rails无法识别我对"/auth/provider"的重定向.实际的错误消息是没有路由匹配"/auth/casport".即使抛出该错误,代码也似乎执行到该错误为止:"request.env ['omniauth.auth']",该错误我非常确定这意味着它无法识别环境散列的"omniauth.auth"键.我觉得OmniAuth无法正确加载.我已经用Mongrel和Webrick测试了相同的策略和代码库,并且收到相同的错误消息.

I am trying to use an OmniAuth (0.2.6) strategy for my application. The architecture is Rails 2.3.10 and Rack is version is 1.1 (this version or higher is required for OmniAuth). A problem that occurs is Rails doesn't recognize my redirect to "/auth/provider". The actual error message is "No route matches "/auth/casport". Even though that error gets thrown, the code seems to execute past that point up to this error: "request.env['omniauth.auth']", which I'm pretty sure means it doesn't recognize the "omniauth.auth" key for the env hash. I have a feeling that OmniAuth isn't being loaded properly. I've tested the same strategy and code base with Mongrel and Webrick, and I get identical error messages.

这是我的OmniAuth初始化程序(config/initializers/omniauth.rb):

Here is my OmniAuth initializer (config/initializers/omniauth.rb):

ActionController::Dispatcher.middleware.use OmniAuth::Builder do
  provider :casport, :setup => true
end

我肯定在auth/casport/setup和auth/casport/callback的地方有路由.

I definitely have routes in places for auth/casport/setup and auth/casport/callback.

我也尝试过这种方法:您如何在Rails 2.2上实现OmniAuth?

I've also tried this approach: How do you implement OmniAuth on Rails 2.2?

config.middleware.use OmniAuth::Builder do
  provider :casport, :setup => true
end

通过将该中间件代码放置在config/environments/development.rb文件中.

by placing that middleware code in the config/environments/development.rb file.

有人对我可能做错的事情有任何想法吗?谢谢!

Does anyone have any thoughts on what I could be doing incorrectly? Thanks!

我也尝试过这种方法

I've also tried this approach Has anyone used omniauth with rails 2.3.8?

ActionController::Dispatcher.middleware.use OmniAuth::Strategies::Casport = {
  :setup => true
}

并返回读取错误:"NoMethodError:#Hash的未定义方法'new'...

and that returns a read error: "NoMethodError: undefined method 'new' for #Hash...

我已升级到Rails 2.3.10,因为OmniAuth与Rails 2.3.4不兼容.

Edit 2: I've upgraded to Rails 2.3.10 as OmniAuth isn't compatible with Rails 2.3.4.

推荐答案

我在OmniAuth的Github页面上创建了一个问题

I created an issue on OmniAuth's Github page https://github.com/intridea/omniauth/issues/397, with the above details and this is the response from Michael Bleigh, the creator of OmniAuth:

"OmniAuth从未正式支持Rails 2.3.x,我听说有些人对此感到幸运,但这并不能保证.抱歉!"

"OmniAuth has never officially supported Rails 2.3.x -- I've heard that some people have had luck with it but it's not something that is guaranteed. Sorry!"

因此,看来我上面发布的方法可能对某些人有用.为了保证正确的操作,需要Rails 3.

So it looks like the methods I posted above may work for some folks. To guarantee correct operation, Rails 3 is needed.

这篇关于如何在Rails 2中正确使用OmniAuth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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