At last, Attribute Exchange for OpenID worked out to properly provide names from Google.

This commit is contained in:
Michael Bleigh 2010-10-19 12:46:42 -05:00
Родитель cc1112f5fc
Коммит bbc6580da2
2 изменённых файлов: 11 добавлений и 8 удалений

Просмотреть файл

@ -36,7 +36,7 @@ module OmniAuth
def initialize(app, store = nil, options = {}) def initialize(app, store = nil, options = {})
super(app, options[:name] || :open_id) super(app, options[:name] || :open_id)
@options = options @options = options
@options[:required] ||= [AX[:email], AX[:first_name], AX[:last_name], 'email', 'fullname'] @options[:required] ||= [AX[:email], AX[:name], AX[:first_name], AX[:last_name], 'email', 'fullname']
@options[:optional] ||= [AX[:nickname], AX[:city], AX[:state], AX[:website], AX[:image], 'postcode', 'nickname'] @options[:optional] ||= [AX[:nickname], AX[:city], AX[:state], AX[:website], AX[:image], 'postcode', 'nickname']
@store = store @store = store
end end
@ -48,7 +48,8 @@ module OmniAuth
:identifier => identifier, :identifier => identifier,
:return_to => callback_url, :return_to => callback_url,
:required => @options[:required], :required => @options[:required],
:optional => @options[:optional] :optional => @options[:optional],
:method => 'post'
)}, []]} )}, []]}
end end
@ -122,11 +123,13 @@ module OmniAuth
ax = ::OpenID::AX::FetchResponse.from_success_response(response) ax = ::OpenID::AX::FetchResponse.from_success_response(response)
return {} unless ax return {} unless ax
{ {
'email' => ax[AX[:email]], 'email' => ax.get_single(AX[:email]),
'name' => ax[AX[:name]], 'first_name' => ax.get_single(AX[:first_name]),
'location' => ("#{ax[AX[:city]]}, #{ax[AX[:state]]}" if Array(ax[AX[:city]]).any? && Array(ax[AX[:state]]).any?), 'last_name' => ax.get_single(AX[:last_name]),
'nickname' => ax[AX[:nickname]], 'name' => (ax.get_single(AX[:name]) || [ax.get_single(AX[:first_name]), ax.get_single(AX[:last_name])].join(' ')),
'urls' => ({'Website' => Array(ax[AX[:website]]).first} if Array(ax[AX[:website]]).any?) 'location' => ("#{ax.get_single(AX[:city])}, #{ax.get_single(AX[:state])}" if Array(ax.get_single(AX[:city])).any? && Array(ax.get_single(AX[:state])).any?),
'nickname' => ax.get_single(AX[:nickname]),
'urls' => ({'Website' => Array(ax.get_single(AX[:website])).first} if Array(ax.get_single(AX[:website])).any?)
}.inject({}){|h,(k,v)| h[k] = Array(v).first; h}.reject{|k,v| v.nil? || v == ''} }.inject({}){|h,(k,v)| h[k] = Array(v).first; h}.reject{|k,v| v.nil? || v == ''}
end end
end end

Просмотреть файл

@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
gem.files = Dir.glob("{lib}/**/*") + %w(LICENSE.rdoc CHANGELOG.rdoc) gem.files = Dir.glob("{lib}/**/*") + %w(LICENSE.rdoc CHANGELOG.rdoc)
gem.add_dependency 'oa-core', version gem.add_dependency 'oa-core', version
gem.add_dependency 'rack-openid', '~> 1.1.1' gem.add_dependency 'rack-openid', '~> 1.2.0'
gem.add_dependency 'ruby-openid-apps-discovery' gem.add_dependency 'ruby-openid-apps-discovery'
eval File.read(File.join(File.dirname(__FILE__), '../development_dependencies.rb')) eval File.read(File.join(File.dirname(__FILE__), '../development_dependencies.rb'))