Sha256: 9cc3ae30465e64d16a11e4afda294b723dd76d2f59c9593fa81686757397126b

Contents?: true

Size: 734 Bytes

Versions: 6

Compression:

Stored size: 734 Bytes

Contents

module Restfulness
  module HttpAuthentication

    class Basic

      # The Requests::AuthorizationHeader object generated in the request
      attr_accessor :header

      def initialize(header)
        self.header = header
      end

      # Determine if the header we were provided is valid.
      def valid?
        header.schema == 'Basic' && credentials.length == 2
      end

      # Attempt to decode the credentials provided in the header.
      def credentials
        @credentials ||= begin
          txt = ::Base64.decode64(header.params || '')
          txt.split(/:/, 2)
        end
      end

      def username
        credentials[0]
      end

      def password
        credentials[1]
      end

    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
restfulness-0.3.6 lib/restfulness/http_authentication/basic.rb
restfulness-0.3.5 lib/restfulness/http_authentication/basic.rb
restfulness-0.3.4 lib/restfulness/http_authentication/basic.rb
restfulness-0.3.3 lib/restfulness/http_authentication/basic.rb
restfulness-0.3.2 lib/restfulness/http_authentication/basic.rb
restfulness-0.3.1 lib/restfulness/http_authentication/basic.rb