Class: EY::ApiHMAC::ApiAuth::LookupServer

Inherits:
Object
  • Object
show all
Defined in:
lib/ey_api_hmac/api_auth.rb

Overview

Server middleware to validate requests, setup with a block that returns the auth_key given an auth_id

To pass authentication information through to your app, be sure to set something in env. Look at EY::ApiHMAC::ApiAuth::Server for an example

raise EY::ApiHMAC::HmacAuthFail, “your message” to fail authentication.

Direct Known Subclasses

Server

Instance Method Summary collapse

Constructor Details

#initialize(app, &lookup) ⇒ LookupServer

Returns a new instance of LookupServer.



12
13
14
# File 'lib/ey_api_hmac/api_auth.rb', line 12

def initialize(app, &lookup)
  @app, @lookup = app, lookup
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/ey_api_hmac/api_auth.rb', line 16

def call(env)
  begin
    ApiHMAC.authenticate!(env) do |auth_id|
      @lookup.call(env, auth_id)
    end
  rescue HmacAuthFail => e
    return [401, {"Content-Type" => "text/plain"}, ["Authentication failure: #{e.message}"]]
  end
  @app.call(env)
end