Skip to content

Commit

Permalink
FIX: do not attempt to fetch user JSON if URL is not set (#94)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ldmosquera authored Jan 24, 2024
1 parent 8277a36 commit d1161b9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def after_authenticate(auth, existing_account: nil)
#{auth["extra"].to_hash.to_yaml}
LOG

if SiteSetting.oauth2_fetch_user_details?
if SiteSetting.oauth2_fetch_user_details? && SiteSetting.oauth2_user_json_url.present?
if fetched_user_details = fetch_user_details(auth["credentials"]["token"], auth["uid"])
auth["uid"] = fetched_user_details[:user_id] if fetched_user_details[:user_id]
auth["info"]["nickname"] = fetched_user_details[:username] if fetched_user_details[
Expand Down
2 changes: 2 additions & 0 deletions spec/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

describe OAuth2BasicAuthenticator do
describe "after_authenticate" do
before { SiteSetting.oauth2_user_json_url = "https://provider.com/user" }

let(:user) { Fabricate(:user) }
let(:authenticator) { OAuth2BasicAuthenticator.new }

Expand Down

0 comments on commit d1161b9

Please sign in to comment.