module RooOnRails::Concerns::RequireApiKey::ClassMethods
Public Instance Methods
require_api_key(only_services: nil, **options)
click to toggle source
Declares that routes on the controller must have access credentials specified in the request that match the approparite environment variables.
@param :only_services (to_s,Array<#to_s>) Restricts the services which will be accepted @see AbstractController::Callbacks::ClassMethods#before_action for additional scoping opts
# File lib/roo_on_rails/concerns/require_api_key.rb, line 41 def require_api_key(only_services: nil, **options) before_action(**options) do authenticate_or_request_with_http_basic('Authenitcation required') do |service_name, client_key| Authenticator.new([*only_services]).valid?(service_name, client_key).tap do |is_valid| @current_client = OpenStruct.new(name: service_name).freeze if is_valid end end end end