ruby sinatra openid app回复“Nonce已经使用或超出范围”

时间:2012-05-09 14:07:47

标签: ruby openid sinatra google-openid nonce

我正在使用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>

进入google网址时(https://www.google.com/accounts/o8/id) 我被重新引导到谷歌,输入我的凭据,但不是被授予访问权限,我得到:

  

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

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

1 个答案:

答案 0 :(得分:1)

解决! 问题起源于Store privliges。 我认为这主要是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?

它有效!