Module: EasyAuth
- Defined in:
- lib/easy_auth.rb,
lib/easy_auth/version.rb
Constant Summary collapse
- VERSION =
"0.0.5"
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate_token ⇒ Object (also: #easy_authenticate!)
- #authenticated? ⇒ Boolean
- #authentication_token ⇒ Object
- #reject_request ⇒ Object
- #request_auth_token ⇒ Object
Class Method Details
.authenticated_request?(request) ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/easy_auth.rb', line 26 def self.authenticated_request? request # this is used as a convenience method to be able to use this in a routes.rb file. [ request.headers.env['HTTP_X_API_TOKEN'], request.env['HTTP_X_API_TOKEN'], request.params[:api_token] ].include? ENV.fetch('API_TOKEN') { 'DEV_TOKEN' } end |
Instance Method Details
#authenticate_token ⇒ Object Also known as: easy_authenticate!
5 6 7 |
# File 'lib/easy_auth.rb', line 5 def authenticate_token reject_request unless authenticated? end |
#authenticated? ⇒ Boolean
14 15 16 |
# File 'lib/easy_auth.rb', line 14 def authenticated? request_auth_token == authentication_token end |
#authentication_token ⇒ Object
22 23 24 |
# File 'lib/easy_auth.rb', line 22 def authentication_token ENV.fetch('API_TOKEN') { 'DEV_TOKEN' } end |
#reject_request ⇒ Object
10 11 12 |
# File 'lib/easy_auth.rb', line 10 def reject_request render(:text => 'bad api token', :status => :unauthorized) and return end |
#request_auth_token ⇒ Object
18 19 20 |
# File 'lib/easy_auth.rb', line 18 def request_auth_token request.headers.env['HTTP_X_API_TOKEN'] || request.env['HTTP_X_API_TOKEN'] || params[:api_token] end |