Module: CASino::ProcessorConcern::Authentication

Included in:
API::LoginCredentialAcceptorProcessor, LoginCredentialAcceptorProcessor
Defined in:
app/processors/casino/processor_concern/authentication.rb

Instance Method Summary collapse

Instance Method Details

#authenticatorsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/processors/casino/processor_concern/authentication.rb', line 22

def authenticators
  @authenticators ||= begin
    CASino.config.authenticators.each do |name, auth|
      next unless auth.is_a?(Hash)

      authenticator = if auth[:class]
        auth[:class].constantize
      else
        load_authenticator(auth[:authenticator])
      end

      CASino.config.authenticators[name] = authenticator.new(auth[:options])
    end
  end
end

#validate_login_credentials(username, password) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/processors/casino/processor_concern/authentication.rb', line 5

def (username, password)
  authentication_result = nil
  authenticators.each do |authenticator_name, authenticator|
    begin
      data = authenticator.validate(username, password)
    rescue CASino::Authenticator::AuthenticatorError => e
      Rails.logger.error "Authenticator '#{authenticator_name}' (#{authenticator.class}) raised an error: #{e}"
    end
    if data
      authentication_result = { authenticator: authenticator_name, user_data: data }
      Rails.logger.info("Credentials for username '#{data[:username]}' successfully validated using authenticator '#{authenticator_name}' (#{authenticator.class})")
      break
    end
  end
  authentication_result
end