Class: Healthier::ApiAuthenticator
- Inherits:
-
Object
- Object
- Healthier::ApiAuthenticator
- Defined in:
- lib/healthier/api_authenticator.rb
Overview
Engine
Instance Attribute Summary collapse
-
#controller ⇒ Object
Returns the value of attribute controller.
Instance Method Summary collapse
- #authenticate ⇒ Object
- #authenticate_with_basic_auth ⇒ Object
- #authenticate_with_bearer_token ⇒ Object
-
#initialize(controller) ⇒ ApiAuthenticator
constructor
A new instance of ApiAuthenticator.
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
#controller ⇒ Object
Returns the value of attribute controller.
6 7 8 |
# File 'lib/healthier/api_authenticator.rb', line 6 def controller @controller end |
Instance Method Details
#authenticate ⇒ Object
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_auth ⇒ Object
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_token ⇒ Object
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, | ENV['HEALTHIER_BEARER_TOKEN'] == token end end |