Skip to content

Commit

Permalink
feat : OAuth2User를 Wrapping 하는 GitHubUser 구현 (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-ho committed Mar 8, 2024
1 parent 8d58613 commit 23b31a5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/main/java/gdsc/binaryho/imhere/security/oauth/GitHubUser.java
Original file line number Diff line number Diff line change
@@ -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<? extends GrantedAuthority> getAuthorities() {
return oAuth2User.getAuthorities();
}

public Map<String, Object> getAttributes() {
return oAuth2User.getAttributes();
}
}

0 comments on commit 23b31a5

Please sign in to comment.