Class: Evrythng::Request::TokenAuthentication

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/evrythng/request/token_authentication.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, token, options = {}) ⇒ TokenAuthentication

Returns a new instance of TokenAuthentication.



7
8
9
10
11
# File 'lib/evrythng/request/token_authentication.rb', line 7

def initialize(app, token, options={})
  super(app)

  @header_value = token
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
# File 'lib/evrythng/request/token_authentication.rb', line 13

def call(env)
  unless env[:request_headers]['X-Evrythng-Token']
    env[:request_headers]['X-Evrythng-Token'] = @header_value
  end
  @app.call(env)
end