lib/mkit/app/mkit_server.rb in mkit-0.5.0 vs lib/mkit/app/mkit_server.rb in mkit-0.6.0

- old
+ new

@@ -7,9 +7,17 @@ set :default_content_type, :json set :dump_errors, true set :show_exceptions, false set :raise_errors, false + before do + api_key = request.env['HTTP_X_API_KEY'] + cfg = YAML.load_file(MKIt::Config.config_file) + if cfg.nil? || cfg['mkit'].nil? || cfg['mkit']['clients'].nil? || !cfg['mkit']['clients'].map{|h| h['id']}.include?(api_key) + error 401, 'Unauthorized - please add your client-id to authorized clients list' + end + end + error MKIt::BaseException do |e| MKItLogger.debug e error e.error_code, e.message end