Sha256: c010c9b36ec74a9ec1f061a0e46d9d5a4cc57f9b2142ba290ecf7243ff51ad8a

Contents?: true

Size: 1.55 KB

Versions: 16

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module FactoryBot
  module Instrumentation
    # A base engine application controller.
    class ApplicationController < ActionController::API
      # Extend our core functionality to support easy authentication logics
      include ActionController::HttpAuthentication::Basic::ControllerMethods
      include ActionController::HttpAuthentication::Digest::ControllerMethods
      include ActionController::HttpAuthentication::Token::ControllerMethods

      # Allow the users to implement additional instrumentation-wide before
      # action logic, like authentication
      before_action do |_controller|
        if FactoryBot::Instrumentation.configuration.before_action
          instance_eval(
            &FactoryBot::Instrumentation.configuration.before_action
          )
        end
      end

      protected

      # A simple shortcut for Basic Auth on Rails 4.2+. Just configure the
      # username and password and you're ready to check the current request.
      #
      # @param username [String] the required user name
      # @param password [String] the required password of the user
      # @param realm [String] the authentication realm
      def basic_auth(username:, password:, realm: 'Instrumentation')
        authenticate_or_request_with_http_basic(realm) \
          do |given_name, given_password|
          ActiveSupport::SecurityUtils.secure_compare(given_name, username) &
            ActiveSupport::SecurityUtils.secure_compare(
              given_password, password
            )
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
factory_bot_instrumentation-1.2.4 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-1.2.3 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-1.2.2 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-1.2.1 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-1.2.0 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-1.1.5 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-1.1.4 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-1.1.3 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-1.1.1 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-1.1.0 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-1.0.2 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-1.0.1 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-1.0.0 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-0.8.0 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-0.7.1 app/controllers/factory_bot/instrumentation/application_controller.rb
factory_bot_instrumentation-0.7.0 app/controllers/factory_bot/instrumentation/application_controller.rb