Sha256: 7a1950ee3b83358eee8dbd42960fa2ec5d486762ee3da7166506b2df3de4ae1a

Contents?: true

Size: 582 Bytes

Versions: 3

Compression:

Stored size: 582 Bytes

Contents

# frozen_string_literal: true
module FinApps
  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

3 entries across 3 versions & 1 rubygems

Version Path
finapps-2.1.4 lib/finapps/middleware/request/no_encoding_basic_authentication.rb
finapps-2.1.3 lib/finapps/middleware/request/no_encoding_basic_authentication.rb
finapps-2.1.2 lib/finapps/middleware/request/no_encoding_basic_authentication.rb