From 8d5ad2b886be0bdd315b9b3135d5b3221ee23c10 Mon Sep 17 00:00:00 2001 From: guqing <38999863+guqing@users.noreply.github.com> Date: Fri, 2 Aug 2024 14:36:15 +0800 Subject: [PATCH] fix: handle missing name for social bingding (#57) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What this PR does? 修复 GitHub 显示名称未设置时无法绑定的问题 /kind bug Fixes #51 Fixes https://github.com/halo-sigs/plugin-oauth2/issues/14 ```release-note 修复 GitHub 显示名称未设置时无法绑定的问题 ``` --- src/main/java/run/halo/oauth/UserConnectionServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/run/halo/oauth/UserConnectionServiceImpl.java b/src/main/java/run/halo/oauth/UserConnectionServiceImpl.java index 4823bc9..45b6b0f 100644 --- a/src/main/java/run/halo/oauth/UserConnectionServiceImpl.java +++ b/src/main/java/run/halo/oauth/UserConnectionServiceImpl.java @@ -8,7 +8,6 @@ import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.stereotype.Component; import org.springframework.util.Assert; -import org.springframework.web.server.ServerWebInputException; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import run.halo.app.core.extension.UserConnection; @@ -112,7 +111,8 @@ UserConnection convert(String username, OAuth2LoginAuthenticationToken authentic Oauth2UserProfile oauth2UserProfile = oauth2UserProfileMapperManager.mapProfile(registrationId, oauth2User); - spec.setDisplayName(oauth2UserProfile.getDisplayName()); + var displayName = StringUtils.defaultIfBlank(oauth2UserProfile.getDisplayName(), username); + spec.setDisplayName(displayName); spec.setAvatarUrl(oauth2UserProfile.getAvatarUrl()); spec.setProfileUrl(oauth2UserProfile.getProfileUrl()); return userConnection;