A platform for community discussion. Free, open, simple.
DEV: Fix username/name mapping for Discord auth (#31494)
Penar Musaraj424da95128bd
diff --git a/lib/auth/discord_authenticator.rb b/lib/auth/discord_authenticator.rbindex 56d8923cd4c..acc90a7d5a0 100644--- a/lib/auth/discord_authenticator.rb+++ b/lib/auth/discord_authenticator.rb@@ -16,7 +16,8 @@ class Auth::DiscordAuthenticator < Auth::ManagedAuthenticatorinfo do{- name: raw_info["username"],+ name: raw_info["global_name"] || raw_info["username"],+ nickname: raw_info["username"],email: raw_info["verified"] ? raw_info["email"] : nil,image: "https://cdn.discordapp.com/avatars/#{raw_info["id"]}/#{raw_info["avatar"]}",}diff --git a/spec/lib/auth/discord_authenticator_spec.rb b/spec/lib/auth/discord_authenticator_spec.rbindex 7aea3e5d094..677b1bf8275 100644--- a/spec/lib/auth/discord_authenticator_spec.rb+++ b/spec/lib/auth/discord_authenticator_spec.rb@@ -3,11 +3,12 @@RSpec.describe Auth::DiscordAuthenticator dolet(:hash) doOmniAuth::AuthHash.new(- provider: "facebook",+ provider: "discord",extra: {raw_info: {id: "100",username: "bobbob",+ global_name: "The Bob",guilds: [{id: "80351110224678912",@@ -21,7 +22,8 @@ RSpec.describe Auth::DiscordAuthenticator do},info: {email: "[email protected]",- name: "bobbob",+ name: "The Bob",+ nickname: "bobbob",},uid: "100",)@@ -34,7 +36,8 @@ RSpec.describe Auth::DiscordAuthenticator doresult = authenticator.after_authenticate(hash)expect(result.user).to eq(nil)expect(result.failed).to eq(false)- expect(result.name).to eq("bobbob")+ expect(result.name).to eq("The Bob")+ expect(result.username).to eq("bobbob")expect(result.email).to eq("[email protected]")end@@ -51,7 +54,8 @@ RSpec.describe Auth::DiscordAuthenticator doresult = authenticator.after_authenticate(hash)expect(result.user).to eq(nil)expect(result.failed).to eq(false)- expect(result.name).to eq("bobbob")+ expect(result.name).to eq("The Bob")+ expect(result.username).to eq("bobbob")expect(result.email).to eq("[email protected]")endend