设计& Rails 3.1 中的omniauth Facebook 身份验证

发布于 2024-12-03 11:13:46 字数 1598 浏览 0 评论 0原文

我已按照本指南让 Devise Facebook 身份验证正常工作,并且我现在已经到了我无法理解的地步,我需要一些帮助。

我收到“使用 Facebook 登录”链接,但单击它时出现以下错误,告诉我路线有问题

未知操作

找不到路径“/users/auth/facebook”的设备映射。也许您忘记将路线包装在范围块内?例如: devise_scope :user 匹配“/some/route”=> “some_devise_controller”结束

这是我的路线文件

  devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
  root :to => 'home#index'

编辑:

通过将路线更改为解决了该问题

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end
root :to => 'home#index'

现在我遇到了下一个错误,让 Facebook 身份验证正常工作,但是当从“允许应用程序屏幕”返回时,ruby 会抛出...

未定义方法“已关闭?”对于 nil:NilClass

activesupport (3.1.0.rc8) lib/active_support/whiny_nil.rb:48:in method_missing' /opt/local/lib/ruby/1.8/net/http.rb:1060:in请求' 法拉第 (0.6.1) lib/faraday/adapter/net_http.rb:51:in call' 法拉第 (0.6.1) lib/faraday/request/url_encoded.rb:14:incall' 法拉第 (0.6.1) lib/faraday/request.rb:88:in run' 法拉第 (0.6.1) lib/faraday/request.rb:28:inrun' 法拉第 (0.6.1) lib/faraday/connection.rb:170:in run_request' oauth2 (0.4.1) lib/oauth2/client.rb:63:in请求'

...

这是使用 Rails 3.1.0rc8 和 ruby​​ 1.9.2

I've followed this guide for getting Devise Facebook authentication to work and I've now come to a point where I can't understand and I would like some help.

I get the Sign in with Facebook link but clicking on it I get the following error, telling me there's something wrong with the routes

Unknown action

Could not find devise mapping for path "/users/auth/facebook". Maybe you forgot to wrap your route inside the scope block? For example: devise_scope :user do match "/some/route" => "some_devise_controller" end

Here is my routes file

  devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
  root :to => 'home#index'

Edit:

Solved that issue by changing the routes to

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end
root :to => 'home#index'

Now I got the next error getting the Facebook auth to work but when coming back from the "Allow app screen" ruby throws...

undefined method `closed?' for nil:NilClass

activesupport (3.1.0.rc8) lib/active_support/whiny_nil.rb:48:in method_missing'
/opt/local/lib/ruby/1.8/net/http.rb:1060:in
request'
faraday (0.6.1) lib/faraday/adapter/net_http.rb:51:in call'
faraday (0.6.1) lib/faraday/request/url_encoded.rb:14:in
call'
faraday (0.6.1) lib/faraday/request.rb:88:in run'
faraday (0.6.1) lib/faraday/request.rb:28:in
run'
faraday (0.6.1) lib/faraday/connection.rb:170:in run_request'
oauth2 (0.4.1) lib/oauth2/client.rb:63:in
request'

...

This is using Rails 3.1.0rc8 and ruby 1.9.2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸵鸟症 2024-12-10 11:13:46

我昨天刚刚完成我的应用程序的omniauth登录,使用完全相同的指南和rails 3.1 Final

不确定你的路线是否正确,我的看起来像这样:

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
  get 'sign_in', :to => 'users/sessions#new', :as => :new_user_session
  get 'sign_out', :to => 'users/sessions#destroy', :as => :destroy_user_session
end

devise_scope :user do
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end

在我的 devise_for :users 块中,我放置了标志登录并注销,因为我使用的是 OmniAuth,没有其他身份验证

该指南还指出 get '/users/auth/:provider' 行应该位于 devise_scope 中:user

不确定这会解决你的问题,但至少我想指出这些不适合评论的观点

I just finished yesterday my omniauth login for my app, using exactly the same guide and rails 3.1 final

Not sure you did your routes ok, mine look like this:

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
  get 'sign_in', :to => 'users/sessions#new', :as => :new_user_session
  get 'sign_out', :to => 'users/sessions#destroy', :as => :destroy_user_session
end

devise_scope :user do
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end

In my devise_for :users block I put the sign in and sign out because I'm using OmniAuth without other authentications

The guide also sais that the get '/users/auth/:provider' line should be in a devise_scope :user

Not sure this will fix your problem, but at least I wanted to state out these points, which don't fit in a comment

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文