diff --git a/rswag-ui/lib/rswag/ui/basic_auth.rb b/rswag-ui/lib/rswag/ui/basic_auth.rb index 957ddfb..7bbd85d 100644 --- a/rswag-ui/lib/rswag/ui/basic_auth.rb +++ b/rswag-ui/lib/rswag/ui/basic_auth.rb @@ -1,25 +1,34 @@ +# frozen_string_literal: true + require 'rack/auth/basic' -class BasicAuth < ::Rack::Auth::Basic - def call(env) - return @app.call(env) unless env_matching_path +module Rswag + module Ui + # Extend Rack HTTP Basic Authentication, as per RFC 2617. + # @api private + # + class BasicAuth < ::Rack::Auth::Basic + def call(env) + return @app.call(env) unless env_matching_path - super(env) - end + super(env) + end - private + private - def env_matching_path - swagger_endpoints = Rswag::Ui.config.swagger_endpoints[:urls] - swagger_endpoints.find do |endpoint| - base_path = base_path(endpoint[:url]) - env_base_path = base_path(env['PATH_INFO']) + def env_matching_path + Rswag::Ui.config.swagger_endpoints[:urls].find do |endpoint| + base_path(endpoint[:url]) == env_base_path + end + end - base_path == env_base_path + def env_base_path + base_path(env['PATH_INFO']) + end + + def base_path(url) + url.downcase.split('/')[1] + end end end - - def base_path(url) - url.downcase.split('/')[1] - end end