Merge pull request #1 from PSPinc/feat/add-basic-auth

fix(references): update reference to Rswag::Ui::BasicAuth and env_mat…
This commit is contained in:
Kabiru Mwenja 2020-01-30 10:18:58 +03:00 committed by GitHub
commit 333a0b535a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 9 deletions

View File

@ -9,23 +9,20 @@ module Rswag
#
class BasicAuth < ::Rack::Auth::Basic
def call(env)
return @app.call(env) unless env_matching_path
return @app.call(env) unless env_matching_path(env)
super(env)
end
private
def env_matching_path
Rswag::Ui.config.swagger_endpoints[:urls].find do |endpoint|
base_path(endpoint[:url]) == env_base_path
def env_matching_path(env)
path = base_path(env['PATH_INFO'])
Rswag::Ui.config.config_object[:urls].find do |endpoint|
base_path(endpoint[:url]) == path
end
end
def env_base_path
base_path(env['PATH_INFO'])
end
def base_path(url)
url.downcase.split('/')[1]
end

View File

@ -11,7 +11,7 @@ module Rswag
if Rswag::Ui.config.basic_auth_enabled
c = Rswag::Ui.config
app.middleware.use UiBasicAuth do |username, password|
app.middleware.use Rswag::Ui::BasicAuth do |username, password|
c.config_object[:basic_auth].values == [username, password]
end
end