我在使用 omniauth/openid 时遇到了一些麻烦。
在尝试进行身份验证时,我在日志中发现了这一点:
OpenID::FetchingError: Error fetching https://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username: undefined method `io' for nil:NilClass
重要的是 undefined method io' for nil:NilClass
来自 openid/fetchers.rb,在下面的代码片段中:
module Net
class HTTP
def post_connection_check(hostname)
check_common_name = true
cert = @socket.io.peer_cert
cert.extensions.each { |ext|
next if ext.oid != "subjectAltName"
ext.value.split(/,\s+/).each{ |general_name|
if /\ADNS:(.*)/ =~ general_name
check_common_name = false
...
该错误由 @socket.io.peer_cert
生成,@socket 未定义。
你们以前遇到过这种情况吗?不太清楚是什么原因。
我正在运行的版本:
- ruby 1.9.3dev(2010-08-17 主干 29020)[x86_64-darwin10.4.0]
- ruby-openid (2.1.8)
- ruby-openid-apps-discovery (1.2.0)
- omniauth 0.2.0
最佳答案
我们遇到了同样的问题,这是 Net::HTTP#connect 从未被调用的直接结果。事实证明,我们将 fakeweb gem 限定在引发错误的环境中(在我们的例子中是开发环境)。
缩小 fakeweb 的范围允许正常处理#connect,@socket 再次高兴。
group :test do
gem 'fakeweb'
end
关于ruby-openid:执行发现时未设置@socket,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5361612/