Class: EY::ApiHMAC::ApiAuth::Client

Inherits:
Object
  • Object
show all
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)

Constructor Details

- (Client) initialize(app, auth_id, auth_key)

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)
  @app, @auth_id, @auth_key = app, auth_id, auth_key
end

Instance Method Details

- (Object) call(env)



63
64
65
66
67
68
69
70
71
72
# File 'lib/ey_api_hmac/api_auth.rb', line 63

def call(env)
  ApiHMAC.sign!(env, @auth_id, @auth_key)
  tuple = @app.call(env)
  if tuple.first.to_i == 401
    response_body = ""
    tuple.last.each{ |v| response_body << v }
    raise AuthFailure, "HMAC Authentication Failed: #{response_body}"
  end
  tuple
end