diff --git a/build.gradle b/build.gradle index d2f2625..e3df5c6 100644 --- a/build.gradle +++ b/build.gradle @@ -32,6 +32,9 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' + + // oauth + implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' } tasks.named('bootBuildImage') { diff --git a/src/main/java/com/api/TaveShot/domain/Member/Member.java b/src/main/java/com/api/TaveShot/domain/Member/Member.java index e7bf8d2..d607c7d 100644 --- a/src/main/java/com/api/TaveShot/domain/Member/Member.java +++ b/src/main/java/com/api/TaveShot/domain/Member/Member.java @@ -8,8 +8,10 @@ import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; +@Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @Builder @@ -19,4 +21,9 @@ public class Member extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + private Long gitId; + private String gitLoginId; + private String gitEmail; + private String gitName; + } diff --git a/src/main/java/com/api/TaveShot/global/oauth2/CustomOauth2User.java b/src/main/java/com/api/TaveShot/global/oauth2/CustomOauth2User.java new file mode 100644 index 0000000..99d3090 --- /dev/null +++ b/src/main/java/com/api/TaveShot/global/oauth2/CustomOauth2User.java @@ -0,0 +1,37 @@ +package com.api.TaveShot.global.oauth2; + +import com.api.TaveShot.domain.Member.Member; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import lombok.RequiredArgsConstructor; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.oauth2.core.user.OAuth2User; + +@RequiredArgsConstructor +public class CustomOauth2User implements OAuth2User { + + private final Member member; + private final Map attributes; + + @Override + public A getAttribute(String name) { + return OAuth2User.super.getAttribute(name); + } + + @Override + public Map getAttributes() { + return attributes; + } + + @Override + public Collection getAuthorities() { + return Collections.singleton(new SimpleGrantedAuthority("GITHUB_MEMBER")); + } + + @Override + public String getName() { + return member.getGitName(); + } +}