我已按照以下说明实施了devise和omniauth-facebook:
https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
问题
我的“facebook”回调函数确实被调用。
如果取消注释“facebook”功能,则会发生错误。
路由似乎工作正常
但是,该函数内部的代码似乎未执行。
以下代码不会引发任何错误。
我一直在研究这个问题好几天了。
请帮忙...
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
raise params.inspect
end
def failure
redirect_to root_path
end
end
日志
Finished "/cable/" [WebSocket] for ::1 at 2016-09-10 22:32:32 +0900
MessagesChannel stopped streaming from messages
Started GET "/cable" for ::1 at 2016-09-10 22:32:32 +0900
Started GET "/cable/" [WebSocket] for ::1 at 2016-09-10 22:32:32 +0900
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
MessagesChannel is transmitting the subscription confirmation
MessagesChannel is streaming from messages
Started GET "/users/auth/facebook" for ::1 at 2016-09-10 22:32:34 +0900
I, [2016-09-10T22:32:34.770050 #84008] INFO -- omniauth: (facebook) Request phase initiated.
Started GET "/users/auth/facebook" for ::1 at 2016-09-10 22:32:34 +0900
I, [2016-09-10T22:32:34.994734 #84008] INFO -- omniauth: (facebook) Request phase initiated.
Finished "/cable/" [WebSocket] for ::1 at 2016-09-10 22:32:35 +0900
MessagesChannel stopped streaming from messages
Started GET "/users/auth/facebook/callback?code=AQBICSjBfjCN7rGbCZLSkdg25FqTZGsnDrJi1UhBj0RwSQBjuZ5bTxEA025jApkwWiianigtILjRV5Uv067Yg73MGzi7sB5BT9yU0kjm7wzYzkBhWMmT0Aecw4ajACkSbBNfVUIii0cokommOAbSJgbzmfKRgbMGmdgYZsF6rBDuPyAGHnFgAa6bSl3jUmzW25SCTY9CDARiGlr880B-gwMs3gX0_KbtXnygAkBhNHoBSFFOIIY7w4QIMQHzZe1aLz6VWz_LxnuN88Ao8_lWOLPCfxsOWUJkdjYbLCowXmu1bpOu1zUuXSf6Dw9qBnWm73XvMyMD3iSasRRqlFW1uVde&state=2362c719c103b6b19f053ccc31b0b90ab34d137a71c2cb8d" for ::1 at 2016-09-10 22:32:40 +0900
I, [2016-09-10T22:32:40.549353 #84008] INFO -- omniauth: (facebook) Callback phase initiated.
Processing by Users::OmniauthCallbacksController#facebook as HTML
Parameters: {"code"=>"AQBICSjBfjCN7rGbCZLSkdg25FqTZGsnDrJi1UhBj0RwSQBjuZ5bTxEA025jApkwWiianigtILjRV5Uv067Yg73MGzi7sB5BT9yU0kjm7wzYzkBhWMmT0Aecw4ajACkSbBNfVUIii0cokommOAbSJgbzmfKRgbMGmdgYZsF6rBDuPyAGHnFgAa6bSl3jUmzW25SCTY9CDARiGlr880B-gwMs3gX0_KbtXnygAkBhNHoBSFFOIIY7w4QIMQHzZe1aLz6VWz_LxnuN88Ao8_lWOLPCfxsOWUJkdjYbLCowXmu1bpOu1zUuXSf6Dw9qBnWm73XvMyMD3iSasRRqlFW1uVde", "state"=>"2362c719c103b6b19f053ccc31b0b90ab34d137a71c2cb8d"}
Redirected to http://localhost:3000/
Filter chain halted as :authenticate_user! rendered or redirected
Completed 302 Found in 1ms (ActiveRecord: 0.0ms)
版本
devise 4.2.0
omniauth 1.3.1
omniauth-oauth2 1.4.0
omniauth-facebook 4.0.0
rails 5.0.0.1
最佳答案
我以一些不同的方式使用了回调:
您应该在omniauth.rb文件中声明回调:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, "app_id", "password",
scope: 'public_profile', info_fields: 'id,name,link', display: 'popup', callback_path: '/stores/facebook_callback'
end
并在控制器中添加“facebook_callback”操作(在我的情况下是存储),并将其添加到路由文件中。
关于ruby-on-rails - omniauth-facebook + devise回调未执行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39426730/