Class: WP::HMAC::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/wp/hmac/server.rb

Overview

HMAC Server

Authenticate a request using EY::ApiHMAC

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Server

Returns a new instance of Server.



13
14
15
16
# File 'lib/wp/hmac/server.rb', line 13

def initialize(app)
  @app = app
  @hmac_auth = EY::ApiHMAC::ApiAuth::Server.new(app, HMAC::KeyCabinet)
end

Class Attribute Details

.hmac_enabled_routesObject

Returns the value of attribute hmac_enabled_routes.



10
11
12
# File 'lib/wp/hmac/server.rb', line 10

def hmac_enabled_routes
  @hmac_enabled_routes
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/wp/hmac/server.rb', line 18

def call(env)
  if hmac_enabled_route?(env)
    verify_key!
    @hmac_auth.call(env)
  else
    @app.call(env)
  end
end

#id_for_requestObject



31
32
33
# File 'lib/wp/hmac/server.rb', line 31

def id_for_request
  HMAC.auth_id
end

#verify_key!Object



27
28
29
# File 'lib/wp/hmac/server.rb', line 27

def verify_key!
  KeyCabinet.find_by_auth_id(id_for_request)
end