Module: Escher::RackMiddleware::Authenticator::Helper

Defined in:
lib/escher/rack_middleware/authenticator/helper.rb

Instance Method Summary collapse

Instance Method Details

#authorized?(request_env) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
# File 'lib/escher/rack_middleware/authenticator/helper.rb', line 7

def authorized?(request_env)
  logger.warn('No Escher authenticator was found. Check your config!') if escher_authenticators.empty?
  escher_authenticators.any? { |instance_init| authorized_with?(instance_init.call, request_env) }
end

#authorized_with?(escher_authenticator, request_env) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/escher/rack_middleware/authenticator/helper.rb', line 12

def authorized_with?(escher_authenticator, request_env)

  request_env['escher.request.api_key_id'] = escher_authenticator.authenticate(
      Rack::Request.new(request_env), credentials)

  request_env.delete('escher.error') rescue nil
  logger.debug(log_message(request_env))

  true

rescue Escher::EscherError => ex

  request_env['escher.error'] = ex.message || ex.inspect
  logger.warn(log_message(request_env))

  false

rescue => ex
  # escher fails, bad implementations
  logger.warn(ex)

  false
end

#escher_authenticatorsObject



3
4
5
# File 'lib/escher/rack_middleware/authenticator/helper.rb', line 3

def escher_authenticators
  self.class.escher_authenticators
end