-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : OAuth2User를 Wrapping 하는 GitHubUser 구현 (#112)
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/gdsc/binaryho/imhere/security/oauth/GitHubUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |