将db_authenticatable添加到已经正常工作的omniautable devise安装会破坏sign_up

时间:2014-11-05 17:41:55

标签: ruby-on-rails ruby-on-rails-3 devise omniauth

我有一个Rails应用程序目前正在使用omniauth-facebook和Devise(https://github.com/plataformatec/devise),我想添加正常的db身份验证,当我使用sign_up_and_redirect @user时,由于某些原因会破坏omniauth。

以下是设计声明:

devise :database_authenticatable, :confirmable, :rememberable, :trackable, :omniauthable, :omniauth_providers => [ :facebook ]

在这里我从Facebook返回后登录我的用户:

def facebook
  @user = User.find_for_facebook_oauth( request.env["omniauth.auth"] )
  sign_in_and_redirect @user, :event => :authentication
  set_flash_message(:notice, :success, :kind => "Facebook")
end

以下是我在日志中看到的内容:

I, [2014-11-05T18:25:20.489760 #94984]  INFO -- omniauth: (facebook) Request phase initiated.
127.0.0.1 - - [05/Nov/2014 18:25:20] "GET /users/auth/facebook HTTP/1.1" 302 298  0.0169
I, [2014-11-05T18:25:20.910383 #94984]  INFO -- omniauth: (facebook) Callback phase initiated.
127.0.0.1 - - [05/Nov/2014 18:25:21] "GET /unauthenticated?code=AQBd86XvpY3mc75U6mEO7b_BbRTLPfb5r5YrRPHcJVKbGZN7kX_86xTZPeL-keScEPsMxbgkkYOlc2ZJXX34gUn8ZBW2UG74p1QIqe-aWEgAiZlXzVtqXsMGGTQzw1Wdi-UF1BnL0U0_7CYRNHzHlku7L6WO8-bQsQXjDR1JEDbLOiFcliznZw1QyKDbmZ9XWXU76R1ss8Ms1yo7_nMRe_YPQ6rFFgiBPsKnKfGQwpIiHB_uqF_JRF3jdTIzkVEg5G4QdQMZY-HIAAmi7d0ejiR1Qo&state=6ae72bde36266fa2c4e57437e66923d1f5c5c2d760dee7e7 HTTP/1.1" 302 - 1.0151
127.0.0.1 - - [05/Nov/2014 18:25:21] "GET /users/sign_in HTTP/1.1" 304 - 0.0438
127.0.0.1 - - [05/Nov/2014 18:25:22] "GET /jquery.js?body=1 HTTP/1.1" 304 - 0.0113

在我看来,Omniauth(成功)身份验证由于某些原因而触发了其他身份验证。我甚至尝试过sign_in_and_redirect User.first,但我的结果相同。

在添加db_authenticatable之后,我发现sign_in_and_redirect的行为已经改变,我不能再强制进行身份验证了。有没有人经历过这样的事情? TIA

1 个答案:

答案 0 :(得分:0)

确认是必需的,所以我需要

      user.skip_confirmation!