Class: OmniAuth::Strategies::Polaris

Inherits:
Object
  • Object
show all
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

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()
  USER_MAP.each_with_object({}) do |(user_key, polaris_user_key), user_hash|
    user_hash[user_key.to_sym] = [polaris_user_key] if [polaris_user_key].present?
  end
end

Instance Method Details

#callback_phaseObject

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(@options)

  fail(MissingCredentialsError, 'Missing login credentials') if %w[barcode pin].any? { |request_key| request.params[request_key].blank? }

   = @adaptor.authenticate_patron(pin: request.params['pin'], barcode: request.params['barcode'])

  fail(InvalidCredentialsError, 'Invalid User Credentials!') if .blank?

  @user_info = self.class.map_user()

  super
rescue MissingCredentialsError => e
  fail!(:missing_credentials, e)
rescue InvalidCredentialsError => e
  fail!(:invalid_credentials, e)
rescue StandardError => e
  fail!(:polaris_error, e)
end

#request_phaseObject



32
33
34
35
36
37
38
39
40
# File 'lib/omniauth/strategies/polaris.rb', line 32

def request_phase
  OmniAuth::Polaris::Adaptor.validate!(@options)

  OmniAuth::Form.build(title: options.fetch(:title, 'Polaris Authentication'), url: callback_path) do |f|
    f.text_field 'Barcode', 'barcode'
    f.password_field 'PIN', 'pin'
    f.button 'Sign In'
  end.to_response
end