Module: RooOnRails::Concerns::RequireApiKey::ClassMethods

Defined in:
lib/roo_on_rails/concerns/require_api_key.rb

Instance Method Summary collapse

Instance Method Details

#require_api_key(only_services: nil, **options) ⇒ Object

Declares that routes on the controller must have access credentials specified in the request that match the approparite environment variables.

Parameters:

  • :only_services (#to_s, Array<#to_s>)

    Restricts the services which will be accepted

See Also:

  • for additional scoping opts


41
42
43
44
45
46
47
48
49
# 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