FEATURE: Add detailed OAuth2 request and response logs
This makes use of Faraday middleware to log precise details about all requests made by the OAuth2 gem. This should make it easier to debug configuration issues
This commit is contained in:
parent
ca5f555750
commit
d8a8724f2b
38
plugin.rb
38
plugin.rb
|
@ -46,6 +46,34 @@ class ::OmniAuth::Strategies::Oauth2Basic < ::OmniAuth::Strategies::OAuth2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if Gem::Version.new(Faraday::VERSION) > Gem::Version.new('1.0')
|
||||||
|
require 'faraday/logging/formatter'
|
||||||
|
class OAuth2FaradayFormatter < Faraday::Logging::Formatter
|
||||||
|
def request(env)
|
||||||
|
warn <<~LOG
|
||||||
|
OAuth2 Debugging: request #{env.method.upcase} #{env.url.to_s}
|
||||||
|
|
||||||
|
Headers: #{env.request_headers}
|
||||||
|
|
||||||
|
Body: #{env[:body]}
|
||||||
|
LOG
|
||||||
|
end
|
||||||
|
|
||||||
|
def response(env)
|
||||||
|
warn <<~LOG
|
||||||
|
OAuth2 Debugging: response status #{env.status}
|
||||||
|
|
||||||
|
From #{env.method.upcase} #{env.url.to_s}
|
||||||
|
|
||||||
|
Headers: #{env.response_headers}
|
||||||
|
|
||||||
|
Body: #{env[:body]}
|
||||||
|
LOG
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class ::OAuth2BasicAuthenticator < Auth::ManagedAuthenticator
|
class ::OAuth2BasicAuthenticator < Auth::ManagedAuthenticator
|
||||||
def name
|
def name
|
||||||
'oauth2_basic'
|
'oauth2_basic'
|
||||||
|
@ -80,6 +108,16 @@ class ::OAuth2BasicAuthenticator < Auth::ManagedAuthenticator
|
||||||
unless SiteSetting.oauth2_scope.blank?
|
unless SiteSetting.oauth2_scope.blank?
|
||||||
opts[:scope] = SiteSetting.oauth2_scope
|
opts[:scope] = SiteSetting.oauth2_scope
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if SiteSetting.oauth2_debug_auth && defined? OAuth2FaradayFormatter
|
||||||
|
opts[:client_options][:connection_build] = lambda{ |builder|
|
||||||
|
builder.response :logger, Rails.logger, { bodies: true, formatter: OAuth2FaradayFormatter }
|
||||||
|
|
||||||
|
# Default stack:
|
||||||
|
builder.request :url_encoded # form-encode POST params
|
||||||
|
builder.adapter Faraday.default_adapter # make requests with Net::HTTP
|
||||||
|
}
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue