Class: BasicApiAuth::Middleware
- Inherits:
-
Object
- Object
- BasicApiAuth::Middleware
- Includes:
- HashkeyGenerator
- Defined in:
- lib/basic_api_auth.rb
Constant Summary collapse
- @@authenticity_error =
[401, {"Content-Type" => "text/plain"}, ['{ "message": "Authentication Failed" }']]
- @@hashkey_requirement_error =
[401, {"Content-Type" => "text/plain"}, ['{ "message": "Hashkey is required for authentication" }']]
Instance Method Summary collapse
- #authenticate_hashkey ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, api_key) ⇒ Middleware
constructor
A new instance of Middleware.
Methods included from HashkeyGenerator
#concat_params, #generate_hashkey_for, #sort_params
Constructor Details
#initialize(app, api_key) ⇒ Middleware
Returns a new instance of Middleware.
11 12 13 14 |
# File 'lib/basic_api_auth.rb', line 11 def initialize(app, api_key) @app = app @api_key = api_key end |
Instance Method Details
#authenticate_hashkey ⇒ Object
24 25 26 |
# File 'lib/basic_api_auth.rb', line 24 def authenticate_hashkey @hashkey == generate_hashkey_for(@params, @api_key) end |
#call(env) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/basic_api_auth.rb', line 16 def call(env) @params = Rack::Request.new(env).params @hashkey = @params.delete('hashkey') return @@hashkey_requirement_error unless @hashkey return @@authenticity_error unless authenticate_hashkey @app.call(env) end |