Sha256: c20193942fd7a13f23e37b4f788b2929b99865bec6e44b528dffd1d3a2b55b88

Contents?: true

Size: 1012 Bytes

Versions: 1

Compression:

Stored size: 1012 Bytes

Contents

# typed: strict
# frozen_string_literal: true

module EML
  module BasicAuth
    class Verify
      extend T::Sig

      sig do
        params(
          auth_token: String,
          username: String,
          password: String
        ).returns(T::Boolean)
      end
      def self.call(auth_token, username, password)
        new(auth_token, username, password).call
      end

      sig do
        params(
          auth_token: String,
          username: String,
          password: String
        ).void
      end
      def initialize(auth_token, username, password)
        @auth_token = auth_token
        @username = username
        @password = password
      end

      sig { returns(T::Boolean) }
      def call
        request_token = parse_auth_token
        expected_token = Generate.(@username, @password)

        ::EML::ConstantTimeCompare.(request_token, expected_token)
      end

      private

      def parse_auth_token
        @auth_token.sub(/^[^\s]+\s/, "")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eml-2.0.0 lib/eml/lib/basic_auth/verify.rb