Omniauth:Facebook 回调杀死了开发服务器
我正在遵循这里的代码: http://railscasts.com/episodes/241-simple-omniauth?autoplay=true
我使用的是 ruby 1.9.2p180(2011-02-18 修订版 30909) [x86_64-darwin10.7.0] 和 Rails 3.0.7
基本上,我有自己的用户模型(没有 Devise/AuthLogic)。我创建了一个 SessionsController 来处理 Facebook 回调:
match "/auth/facebook/callback" => "sessions#create"
def create
auth = request.env["omniauth.auth"]
user = User.find_by_email(auth["user_info"]["email"]) || User.create_with_omniauth(auth)
session[:user_id] = user.id
redirect_to root_url
end
最后,我的用户模型:
class User < ActiveRecord::Base
has_one :facebook
validates :email, :presence => true, :uniqueness => true
validates :facebook, :presence => true
def self.create_with_omniauth(auth)
create! do |user|
user.email = auth["user_info"]["email"]
user.facebook = Facebook.create!(:uid => auth["uid"])
end
end
class Facebook < ActiveRecord::Base
belongs_to :user
validates :uid, :presence => true, :uniqueness => true
end
当我在本地主机上运行它并授予应用程序访问权限时,它会访问我的开发服务器并杀死它。这是堆栈跟踪(始终可重现):
-- control frame ----------
c:0060 p:---- s:0340 b:0340 l:000339 d:000339 CFUNC :connect
c:0059 p:0011 s:0337 b:0337 l:000150 d:000336 BLOCK /Users/andy/.rvm/rubies/ruby-1.9.2 -p180/lib/ruby/1.9.1/net/http.rb:678
c:0058 p:0031 s:0335 b:0335 l:000334 d:000334 METHOD /Users/andy/.rvm/rubies/ruby-1.9.2- p180/lib/ruby/1.9.1/timeout.rb:44
c:0057 p:0026 s:0323 b:0323 l:000322 d:000322 METHOD /Users/andy/.rvm/rubies/ruby-1.9.2- p180/lib/ruby/1.9.1/timeout.rb:87
c:0056 p:0444 s:0317 b:0317 l:000150 d:000150 METHOD /Users/andy/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:678
c:0055 p:0011 s:0309 b:0309 l:000308 d:000308 METHOD /Users/andy/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:637
c:0054 p:0048 s:0306 b:0306 l:000305 d:000305 METHOD /Users/andy/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:626
c:0053 p:0025 s:0303 b:0303 l:000302 d:000302 METHOD /Users/andy/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:1168
c:0052 p:0499 s:0296 b:0296 l:000295 d:000295 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/faraday-0.5.7/lib/faraday/adapter/net_http.rb:45
c:0051 p:0041 s:0283 b:0283 l:000282 d:000282 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/faraday-0.5.7/lib/faraday/request.rb:85
c:0050 p:0044 s:0276 b:0276 l:000275 d:000275 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/faraday-0.5.7/lib/faraday/request.rb:27
c:0049 p:0065 s:0270 b:0270 l:000269 d:000269 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/faraday-0.5.7/lib/faraday/connection.rb:177
c:0048 p:0069 s:0263 b:0263 l:000262 d:000262 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oauth2-0.1.1/lib/oauth2/client.rb:63
c:0047 p:0039 s:0254 b:0254 l:000253 d:000253 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oauth2-0.1.1/lib/oauth2/strategy/web_server.rb:15
c:0046 p:0070 s:0244 b:0244 l:000243 d:000243 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oa-oauth-0.2.0/lib/omniauth/strategies/oauth2.rb:87
c:0045 p:0042 s:0240 b:0240 l:000239 d:000239 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oa-oauth-0.2.0/lib/omniauth/strategies/facebook.rb:31
c:0044 p:0146 s:0237 b:0237 l:000236 d:000236 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oa-oauth-0.2.0/lib/omniauth/strategies/oauth2.rb:66
c:0043 p:0411 s:0233 b:0233 l:000232 d:000232 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oa-core-0.2.0/lib/omniauth/strategy.rb:49
c:0042 p:0019 s:0228 b:0228 l:000227 d:000227 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oa-core-0.2.0/lib/omniauth/strategy.rb:22
c:0041 p:0044 s:0224 b:0224 l:000223 d:000223 METHOD /Users/andy/.rvm/gems/ruby-1.9.2- p180@rails3tutorial/gems/oa-core-0.2.0/lib/omniauth/builder.rb:30
c:0040 p:0014 s:0220 b:0220 l:000211 d:000219 BLOCK /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/warden-1.0.4/lib/warden/manager.rb:35
c:0039 p:---- s:0218 b:0218 l:000217 d:000217 FINISH
c:0038 p:---- s:0216 b:0216 l:000215 d:000215 CFUNC :catch
[.......snipped]
Abort trap
我的 OmniAuth 设置是:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, 'MY_APP_ID', 'MY_SECRET',
{ :scope => 'email, offline_access',
:client_options => { :ssl => { :ca_file => '/usr/lib/ssl/certs/ca-certificates.crt' } } }
end
尝试使用和不使用 ssl 客户端选项,结果是相同的。
无论如何,其他人也遇到过这个问题,但我找不到任何地方发布的解决方案。参见示例: https://github.com/plataformatec/devise/issues/1069
I'm following the code here:
http://railscasts.com/episodes/241-simple-omniauth?autoplay=true
I'm on ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
and Rails 3.0.7
Basically, I have my own user model (no Devise/AuthLogic). I created a SessionsController to handle the Facebook callback:
match "/auth/facebook/callback" => "sessions#create"
def create
auth = request.env["omniauth.auth"]
user = User.find_by_email(auth["user_info"]["email"]) || User.create_with_omniauth(auth)
session[:user_id] = user.id
redirect_to root_url
end
Finally, my User model:
class User < ActiveRecord::Base
has_one :facebook
validates :email, :presence => true, :uniqueness => true
validates :facebook, :presence => true
def self.create_with_omniauth(auth)
create! do |user|
user.email = auth["user_info"]["email"]
user.facebook = Facebook.create!(:uid => auth["uid"])
end
end
class Facebook < ActiveRecord::Base
belongs_to :user
validates :uid, :presence => true, :uniqueness => true
end
When I run this on localhost and grant the app access, it hits my dev server and kills it. This is the stack trace (consistently reproducible):
-- control frame ----------
c:0060 p:---- s:0340 b:0340 l:000339 d:000339 CFUNC :connect
c:0059 p:0011 s:0337 b:0337 l:000150 d:000336 BLOCK /Users/andy/.rvm/rubies/ruby-1.9.2 -p180/lib/ruby/1.9.1/net/http.rb:678
c:0058 p:0031 s:0335 b:0335 l:000334 d:000334 METHOD /Users/andy/.rvm/rubies/ruby-1.9.2- p180/lib/ruby/1.9.1/timeout.rb:44
c:0057 p:0026 s:0323 b:0323 l:000322 d:000322 METHOD /Users/andy/.rvm/rubies/ruby-1.9.2- p180/lib/ruby/1.9.1/timeout.rb:87
c:0056 p:0444 s:0317 b:0317 l:000150 d:000150 METHOD /Users/andy/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:678
c:0055 p:0011 s:0309 b:0309 l:000308 d:000308 METHOD /Users/andy/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:637
c:0054 p:0048 s:0306 b:0306 l:000305 d:000305 METHOD /Users/andy/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:626
c:0053 p:0025 s:0303 b:0303 l:000302 d:000302 METHOD /Users/andy/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:1168
c:0052 p:0499 s:0296 b:0296 l:000295 d:000295 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/faraday-0.5.7/lib/faraday/adapter/net_http.rb:45
c:0051 p:0041 s:0283 b:0283 l:000282 d:000282 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/faraday-0.5.7/lib/faraday/request.rb:85
c:0050 p:0044 s:0276 b:0276 l:000275 d:000275 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/faraday-0.5.7/lib/faraday/request.rb:27
c:0049 p:0065 s:0270 b:0270 l:000269 d:000269 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/faraday-0.5.7/lib/faraday/connection.rb:177
c:0048 p:0069 s:0263 b:0263 l:000262 d:000262 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oauth2-0.1.1/lib/oauth2/client.rb:63
c:0047 p:0039 s:0254 b:0254 l:000253 d:000253 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oauth2-0.1.1/lib/oauth2/strategy/web_server.rb:15
c:0046 p:0070 s:0244 b:0244 l:000243 d:000243 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oa-oauth-0.2.0/lib/omniauth/strategies/oauth2.rb:87
c:0045 p:0042 s:0240 b:0240 l:000239 d:000239 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oa-oauth-0.2.0/lib/omniauth/strategies/facebook.rb:31
c:0044 p:0146 s:0237 b:0237 l:000236 d:000236 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oa-oauth-0.2.0/lib/omniauth/strategies/oauth2.rb:66
c:0043 p:0411 s:0233 b:0233 l:000232 d:000232 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oa-core-0.2.0/lib/omniauth/strategy.rb:49
c:0042 p:0019 s:0228 b:0228 l:000227 d:000227 METHOD /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/oa-core-0.2.0/lib/omniauth/strategy.rb:22
c:0041 p:0044 s:0224 b:0224 l:000223 d:000223 METHOD /Users/andy/.rvm/gems/ruby-1.9.2- p180@rails3tutorial/gems/oa-core-0.2.0/lib/omniauth/builder.rb:30
c:0040 p:0014 s:0220 b:0220 l:000211 d:000219 BLOCK /Users/andy/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/warden-1.0.4/lib/warden/manager.rb:35
c:0039 p:---- s:0218 b:0218 l:000217 d:000217 FINISH
c:0038 p:---- s:0216 b:0216 l:000215 d:000215 CFUNC :catch
[.......snipped]
Abort trap
My OmniAuth setup is:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, 'MY_APP_ID', 'MY_SECRET',
{ :scope => 'email, offline_access',
:client_options => { :ssl => { :ca_file => '/usr/lib/ssl/certs/ca-certificates.crt' } } }
end
Tried both with and without the ssl client option and the result is the same.
For what it's worth, others have run into this too, but I can't find a solution posted anywhere. See for example:
https://github.com/plataformatec/devise/issues/1069
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过几个令人沮丧的小时后,我在这里找到了解决方案:
http://redmine.ruby-lang.org/issues/4875
基本上,Postgres gem 最终使用了不同版本的 OpenSSL。我仍然不完全清楚所有这些工作原理的细节,但摆脱困境的方法是:
即使使用周围阅读的 MySQL gem,也会发生这种情况。
最后,我和许多其他开发人员一样使用 Mac OSX (Snow Leopard)。
After several frustrating hours, I found the solution here:
http://redmine.ruby-lang.org/issues/4875
Basically, the Postgres gem ended up using a different version of OpenSSL. The details of how all that works under the hood are still not totally clear to me, but the way to get unstuck is:
This can happen even with the MySQL gem from reading around.
Finally, I'm on Mac OSX (Snow Leopard) like a lot of other developers.
我的解决方案比其他一些帖子要简单一些。
我无需卸载并重新安装
openssl
或postgresql
。我通过 macports 安装了这两个项目,它们在原处运行良好。
问题是 ruby 构建过程在出现时有点不同步
寻找
openssl
。openssl
扩展与macports openssl 版本 (1.0.0)
链接,摘要扩展(即 md5、sha1 等)与链接>系统openssl版本(0.9.8)
。我重新下载了 ruby-1.9.3-p0 并使用以下选项重新编译:--prefix
参数当然应该指向您通常安装 ruby 的位置。这导致所有内容都能正确链接并使用相同版本的 openssl 。
仅在现有安装上进行安装是行不通的,然后将其彻底清除并重新安装。然后返回您的应用并
捆绑安装
。My solution to this was a bit simpler than some of the other posts.
I did not have to uninstall and reinstall
openssl
orpostgresql
.I have those two items installed via macports, and they are working fine where they are.
The problem turns out being that the ruby build process is a bit out of sync when it comes
to looking for
openssl
. Theopenssl
extension was being linked against themacports openssl version (1.0.0)
and the digest extensions (i.e. md5, sha1, et al) were being linked against thesystem openssl version (0.9.8)
. I re-downloadedruby-1.9.3-p0
and recompiled with the following option:The
--prefix
argument should of course point to wherever you would normally install ruby.This caused everything to link properly and with the same versions of
openssl
.Just installing over your existing installation doesn't work out, then completely blow it away and reinstall it. Then go back to your app and
bundle install
.