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