Sha256: dbab6af4e33388200f0f9d940ae97cc02ea5a232ba6432b6be6e1132d9a4065d

Contents?: true

Size: 1.09 KB

Versions: 9

Compression:

Stored size: 1.09 KB

Contents

# typed: strict
# frozen_string_literal: true

module EML
  module BasicAuth
    class Verify
      extend T::Sig

      sig do
        params(
          auth_token: T.nilable(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: T.nilable(String),
          username: String,
          password: String
        ).void
      end
      def initialize(auth_token, username, password)
        @auth_token = T.let(auth_token || "", String)
        @username = T.let(username, String)
        @password = T.let(password, String)
      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

      sig { returns(String) }
      def parse_auth_token
        @auth_token.sub(/^[^\s]+\s/, "")
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
eml-2.1.8 lib/eml/lib/basic_auth/verify.rb
eml-2.1.7 lib/eml/lib/basic_auth/verify.rb
eml-2.1.6 lib/eml/lib/basic_auth/verify.rb
eml-2.1.5 lib/eml/lib/basic_auth/verify.rb
eml-2.1.4 lib/eml/lib/basic_auth/verify.rb
eml-2.1.3 lib/eml/lib/basic_auth/verify.rb
eml-2.1.2 lib/eml/lib/basic_auth/verify.rb
eml-2.1.1 lib/eml/lib/basic_auth/verify.rb
eml-2.1.0 lib/eml/lib/basic_auth/verify.rb