Skip to content

Commit 253f63a

Browse files
committed
Merge remote-tracking branch 'origin/better-logging' into feature-add-json-encoding
2 parents 78bb57d + 12e2f7e commit 253f63a

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

plugin.rb

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ def request(env)
5151
warn <<~LOG
5252
OAuth2 Debugging: request #{env.method.upcase} #{env.url.to_s}
5353
54-
Headers: #{env.request_headers}
54+
Headers:
55+
#{env.request_headers.to_yaml}
5556
56-
Body: #{env[:body]}
57+
Body:
58+
#{env[:body].to_yaml}
5759
LOG
5860
end
5961

@@ -63,9 +65,11 @@ def response(env)
6365
6466
From #{env.method.upcase} #{env.url.to_s}
6567
66-
Headers: #{env.response_headers}
68+
Headers:
69+
#{env.request_headers.to_yaml}
6770
68-
Body: #{env[:body]}
71+
Body:
72+
#{env[:body].to_yaml}
6973
LOG
7074
end
7175
end
@@ -225,19 +229,22 @@ def fetch_user_details(token, id)
225229
user_json_url = SiteSetting.oauth2_user_json_url.sub(":token", token.to_s).sub(":id", id.to_s)
226230
user_json_method = SiteSetting.oauth2_user_json_url_method.downcase.to_sym
227231

228-
log("user_json_url: #{user_json_method} #{user_json_url}")
229-
230232
bearer_token = "Bearer #{token}"
231233
connection = Faraday.new { |f| f.adapter FinalDestination::FaradayAdapter }
232234
headers = { "Authorization" => bearer_token, "Accept" => "application/json" }
233235
user_json_response = connection.run_request(user_json_method, user_json_url, nil, headers)
234236

235-
log("user_json_response: #{user_json_response.inspect}")
237+
log <<-LOG
238+
user_json request: #{user_json_method} #{user_json_url}
239+
240+
response:
241+
#{user_json_response.to_yaml}
242+
LOG
236243

237244
if user_json_response.status == 200
238245
user_json = JSON.parse(user_json_response.body)
239246

240-
log("user_json: #{user_json}")
247+
log("user_json:\n#{user_json.to_yaml}")
241248

242249
result = {}
243250
if user_json.present?
@@ -272,9 +279,20 @@ def always_update_user_email?
272279
end
273280

274281
def after_authenticate(auth, existing_account: nil)
275-
log(
276-
"after_authenticate response: \n\ncreds: #{auth["credentials"].to_hash}\nuid: #{auth["uid"]}\ninfo: #{auth["info"].to_hash}\nextra: #{auth["extra"].to_hash}",
277-
)
282+
log <<-LOG
283+
after_authenticate response:
284+
285+
creds:
286+
#{auth["credentials"].to_hash.to_yaml}
287+
288+
uid: #{auth["uid"]}
289+
290+
info:
291+
#{auth["info"].to_hash.to_yaml}
292+
293+
extra:
294+
#{auth["extra"].to_hash.to_yaml}
295+
LOG
278296

279297
if SiteSetting.oauth2_fetch_user_details?
280298
if fetched_user_details = fetch_user_details(auth["credentials"]["token"], auth["uid"])

0 commit comments

Comments
 (0)