Class: Psc::Faraday::PscToken
- Inherits:
-
Object
- Object
- Psc::Faraday::PscToken
- Defined in:
- lib/psc/faraday/psc_token.rb
Overview
Faraday middleware that implements the psc_token
authentication type. Tokens may either be static or computed
per request.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Adds the
Authorization
header using the configured token creator. -
#initialize(app, token_or_creator) ⇒ PscToken
constructor
Create a new instance of the middleware.
Constructor Details
#initialize(app, token_or_creator) ⇒ PscToken
Create a new instance of the middleware.
18 19 20 21 22 23 24 25 |
# File 'lib/psc/faraday/psc_token.rb', line 18 def initialize(app, token_or_creator) @app = app if token_or_creator.respond_to?(:call) @token_creator = token_or_creator else @token_creator = lambda { token_or_creator } end end |
Instance Method Details
#call(env) ⇒ Object
Adds the Authorization
header using the configured token creator.
29 30 31 32 33 |
# File 'lib/psc/faraday/psc_token.rb', line 29 def call(env) env[:request_headers]['Authorization'] = "psc_token #{token}" @app.call(env) end |