mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-22 22:06:43 +00:00
fix(rswag-ui): Define BasicAuth in Rswag::Ui module
This commit is contained in:
parent
6e706c04d7
commit
a43e6f6546
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user