2011-01-14 98 views
0

我正在将应用程序从Rails 2迁移到Rails 3. 该应用程序使用Open ID登录Google,而我正在使用open_id_authentication插件。Rails 3上的open_id_authentication 3

的代码看起来是这样的:

options = { 
    :identifier => 'https://www.google.com/accounts/o8/id', 
    :required => [ 'http://axschema.org/contact/email', 
       'http://axschema.org/namePerson/first', 
       'http://axschema.org/namePerson/last' ], 
    :oauth => { 
    :consumer => OAUTH_CONSUMER_TOKEN, 
    :scope => "http://www.google.com/m8/feeds/" 
    } 
} 
authenticate_with_open_id('https://www.google.com/accounts/o8/id', options) 
    do |result, identity_url, registration, extended_attributes| 

    email = registration["http://axschema.org/contact/email"] 

end 

这是on Rails的2工作正常,但是当我更新到Rails 3,并更新了开放ID插件(由于兼容性原因),当我尝试获得的电子邮件属性我得到以下错误:

引发ArgumentError在SessionsController#创建 http://schema.openid.net/contact/email不是一个定义简单的注册场

ruby-openid (2.1.8) lib/openid/extensions/sreg.rb:32:in `check_sreg_field_name' 
ruby-openid (2.1.8) lib/openid/extensions/sreg.rb:266:in `[]' 
app/controllers/sessions_controller.rb:33:in `open_id_authentication' 
vendor/plugins/open_id_authentication/lib/open_id_authentication.rb:114:in `complete_open_id_authentication' 
vendor/plugins/open_id_authentication/lib/open_id_authentication.rb:90:in `authenticate_with_open_id' 

这个错误是什么意思,我该如何解决?我知道沟通工作正常,因为我得到谷歌的网页,并要求我的密码,但我不明白为什么电子邮件属性停止通过更新到Rails 3时通过。

+0

可能重复http://stackoverflow.com/questions/2492043/ruby-open-id-authentication-与谷歌openid) – pgb 2011-01-14 20:23:58

回答

0

找到了答案here。如何获取电子邮件AX属性的代码如下:

options = { 
    :identifier => 'https://www.google.com/accounts/o8/id', 
    :required => [ 'http://axschema.org/contact/email', 
       'http://axschema.org/namePerson/first', 
       'http://axschema.org/namePerson/last' ], 
    :oauth => { 
    :consumer => OAUTH_CONSUMER_TOKEN, 
    :scope => "http://www.google.com/m8/feeds/" 
    } 
} 
authenticate_with_open_id('https://www.google.com/accounts/o8/id', options) 
    do |result, identity_url, registration, extended_attributes| 

    ax_response = OpenID::AX::FetchResponse.from_success_response(request.env[Rack::OpenID::RESPONSE]) 

    email = ax_response['http://axschema.org/contact/email'].first 

end 
[与谷歌的OpenID红宝石open_id_authentication(的