Module: ApiAuthenticator
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/api_authenticator.rb,
lib/api_authenticator/errors.rb,
lib/api_authenticator/version.rb,
lib/api_authenticator/configuration.rb,
lib/api_authenticator/api_authenticator.rb,
lib/api_authenticator/authenticated_request.rb
Defined Under Namespace
Classes: BaseError, InvalidTimeError, InvalidTokenError
Constant Summary
collapse
- VERSION =
"0.2.1"
- @@logger =
nil
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.authenticated_request?(request) ⇒ Boolean
authenticated_request?
Returns: True or False
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/api_authenticator/authenticated_request.rb', line 8
def self.authenticated_request?(request)
time = nil
token = request.['API-Token']
begin
time = DateTime.parse(request.['API-Time'])
rescue ArgumentError, TypeError
end
valid_api_time?(time)
valid_api_token?(request.original_url, time, token)
end
|
4
5
6
|
# File 'lib/api_authenticator/configuration.rb', line 4
def self.configure
yield self
end
|
.logger ⇒ Object
32
33
34
|
# File 'lib/api_authenticator/configuration.rb', line 32
def self.logger
@@logger || Logger.new($stdout)
end
|
.logger=(logger) ⇒ Object
28
29
30
|
# File 'lib/api_authenticator/configuration.rb', line 28
def self.logger=(logger)
@@logger = logger || Logger.new($stdout)
end
|
.report_unauthenticated_requests=(report) ⇒ Object
24
25
26
|
# File 'lib/api_authenticator/configuration.rb', line 24
def self.report_unauthenticated_requests=(report)
@@report_unauthenticated_requests = report || false
end
|
.shared_secret_keys ⇒ Object
12
13
14
|
# File 'lib/api_authenticator/configuration.rb', line 12
def self.shared_secret_keys
@@shared_secret_keys
end
|
.shared_secret_keys=(shared_secret_keys) ⇒ Object
8
9
10
|
# File 'lib/api_authenticator/configuration.rb', line 8
def self.shared_secret_keys=(shared_secret_keys)
@@shared_secret_keys = shared_secret_keys
end
|
.time_threshold ⇒ Object
20
21
22
|
# File 'lib/api_authenticator/configuration.rb', line 20
def self.time_threshold
@@time_threshold
end
|
.time_threshold=(time_threshold) ⇒ Object
16
17
18
|
# File 'lib/api_authenticator/configuration.rb', line 16
def self.time_threshold=(time_threshold)
@@time_threshold = time_threshold
end
|
Instance Method Details
#api_authenticator ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/api_authenticator/api_authenticator.rb', line 9
def api_authenticator
begin
ApiAuthenticator.authenticated_request?(request)
rescue BaseError => e
report_unauthenticated_requests(e)
render( status: 401, nothing: true ) and return false
end
end
|