Sha256: 956683f39006dbfd18770edba2fb365b1260a7c97f05b0a821f6c7980f958124

Contents?: true

Size: 762 Bytes

Versions: 5

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins
    #
    # This plugin adds helper methods to implement HTTP Basic Auth (https://tools.ietf.org/html/rfc7617)
    #
    # https://gitlab.com/honeyryderchuck/httpx/wikis/Authentication#basic-authentication
    #
    module BasicAuthentication
      def self.load_dependencies(klass)
        require "base64"
        klass.plugin(:authentication)
      end

      module InstanceMethods
        def basic_authentication(user, password)
          authentication("Basic #{Base64.strict_encode64("#{URI.escape(user)}:#{URI.escape(password)}")}")
        end
        alias_method :basic_auth, :basic_authentication
      end
    end
    register_plugin :basic_authentication, BasicAuthentication
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
httpx-0.6.1 lib/httpx/plugins/basic_authentication.rb
httpx-0.6.0 lib/httpx/plugins/basic_authentication.rb
httpx-0.5.1 lib/httpx/plugins/basic_authentication.rb
httpx-0.5.0 lib/httpx/plugins/basic_authentication.rb
httpx-0.4.1 lib/httpx/plugins/basic_authentication.rb