File: basic_auth.rb

package info (click to toggle)
ruby-httpx 1.7.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,816 kB
  • sloc: ruby: 12,209; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 697 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module HTTPX
  module Plugins
    #
    # This plugin adds helper methods to implement HTTP Basic Auth (https://datatracker.ietf.org/doc/html/rfc7617)
    #
    # https://gitlab.com/os85/httpx/wikis/Auth#basic-auth
    #
    module BasicAuth
      class << self
        def load_dependencies(_klass)
          require_relative "auth/basic"
        end

        def configure(klass)
          klass.plugin(:auth)
        end
      end

      module InstanceMethods
        def basic_auth(user, password)
          authorization(Authentication::Basic.new(user, password).authenticate)
        end
      end
    end
    register_plugin :basic_auth, BasicAuth
  end
end