这是一个路由问题。
Omniauth 通过检测 404 错误页面来工作:
如果它与路由 /auth/:provider 匹配,那么它会捕获请求并将其发送给提供者
...但是舒适的墨西哥沙发 cms(如炼油厂和其他),有一条包罗万象的路线,这就是为什么请求从未返回 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"`
感谢OlegFederico Gonzalez
Khabarov
我希望这对其他人有帮助;-)
再见 Luca G. Soave