Skip to content

Commit d1161b9

Browse files
authored
FIX: do not attempt to fetch user JSON if URL is not set (discourse#94)
It is a configuration error to set oauth2_fetch_user_details to true but leave oauth2_user_json_url empty. Before, this resulted in an unhandled exception in core. Now it is checked here.
1 parent 8277a36 commit d1161b9

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

plugin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def after_authenticate(auth, existing_account: nil)
296296
#{auth["extra"].to_hash.to_yaml}
297297
LOG
298298

299-
if SiteSetting.oauth2_fetch_user_details?
299+
if SiteSetting.oauth2_fetch_user_details? && SiteSetting.oauth2_user_json_url.present?
300300
if fetched_user_details = fetch_user_details(auth["credentials"]["token"], auth["uid"])
301301
auth["uid"] = fetched_user_details[:user_id] if fetched_user_details[:user_id]
302302
auth["info"]["nickname"] = fetched_user_details[:username] if fetched_user_details[

spec/plugin_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
describe OAuth2BasicAuthenticator do
66
describe "after_authenticate" do
7+
before { SiteSetting.oauth2_user_json_url = "https://provider.com/user" }
8+
79
let(:user) { Fabricate(:user) }
810
let(:authenticator) { OAuth2BasicAuthenticator.new }
911

0 commit comments

Comments
 (0)