PHP 8.2.31
Preview: basic.rb Size: 1.16 KB
/proc/thread-self/root/opt/alt/ruby19/lib64/ruby/gems/1.9.1/gems/rack-1.6.4/lib/rack/auth/basic.rb

require 'rack/auth/abstract/handler'
require 'rack/auth/abstract/request'

module Rack
  module Auth
    # Rack::Auth::Basic implements HTTP Basic Authentication, as per RFC 2617.
    #
    # Initialize with the Rack application that you want protecting,
    # and a block that checks if a username and password pair are valid.
    #
    # See also: <tt>example/protectedlobster.rb</tt>

    class Basic < AbstractHandler

      def call(env)
        auth = Basic::Request.new(env)

        return unauthorized unless auth.provided?

        return bad_request unless auth.basic?

        if valid?(auth)
          env['REMOTE_USER'] = auth.username

          return @app.call(env)
        end

        unauthorized
      end


      private

      def challenge
        'Basic realm="%s"' % realm
      end

      def valid?(auth)
        @authenticator.call(*auth.credentials)
      end

      class Request < Auth::AbstractRequest
        def basic?
          "basic" == scheme
        end

        def credentials
          @credentials ||= params.unpack("m*").first.split(/:/, 2)
        end

        def username
          credentials.first
        end
      end

    end
  end
end

Directory Contents

Dirs: 2 × Files: 1

Name Size Perms Modified Actions
abstract DIR
- drwxr-xr-x 2024-03-03 22:48:10
Edit Download
digest DIR
- drwxr-xr-x 2024-03-03 22:48:10
Edit Download
1.16 KB lrw-r--r-- 2019-12-05 22:59:30
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).