Class: PDC::Request::Token

Inherits:
Faraday::Middleware
  • Object
show all
Includes:
Logging
Defined in:
lib/pdc/http/request/pdc_token.rb

Overview

Adds TokenAuthentication to request header. Uses the token if passed else fetches token using the TokenFetcher to get the token once

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(app, options = {}) ⇒ Token

Returns a new instance of Token.



9
10
11
12
# File 'lib/pdc/http/request/pdc_token.rb', line 9

def initialize(app, options = {})
  @options = options
  super(app)
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
# File 'lib/pdc/http/request/pdc_token.rb', line 14

def call(env)
  env.request_headers['Token'] = token
  logger.debug "Token set, headers: #{env.request_headers}"
  @app.call(env)
end