Class: OmniAuth::Strategies::Polaris
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::Polaris
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/polaris.rb
Defined Under Namespace
Classes: InvalidCredentialsError, MissingCredentialsError
Constant Summary collapse
- USER_MAP =
{ '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' }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#callback_phase ⇒ Object
rubocop:disable Style/SignalException.
- #request_phase ⇒ Object
Class Method Details
.map_user(polaris_user_info) ⇒ Object
24 25 26 27 28 |
# File 'lib/omniauth/strategies/polaris.rb', line 24 def self.map_user(polaris_user_info) USER_MAP.each_with_object({}) do |(user_key, polaris_user_key), user_hash| user_hash[user_key.to_sym] = polaris_user_info[polaris_user_key] if polaris_user_info[polaris_user_key].present? end end |
Instance Method Details
#callback_phase ⇒ Object
rubocop:disable Style/SignalException
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/omniauth/strategies/polaris.rb', line 43 def callback_phase @adaptor = OmniAuth::Polaris::Adaptor.new() fail(MissingCredentialsError, 'Missing login credentials') if %w[barcode pin].any? { |request_key| request.params[request_key].blank? } @polaris_user_info = @adaptor.authenticate_patron(pin: request.params['pin'], barcode: request.params['barcode']) fail(InvalidCredentialsError, 'Invalid User Credentials!') if @polaris_user_info.blank? @user_info = self.class.map_user(@polaris_user_info) super rescue MissingCredentialsError => e fail!(:missing_credentials, e) rescue InvalidCredentialsError => e fail!(:invalid_credentials, e) rescue StandardError => e fail!(:polaris_error, e) end |
#request_phase ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/omniauth/strategies/polaris.rb', line 32 def request_phase OmniAuth::Polaris::Adaptor.validate!() OmniAuth::Form.build(title: .fetch(:title, 'Polaris Authentication'), url: callback_path) do |f| f.text_field 'Barcode', 'barcode' f.password_field 'PIN', 'pin' f. 'Sign In' end.to_response end |