Class: EY::GateKeeper::Client::Middleware::ServiceTokenAuthentication

Inherits:
Object
  • Object
show all
Defined in:
lib/ey_gatekeeper/client/middlewares/service_token_authentication.rb

Overview

This middleware is for use by service clients.

Given the service client’s app to run along with a gatekeeper endpoint, key, and secret it will contact the gatekeeper and retrieve a token. The token will then be passed as part of the request in the ‘Auth-Token` header.

Instance Method Summary collapse

Constructor Details

#initialize(app, gatekeeper_endpoint, xdna_key, xdna_secret) ⇒ ServiceTokenAuthentication

Returns a new instance of ServiceTokenAuthentication.



17
18
19
20
# File 'lib/ey_gatekeeper/client/middlewares/service_token_authentication.rb', line 17

def initialize(app, gatekeeper_endpoint, xdna_key, xdna_secret)
  @app, @gatekeeper_endpoint, @xdna_key, @xdna_secret =
    app, gatekeeper_endpoint, xdna_key, xdna_secret
end

Instance Method Details

#call(env) ⇒ Object



22
23
24
25
# File 'lib/ey_gatekeeper/client/middlewares/service_token_authentication.rb', line 22

def call(env)
  env.merge!('HTTP_AUTH_TOKEN' => current_token.token)
  @app.call(env)
end

#current_tokenObject



31
32
33
# File 'lib/ey_gatekeeper/client/middlewares/service_token_authentication.rb', line 31

def current_token
  gatekeeper_client.token
end

#gatekeeper_clientObject



27
28
29
# File 'lib/ey_gatekeeper/client/middlewares/service_token_authentication.rb', line 27

def gatekeeper_client
  @gatekeeper_client ||= EY::GateKeeper.new(@xdna_key, @xdna_secret, :endpoint => @gatekeeper_endpoint)
end