FIX: do not attempt to fetch user JSON if URL is not set (#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.
This commit is contained in:
Leonardo Mosquera 2024-01-24 18:50:52 -03:00 committed by GitHub
parent 8277a3666d
commit d1161b99a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View File

@ -296,7 +296,7 @@ class ::OAuth2BasicAuthenticator < Auth::ManagedAuthenticator
#{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[

View File

@ -4,6 +4,8 @@ require "rails_helper"
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 }