1

我在 Ubuntu 映像上的 sinatra 上运行以下 ruby​​ openId 示例。

    %w(rubygems sinatra openid openid/store/filesystem).each { |lib| require lib}

REALM = 'http://localhost:4567'
RETURN_TO = "#{REALM}/complete"

get '/loginform' do
  erb :loginform
end


post '/login' do
  checkid_request = openid_consumer.begin(params[:openid_identifier])
  redirect checkid_request.redirect_url(REALM, RETURN_TO) if checkid_request.send_redirect?(REALM, RETURN_TO)
  checkid_request.html_markup(REALM, RETURN_TO)
end

get '/complete' do
  response = openid_consumer.complete(params, RETURN_TO)
  return 'You are logged in!' if response.status == OpenID::Consumer::SUCCESS
   msg=response.message
   <<-eos
    Could not log on with your OpenID due to #{msg}
    eos
end

def openid_consumer
  @consumer = OpenID::Consumer.new(session, OpenID::Store::Filesystem.new("#{File.dirname(__FILE__)}/.tmp/openid")) if @consumer.nil?
  return @consumer
end


enable :inline_templates

__END__

@@ layout
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <title>got openid?</title>
</head>
<body>
  <%= yield %>
</body>
</html>


@@ loginform
<form method="post" accept-charset="UTF-8" action='/login'>
  Identifier:
  <input type="text" class="openid" name="openid_identifier" />
  <input type="submit" value="Verify" />
</form>

输入谷歌网址(https://www.google.com/accounts/o8/id)时,我被重定向到谷歌,输入我的凭据,但我没有被授予访问权限:

Nonce 已使用或超出范围:“2012-05-09T13:50:xxxxxxxxxxxxxxx”

(顺便说一句,我正在使用“ruby”而不是“shotgun”执行 ruby​​ 程序)。有人可以为我提供一些关于输出的含义以及补救措施的见解吗?谢谢!

4

1 回答 1

1

解决了!问题源于商店特权。我认为这主要是一个Ubuntu问题。

我改变了这个:

@consumer = OpenID::Consumer.new(session, OpenID::Store::Filesystem.new("#{File.dirname(__FILE__)}/.tmp/openid")) if @consumer.nil?

进入这个(无状态):

@consumer = OpenID::Consumer.new(session, nil) if @consumer.nil?

它奏效了!

于 2012-05-10T08:00:42.080 回答