Class: Healthier::ApiAuthenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/healthier/api_authenticator.rb

Overview

Engine

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ ApiAuthenticator

Returns a new instance of ApiAuthenticator.



8
9
10
# File 'lib/healthier/api_authenticator.rb', line 8

def initialize(controller)
  @controller = controller
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



6
7
8
# File 'lib/healthier/api_authenticator.rb', line 6

def controller
  @controller
end

Instance Method Details

#authenticateObject



12
13
14
15
16
# File 'lib/healthier/api_authenticator.rb', line 12

def authenticate
  return true if Healthier.auth_mechanism == :none

  send("authenticate_with_#{Healthier.auth_mechanism}")
end

#authenticate_with_basic_authObject



24
25
26
27
28
# File 'lib/healthier/api_authenticator.rb', line 24

def authenticate_with_basic_auth
  controller.authenticate_or_request_with_http_basic do |username, password|
    username == ENV['HEALTHIER_USERNAME'] && password == ENV['HEALTHIER_PASSWORD']
  end
end

#authenticate_with_bearer_tokenObject



18
19
20
21
22
# File 'lib/healthier/api_authenticator.rb', line 18

def authenticate_with_bearer_token
  controller.authenticate_with_http_token do |token, _options|
    ENV['HEALTHIER_BEARER_TOKEN'] == token
  end
end