Class: OmniAuth::Strategies::Polaris
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::Polaris
show all
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/polaris.rb
Defined Under Namespace
Classes: MissingCredentialsError
Constant Summary
collapse
- @@config =
{
'barcode' => 'barcode',
'valid_patron' => 'ValidPatron',
'patron_id' => 'PatronID',
'assigned_branch_id' => 'AssignedBranchID',
'assigned_branch_name' => 'AssignedBranchName',
'first_name' => 'NameFirst',
'last_name' => 'NameLast',
'middle_name' => 'NameMiddle',
'phone_number' => 'PhoneNumber',
'email' => 'EmailAddress'
}
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.map_user(mapper, object) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/omniauth/strategies/polaris.rb', line 84
def self.map_user(mapper, object)
user = {}
mapper.each do |key, value|
case value.class.to_s
when String
user[key.to_sym] = object[value.to_sym] if object[value.to_sym]
when Array
value.each {|v| (user[key] = object[v.downcase.to_sym]; break;) if object[v.downcase.to_sym]}
when Hash
value.map do |key1, value1|
pattern = key1.dup
value1.each_with_index do |v,i|
part = ''; v.collect(&:downcase).collect(&:to_sym).each {|v1| (part = object[v1]; break;) if object[v1]}
pattern.gsub!("%#{i}", part || '')
end
user[key] = pattern
end
end
end
user
end
|
Instance Method Details
#callback_phase ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/omniauth/strategies/polaris.rb', line 32
def callback_phase
@adaptor = OmniAuth::Polaris::Adaptor.new @options
raise MissingCredentialsError.new("Missing login credentials") if request['barcode'].nil? || request['pin'].nil?
begin
@polaris_user_info = @adaptor.bind_as(:barcode => request['barcode'], :pin => request['pin'])
return fail!(:invalid_credentials) if !@polaris_user_info
@user_info = self.class.map_user(@@config, @polaris_user_info)
super
rescue Exception => e
return fail!(:polaris_error, e)
end
end
|
#request_phase ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/omniauth/strategies/polaris.rb', line 23
def request_phase
OmniAuth::Polaris::Adaptor.validate @options
f = OmniAuth::Form.new(:title => (options[:title] || "Polaris Authentication"), :url => callback_path)
f.text_field 'Barcode', 'barcode'
f.password_field 'PIN', 'pin'
f.button "Sign In"
f.to_response
end
|