lib/omniauth/strategies/alephx.rb in omniauth-alephx-0.1.31 vs lib/omniauth/strategies/alephx.rb in omniauth-alephx-0.1.32

- old
+ new

@@ -9,55 +9,56 @@ #required option :url # :url => "http://aleph.ugent.be/X" option :library # :library => "rug50" - #only for test purpose (if you do not specify the option :form, a form will be created, using these options) + #only for test purpose (if you do not specify the option :form, a form + #will be created, using these options) option :title_form, "Aleph authentication" option :label_password,:password option :label_username,:username option :label_submit, "submit" - @user_info = {} - class << self - attr_accessor :filters,:on_error + attr_accessor :filters, :on_error def add_filter(&block) - @filters = [] if @filters.nil? + @filters ||= [] @filters << block end end uid { - @user_info[:bor_id] + user_info[:bor_id] } info { - { - :name => @user_info[:name], - :email => @user_info[:email] - } + i = {} + [:name, :email].each do |key| + i[key] = user_info[key] if user_info[key].is_a? String + end + i } credentials { {} } extra { - @user_info + {} } - def request_phase + def user_info + @user_info ||= {} + end + def request_phase form = OmniAuth::Form.new(:title => options[:title_form], :url => callback_path) form.text_field options[:label_username],:username form.password_field options[:label_password],:password form.button options[:label_submit] form.to_response - end def callback_phase - params = request.params rp = script_name + request_path+"?"+{ :username => params['username'] }.to_query if missing_credentials? @@ -66,11 +67,10 @@ return redirect(rp) end begin - unless self.class.filters.nil? self.class.filters.each do |filter| filter.call(params) end end @@ -94,11 +94,10 @@ super end def bor_auth(username,password) - uri = URI.parse(options[:url]+"?"+{ :op => "bor-auth", :bor_id => username, :verification => password, :library => options[:library] @@ -113,18 +112,20 @@ document = XmlSimple.xml_in(res.body,{ 'ForceArray' => false }) return false if document['error'] @user_info = { - #user pwd to communicate with aleph (cannot extract cas username or barcode from alephx!) + # user pwd to communicate with aleph (cannot extract cas username or + # barcode from alephx!) :bor_id => document['z303']['z303-id'], :name => document['z303']['z303-name'], - :email => document['z304']['z304-email-address'] + :email => document['z304']['z304-email-address'], + :doc => document } return true - end + def missing_credentials? request['username'].nil? or request['username'].empty? or request['password'].nil? or request['password'].empty? end end end