如何在Rails 2中正确使用OmniAuth

编程入门 行业动态 更新时间:2024-10-24 08:20:45
本文介绍了如何在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!

我也尝试过这种方法有人用过带有rails 2.3.8的omniauth吗?

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页面上创建了一个问题 github/intridea/omniauth/issues/397 ,上面有详细信息,这是OmniAuth的创建者Michael Bleigh的回复:

I created an issue on OmniAuth's Github page github/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

本文发布于:2023-10-16 11:54:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497484.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   如何在   Rails   OmniAuth

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!