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,5 +1,12 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rack/auth/basic'
|
require 'rack/auth/basic'
|
||||||
|
|
||||||
|
module Rswag
|
||||||
|
module Ui
|
||||||
|
# Extend Rack HTTP Basic Authentication, as per RFC 2617.
|
||||||
|
# @api private
|
||||||
|
#
|
||||||
class BasicAuth < ::Rack::Auth::Basic
|
class BasicAuth < ::Rack::Auth::Basic
|
||||||
def call(env)
|
def call(env)
|
||||||
return @app.call(env) unless env_matching_path
|
return @app.call(env) unless env_matching_path
|
||||||
@ -10,16 +17,18 @@ class BasicAuth < ::Rack::Auth::Basic
|
|||||||
private
|
private
|
||||||
|
|
||||||
def env_matching_path
|
def env_matching_path
|
||||||
swagger_endpoints = Rswag::Ui.config.swagger_endpoints[:urls]
|
Rswag::Ui.config.swagger_endpoints[:urls].find do |endpoint|
|
||||||
swagger_endpoints.find do |endpoint|
|
base_path(endpoint[:url]) == env_base_path
|
||||||
base_path = base_path(endpoint[:url])
|
|
||||||
env_base_path = base_path(env['PATH_INFO'])
|
|
||||||
|
|
||||||
base_path == env_base_path
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def env_base_path
|
||||||
|
base_path(env['PATH_INFO'])
|
||||||
|
end
|
||||||
|
|
||||||
def base_path(url)
|
def base_path(url)
|
||||||
url.downcase.split('/')[1]
|
url.downcase.split('/')[1]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user