我将comfortable-mexican-sofa CMS与我的Rails 3.0.9应用程序集成了omniauth 0.2.6。
博客方面的一切都很好。我可以登录cms-admin,使用管理控制台,发帖和注销(cms-admin有自己的身份验证系统,不同于我的应用...),而不是我可以浏览新帖子。
问题是我的应用程序的其余部分,使用omniauth对用户进行身份验证,当我注销/打开时,我收到以下错误:
Started GET "/auth/github" for 127.0.0.1 at 2011-07-25 21:04:46 +0200
Processing by CmsContentController#render_html as HTML
Parameters: {"cms_path"=>"auth/github"}
SQL (0.3ms) SELECT COUNT(*) FROM "cms_sites"
Cms::Site Load (0.3ms) SELECT "cms_sites".* FROM "cms_sites" LIMIT 1
Completed 500 Internal Server Error in 156ms
NoMethodError (undefined method `gsub!' for nil:NilClass):
我的Gemfile.lock在这里:http://pastie.org/2270005
任何帮助将不胜感激。 Luca G. Soave
答案 0 :(得分:5)
这是一个路由问题。
Omniauth通过检测404错误页面来工作:
如果它匹配route / auth /:provider,那么它会捕获请求将其发送给提供者
...但comfortable-mexican-sofa cms(如refinery和其他人)有一个捕获所有路由,这就是为什么请求永远不会返回404错误,omniauth可以检测到错误。
在舒适墨西哥沙发的情况下,它会通过"cms_path"=>"auth/github"
获取
NoMethodError in CmsContentController#render_html
undefined method `gsub!' for nil:NilClass
而不是正确的omniauth路径,应该如下所示:
Started GET "/" for 127.0.0.1 at 2011-07-25 22:27:26 +0200
Processing by HomeController#index as HTML
Rendered home/index.html.haml within layouts/application (29.5ms)
Completed 200 OK in 44ms (Views: 42.8ms | ActiveRecord: 0.0ms)
Started GET "/auth/github" for 127.0.0.1 at 2011-07-25 22:27:35 +0200
MONGODB gitwatch_dev['users'].find({:provider=>"github", :uid=>1573})
Started GET "/auth/github/callback?code=4334bab983hd5fec19dd" for 127.0.0.1 at 2011-07-25 22:27:36 +0200
Processing by SessionsController#create as HTML
Parameters: {"code"=>"4334bab983hd5fec19dd", "provider"=>"github"}
Redirected to http://localhost:3001/
Completed 302 Found in 255ms
MONGODB gitwatch_dev['users'].find({:_id=>BSON::ObjectId('4e23114b1d41c80f180005b2')})
Started GET "/" for 127.0.0.1 at 2011-07-25 22:27:39 +0200
Processing by HomeController#index as HTML
Rendered home/index.html.haml within layouts/application (415.6ms)
Completed 200 OK in 890ms (Views: 428.6ms | ActiveRecord: 0.0ms)
我的案例中的解决方案如下:
app / controllers / errors_controller.rb中的
class ErrorsController < ApplicationController
def error
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end
end
config / routes.rb中的在底部添加
match '/auth/:provider' => 'errors#error'
...在Omniouth最后一条路线之后
`match "/auth/:provider/callback" => "sessions#create"`
感谢Federico Gonzalez
和Oleg Khabarov
我希望这能帮助别人; - )
bye Luca G. Soave