new*_*ike 6 devise omniauth ruby-on-rails-4
我得到了 Authentication failure! csrf_detected: 所以我无法登录omniauth.
我按照本教程
我在这里发现了类似的问题,
但到目前为止我的问题没有运气.
有没有修复错误的想法?谢谢
E, [2015-06-27T10:40:06.028200 #18798] ERROR -- omniauth: (facebook) Authentication failure! csrf_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected | CSRF detected
Run Code Online (Sandbox Code Playgroud)
* devise (3.5.0)
* omniauth (1.2.2)
* omniauth-facebook (2.0.0)
* omniauth-oauth2 (1.3.1)
Run Code Online (Sandbox Code Playgroud)
protect_from_forgery with: :exception
-
+ before_action :authenticate_user!
Run Code Online (Sandbox Code Playgroud)
devise :database_authenticatable, :registerable,
+ :omniauthable, :omniauth_providers => [:facebook]
+ def self.from_omniauth(auth)
+ where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
+ binding.pry
+ user.provider = auth.provider
+ user.uid = auth.uid
+ user.email = auth.info.email
+ user.password = Devise.friendly_token[0,20]
+ end
+ end
+
Run Code Online (Sandbox Code Playgroud)
+Rails.application.config.middleware.use OmniAuth::Builder do
+ provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'],
+ :scope => 'email'
+end
Run Code Online (Sandbox Code Playgroud)
Started GET "/users/auth/facebook/callback?code=AQDZC-Ny2PI-UwunCNi29mx4YGKT&state=cf896d3decffe2a7a664315e050a1165a290477542ff7d33" for 127.0.0.1 at 2015-06-27 10:40:05 +0800
I, [2015-06-27T10:40:05.255832 #18798] INFO -- omniauth: (facebook) Callback phase initiated.
I, [2015-06-27T10:40:06.028051 #18798] INFO -- omniauth: (facebook) Callback phase initiated.
E, [2015-06-27T10:40:06.028200 #18798] ERROR -- omniauth: (facebook) Authentication failure! csrf_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected | CSRF detected
Processing by CallbacksController#failure as HTML
Parameters: {"code"=>"AQDZC-Ny2PI-UwunCNi29mx4YGKTuHDeP2X2X-leywO14gr_iHLvXxX1LpV5WteUrQHpX-uc0Z01wcjy4XHA9CBkZeSo4qRb7jXdvPLfQl6mgwbMrFuQb1_55KughvtMWMlZ_7YEhtiLoEZH_2EvGXLbuKkUq", "state"=>"cf896d3decffe2a7a663"}
Run Code Online (Sandbox Code Playgroud)
+ devise_for :users, :controllers => { :omniauth_callbacks => "callbacks" }
Run Code Online (Sandbox Code Playgroud)
看来您也在Omniauth Facebook Github Repo上问过这个问题。看起来也没有一个可靠的答案。
@dmcbrayer确实建议将初始化程序更改为如下所示:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'],
:scope => 'email',
:info_fields => 'email'
end
Run Code Online (Sandbox Code Playgroud)
这是由于 facebook 方面的 API 更改导致您需要明确请求info_fields.
维护者@mkdynamic还希望您验证它是否已在较新版本(当时为 3.0.0)中修复。
| 归档时间: |
|
| 查看次数: |
3431 次 |
| 最近记录: |