diff --git a/app/models/discourse_single_sign_on.rb b/app/models/discourse_single_sign_on.rb index a9784f52a91..83c3d431f5b 100644 --- a/app/models/discourse_single_sign_on.rb +++ b/app/models/discourse_single_sign_on.rb @@ -114,7 +114,9 @@ class DiscourseSingleSignOn < SingleSignOn user.email = email end - if SiteSetting.sso_overrides_username && user.username != username + if SiteSetting.sso_overrides_username && + user.username != username && + user.username != UserNameSuggester.fix_username(username || name || email) user.username = UserNameSuggester.suggest(username || name || email) end diff --git a/spec/models/discourse_single_sign_on_spec.rb b/spec/models/discourse_single_sign_on_spec.rb index 173f4efe8f0..62a10d0ae5a 100644 --- a/spec/models/discourse_single_sign_on_spec.rb +++ b/spec/models/discourse_single_sign_on_spec.rb @@ -88,7 +88,9 @@ describe DiscourseSingleSignOn do sso.lookup_or_create_user(ip_address) admin.reload + expect(admin.email).to eq("test@bob.com") + expect(admin.username).to eq "bob_the_admin" end it "can fill in data on way back" do