lib/omniauth/strategies/alephx.rb in omniauth-alephx-0.1.3 vs lib/omniauth/strategies/alephx.rb in omniauth-alephx-0.1.31
- old
+ new
@@ -8,33 +8,33 @@
include OmniAuth::Strategy
#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)
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
-
+
def add_filter(&block)
@filters = [] if @filters.nil?
@filters << block
end
end
uid {
@user_info[:bor_id]
}
info {
- {
+ {
:name => @user_info[:name],
:email => @user_info[:email]
}
}
credentials {
@@ -43,24 +43,24 @@
extra {
@user_info
}
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
+ def callback_phase
params = request.params
- rp = request_path+"?"+{ :username => params['username'] }.to_query
+ rp = script_name + request_path+"?"+{ :username => params['username'] }.to_query
if missing_credentials?
session['omniauth.alephx.error'] = :missing_credentials
self.class.on_error.call(:missing_credentials) unless self.class.on_error.nil?
return redirect(rp)
@@ -74,13 +74,13 @@
filter.call(params)
end
end
username = params['username']
- password = params['password']
-
- unless bor_auth(username,password)
+ password = params['password']
+
+ unless bor_auth(username,password)
session['omniauth.alephx.error'] = :invalid_credentials
self.class.on_error.call(:invalid_credentials) unless self.class.on_error.nil?
return redirect(rp)
end
@@ -94,11 +94,11 @@
super
end
def bor_auth(username,password)
-
+
uri = URI.parse(options[:url]+"?"+{
:op => "bor-auth",
:bor_id => username,
:verification => password,
:library => options[:library]
@@ -109,22 +109,22 @@
http.use_ssl = true
end
res = http.request(Net::HTTP::Get.new(uri.request_uri))
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!)
:bor_id => document['z303']['z303-id'],
:name => document['z303']['z303-name'],
:email => document['z304']['z304-email-address']
- }
+ }
return true
- end
+ end
def missing_credentials?
request['username'].nil? or request['username'].empty? or request['password'].nil? or request['password'].empty?
end
end
end