Class: FmRest::V1::TokenSession
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- FmRest::V1::TokenSession
- Defined in:
- lib/fmrest/v1/token_session.rb
Overview
FM Data API authentication middleware using the credentials strategy
Constant Summary collapse
- HEADER_KEY =
"Authorization".freeze
- TOKEN_STORE_INTERFACE =
[:load, :store, :delete].freeze
Instance Method Summary collapse
-
#call(env) ⇒ Object
Entry point for the middleware when sending a request.
-
#initialize(app, options = FmRest.default_connection_settings) ⇒ TokenSession
constructor
A new instance of TokenSession.
Constructor Details
#initialize(app, options = FmRest.default_connection_settings) ⇒ TokenSession
Returns a new instance of TokenSession.
11 12 13 14 |
# File 'lib/fmrest/v1/token_session.rb', line 11 def initialize(app, = FmRest.default_connection_settings) super(app) = end |
Instance Method Details
#call(env) ⇒ Object
Entry point for the middleware when sending a request
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fmrest/v1/token_session.rb', line 18 def call(env) set_auth_header(env) request_body = env[:body] # After failure env[:body] is set to the response body @app.call(env).on_complete do |response_env| if response_env[:status] == 401 # Unauthorized env[:body] = request_body token_store.delete(token_store_key) set_auth_header(env) return @app.call(env) end end end |