From 23b31a568c15c7758078c925403bc33fbc772734 Mon Sep 17 00:00:00 2001 From: binary_ho Date: Fri, 8 Mar 2024 23:19:44 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20OAuth2User=EB=A5=BC=20Wrapping=20?= =?UTF-8?q?=ED=95=98=EB=8A=94=20GitHubUser=20=EA=B5=AC=ED=98=84=20(#112)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../imhere/security/oauth/GitHubUser.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/java/gdsc/binaryho/imhere/security/oauth/GitHubUser.java diff --git a/src/main/java/gdsc/binaryho/imhere/security/oauth/GitHubUser.java b/src/main/java/gdsc/binaryho/imhere/security/oauth/GitHubUser.java new file mode 100644 index 0000000..43f3297 --- /dev/null +++ b/src/main/java/gdsc/binaryho/imhere/security/oauth/GitHubUser.java @@ -0,0 +1,39 @@ +package gdsc.binaryho.imhere.security.oauth; + +import java.util.Collection; +import java.util.Map; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.oauth2.core.user.OAuth2User; + +public class GitHubUser { + + public static final String GITHUB_NAME_ATTRIBUTE_KEY = "id"; + private static final String GIT_HUB_HANDLE_ATTRIBUTE_NAME = "login"; + private static final String GIT_HUB_AVATAR_URL_ATTRIBUTE_NAME = "avatar_url"; + + private final OAuth2User oAuth2User; + + public GitHubUser(OAuth2User oAuth2User) { + this.oAuth2User = oAuth2User; + } + + public String getId() { + return oAuth2User.getName(); + } + + public String getHandle() { + return oAuth2User.getAttribute(GIT_HUB_HANDLE_ATTRIBUTE_NAME); + } + + public String getAvatarUrl() { + return oAuth2User.getAttribute(GIT_HUB_AVATAR_URL_ATTRIBUTE_NAME); + } + + public Collection getAuthorities() { + return oAuth2User.getAuthorities(); + } + + public Map getAttributes() { + return oAuth2User.getAttributes(); + } +}