Sha256: 29c44d3478d0893ebd995678471f5d4dc20e760a4b8931d3d71fb7fa7cfbfe6f
Contents?: true
Size: 1.24 KB
Versions: 10
Compression:
Stored size: 1.24 KB
Contents
module Scimaenaga class AuthorizeApiRequest def initialize(searchable_attribute:, authentication_attribute:) @searchable_attribute = searchable_attribute @authentication_attribute = authentication_attribute if searchable_attribute.blank? || authentication_attribute.blank? raise Scimaenaga::ExceptionHandler::InvalidCredentials end @search_parameter = { Scimaenaga.config.basic_auth_model_searchable_attribute => @searchable_attribute } end def company company = find_company authorize(company) company end private attr_reader :authentication_attribute, :search_parameter, :searchable_attribute def find_company @company ||= Scimaenaga.config.basic_auth_model.find_by!(search_parameter) rescue ActiveRecord::RecordNotFound raise Scimaenaga::ExceptionHandler::InvalidCredentials end def authorize(authentication_model) authorized = ActiveSupport::SecurityUtils.secure_compare( authentication_model.public_send(Scimaenaga.config.basic_auth_model_authenticatable_attribute), authentication_attribute ) raise Scimaenaga::ExceptionHandler::InvalidCredentials unless authorized end end end
Version data entries
10 entries across 10 versions & 1 rubygems