Sha256: c58313e8c13c7f9e2cae69eaf933cf1cdde5372db94513cc9697aa6fe1005f07

Contents?: true

Size: 792 Bytes

Versions: 12

Compression:

Stored size: 792 Bytes

Contents

# frozen_string_literal: true

# IronBank main module
module IronBank
  # IronBank Faraday middleware module
  module FaradayMiddleware
    # This middleware reauthorize the request on unauthorized request
    class RenewAuth < Faraday::Response::Middleware
      def initialize(app, auth)
        @auth = auth

        super(app)
      end

      def on_complete(env)
        @env = env

        renew_auth_header if env.status == 401
      end

      private

      attr_reader :auth, :env

      def renew_auth_header
        auth.renew_session

        # NOTE: Merging the refreshed auth headers into the original request
        #       (which will be retried via the `:retry` middleware.)
        env.request_headers = env.request_headers.merge(auth.header)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
iron_bank-3.3.2 lib/iron_bank/faraday_middleware/renew_auth.rb
iron_bank-3.3.1 lib/iron_bank/faraday_middleware/renew_auth.rb
iron_bank-3.3.0 lib/iron_bank/faraday_middleware/renew_auth.rb
iron_bank-3.2.0 lib/iron_bank/faraday_middleware/renew_auth.rb
iron_bank-3.1.1 lib/iron_bank/faraday_middleware/renew_auth.rb
iron_bank-3.1.0 lib/iron_bank/faraday_middleware/renew_auth.rb
iron_bank-3.0.3 lib/iron_bank/faraday_middleware/renew_auth.rb
iron_bank-3.0.2 lib/iron_bank/faraday_middleware/renew_auth.rb
iron_bank-3.0.1 lib/iron_bank/faraday_middleware/renew_auth.rb
iron_bank-3.0.0 lib/iron_bank/faraday_middleware/renew_auth.rb
iron_bank-2.2.0 lib/iron_bank/faraday_middleware/renew_auth.rb
iron_bank-2.1.0 lib/iron_bank/faraday_middleware/renew_auth.rb