Sha256: 3cefaa64327c5bcc4d763ffcba6c14848b309e552a047feb244664b1c84c18f0

Contents?: true

Size: 588 Bytes

Versions: 32

Compression:

Stored size: 588 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 = "Bearer #{sanitized}"
      end

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

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
finapps_core-6.0.2 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-6.0.1 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-6.0.0 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.16 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.15 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.14 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.13 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.11 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.10 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.9 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.8 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.7 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.6 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.5 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.4 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.3 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.2 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.1 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-5.0.0 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb
finapps_core-4.0.7 lib/finapps_core/middleware/request/no_encoding_basic_authentication.rb