Sha256: ba1ed76ce9c978ae810d663a13a9d171b74a015050d29edc7be1a5ba74153aac

Contents?: true

Size: 586 Bytes

Versions: 11

Compression:

Stored size: 586 Bytes

Contents

# frozen_string_literal: true
module FinAppsCore
  module Middleware
    # Adds a custom header for basic authorization.
    # If the value for this header already exists, it is not overriden.
    class NoEncodingBasicAuthentication < Faraday::Middleware
      KEY = 'Authorization' unless defined? KEY

      def initialize(app, token)
        super(app)
        sanitized = token.to_s.strip.delete("\n")
        @header_value = "Basic #{sanitized}"
      end

      def call(env)
        env[:request_headers][KEY] ||= @header_value
        @app.call(env)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
finapps_core-2.0.12 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-2.0.11 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-2.0.10 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-2.0.9 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-2.0.8 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-2.0.7 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-2.0.6 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-2.0.5 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-2.0.4 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-2.0.3 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-2.0.2 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb