From 29375bdca75bdbfe2ecd3c55260b73c6643712c3 Mon Sep 17 00:00:00 2001 From: Ryan Peper Date: Thu, 22 Jun 2023 11:40:21 -0400 Subject: [PATCH] Conditionally append discriminator if not 0 --- .../keycloak/social/discord/DiscordIdentityProvider.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/keycloak/social/discord/DiscordIdentityProvider.java b/src/main/java/org/keycloak/social/discord/DiscordIdentityProvider.java index 10f183e..87b4e84 100755 --- a/src/main/java/org/keycloak/social/discord/DiscordIdentityProvider.java +++ b/src/main/java/org/keycloak/social/discord/DiscordIdentityProvider.java @@ -69,7 +69,14 @@ protected String getProfileEndpointForValidation(EventBuilder event) { protected BrokeredIdentityContext extractIdentityFromProfile(EventBuilder event, JsonNode profile) { BrokeredIdentityContext user = new BrokeredIdentityContext(getJsonProperty(profile, "id")); - user.setUsername(getJsonProperty(profile, "username") + "#" + getJsonProperty(profile, "discriminator")); + String username = getJsonProperty(profile, "username"); + String discriminator = getJsonProperty(profile, "discriminator"); + + if (!"0".equals(discriminator)) { + username += "#" + discriminator; + } + + user.setUsername(username); user.setEmail(getJsonProperty(profile, "email")); user.setIdpConfig(getConfig()); user.setIdp(this);