lib/omniauth/strategies/open_id.rb in oa-openid-0.1.5 vs lib/omniauth/strategies/open_id.rb in oa-openid-0.1.6

- old
+ new

@@ -23,10 +23,12 @@ :state => 'http://axschema.org/contact/state/home', :website => 'http://axschema.org/contact/web/default', :image => 'http://axschema.org/media/image/aspect11' } + # Initialize the strategy as a Rack Middleware. + # # @param app [Rack Application] Standard Rack middleware application argument. # @param store [OpenID Store] The [OpenID Store](http://github.com/openid/ruby-openid/tree/master/lib/openid/store/) # you wish to use. Defaults to OpenID::MemoryStore. # @option options [Array] :required The identity fields that are required for the OpenID # request. May be an ActiveExchange schema URL or an sreg identifier. @@ -34,11 +36,11 @@ # be ActiveExchange or sreg. # @option options [Symbol, :open_id] :name The URL segment name for this provider. def initialize(app, store = nil, options = {}) super(app, options[:name] || :open_id) @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'] @store = store end protected @@ -46,11 +48,12 @@ def dummy_app lambda{|env| [401, {"WWW-Authenticate" => Rack::OpenID.build_header( :identifier => identifier, :return_to => callback_url, :required => @options[:required], - :optional => @options[:optional] + :optional => @options[:optional], + :method => 'post' )}, []]} end def callback_url uri = URI.parse(request.url) @@ -120,14 +123,16 @@ def ax_user_info(response) ax = ::OpenID::AX::FetchResponse.from_success_response(response) return {} unless ax { - 'email' => ax[AX[:email]], - 'name' => ax[AX[:name]], - 'location' => ("#{ax[AX[:city]]}, #{ax[AX[:state]]}" if Array(ax[AX[:city]]).any? && Array(ax[AX[:state]]).any?), - 'nickname' => ax[AX[:nickname]], - 'urls' => ({'Website' => Array(ax[AX[:website]]).first} if Array(ax[AX[:website]]).any?) + 'email' => ax.get_single(AX[:email]), + 'first_name' => ax.get_single(AX[:first_name]), + 'last_name' => ax.get_single(AX[:last_name]), + 'name' => (ax.get_single(AX[:name]) || [ax.get_single(AX[:first_name]), ax.get_single(AX[:last_name])].join(' ')), + '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 == ''} end end end end