Class: EY::ApiHMAC::ApiAuth::LookupServer
- Inherits:
-
Object
- Object
- EY::ApiHMAC::ApiAuth::LookupServer
- 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
Instance Method Summary (collapse)
- - (Object) call(env)
-
- (LookupServer) initialize(app, &lookup)
constructor
A new instance of LookupServer.
Constructor Details
- (LookupServer) initialize(app, &lookup)
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
- (Object) call(env)
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, {}, ["Authentication failure: #{e.}"]] end @app.call(env) end |