Class: EY::ApiHMAC::ApiAuth::Client
- Inherits:
-
Object
- Object
- EY::ApiHMAC::ApiAuth::Client
- Defined in:
- lib/ey_api_hmac/api_auth.rb
Overview
Client middleware that’s used to add authentication to requests.
Defined Under Namespace
Classes: AuthFailure
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, auth_id, auth_key, quiet = false) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(app, auth_id, auth_key, quiet = false) ⇒ Client
Returns a new instance of Client.
60 61 62 |
# File 'lib/ey_api_hmac/api_auth.rb', line 60 def initialize(app, auth_id, auth_key, quiet=false) @app, @auth_id, @auth_key, @quiet = app, auth_id, auth_key, quiet end |
Instance Method Details
#call(env) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ey_api_hmac/api_auth.rb', line 63 def call(env) env['HTTP_DATE'] ||= Time.now.httpdate ApiHMAC.sign!(env, @auth_id, @auth_key) tuple = @app.call(env) if !@quiet && tuple.first.to_i == 401 response_body = "" tuple.last.each{ |v| response_body << v } raise AuthFailure, "HMAC Authentication Failed: #{response_body}" end tuple end |