Skip to content

Commit

Permalink
Merge pull request #646 from tukcomCD2024/refact/remove_oauth-B-core-…
Browse files Browse the repository at this point in the history
…#643

refact : 사용하지 않는 oauth2 컴포넌트 제거 #643
  • Loading branch information
seokho-1116 authored Aug 22, 2024
2 parents 7900037 + f660b3a commit 1c389e2
Show file tree
Hide file tree
Showing 29 changed files with 153 additions and 782 deletions.
3 changes: 3 additions & 0 deletions backend/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ dependencies {
annotationProcessor 'jakarta.annotation:jakarta.annotation-api'
annotationProcessor 'jakarta.persistence:jakarta.persistence-api'

// nanoid
implementation 'com.aventrix.jnanoid:jnanoid:2.0.0'

//swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,65 +23,6 @@
import site.timecapsulearchive.core.global.error.ErrorResponse;

public interface AuthApi {

@Operation(
summary = "카카오 로그인 페이지",
description = """
oauth2 kakao 인증 페이지 url을 반환한다.
""",
tags = {"oauth2"}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "ok"
)
})
ResponseEntity<OAuth2UriResponse> getOAuth2KakaoUrl(HttpServletRequest request);


@Operation(
summary = "구글 로그인 페이지",
description = """
oauth2 google 인증 페이지 url을 반환한다.
""",
tags = {"oauth2"}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "ok"
)
})
ResponseEntity<OAuth2UriResponse> getOAuth2GoogleUrl(HttpServletRequest request);

@Operation(
summary = "카카오 인증 성공시 임시 인증 토큰 발급",
description = "oauth2 kakao 인증 성공시 임시 인증 토큰을 발급한다. (oauth2 로그인 성공시 리다이렉트 엔드포인트로 문서화 목적) ",
tags = {"oauth2"}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "ok"
)
})
ResponseEntity<TemporaryTokenResponse> getTemporaryTokenByKakao();


@Operation(
summary = "구글 인증 성공시 임시 인증 토큰 발급",
description = "oauth2 google 인증 성공시 임시 인증 토큰을 발급한다. (oauth2 로그인 성공시 리다이렉트 엔드포인트로 문서화 목적) ",
tags = {"oauth2"}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "ok"
)
})
ResponseEntity<TemporaryTokenResponse> getTemporaryTokenByGoogle();

@Operation(
summary = "다른 소셜 프로바이더의 앱으로 인증한 클라이언트 아이디로 회원가입",
description = """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package site.timecapsulearchive.core.domain.auth.api;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -19,7 +17,6 @@
import site.timecapsulearchive.core.domain.auth.data.request.TokenReIssueRequest;
import site.timecapsulearchive.core.domain.auth.data.request.VerificationMessageSendRequest;
import site.timecapsulearchive.core.domain.auth.data.request.VerificationNumberValidRequest;
import site.timecapsulearchive.core.domain.auth.data.response.OAuth2UriResponse;
import site.timecapsulearchive.core.domain.auth.data.response.TemporaryTokenResponse;
import site.timecapsulearchive.core.domain.auth.data.response.TokenResponse;
import site.timecapsulearchive.core.domain.auth.data.response.VerificationMessageSendResponse;
Expand All @@ -35,34 +32,6 @@ public class AuthApiController implements AuthApi {

private final AuthManager authManager;

@GetMapping(value = "/login/url/kakao", produces = {"application/json"})
@Override
public ResponseEntity<OAuth2UriResponse> getOAuth2KakaoUrl(final HttpServletRequest request) {
final String kakaoLoginUrl = authManager.getOAuth2KakaoUrl(request);

return ResponseEntity.ok(OAuth2UriResponse.from(kakaoLoginUrl));
}

@GetMapping(value = "/login/url/google", produces = {"application/json"})
@Override
public ResponseEntity<OAuth2UriResponse> getOAuth2GoogleUrl(final HttpServletRequest request) {
final String googleLoginUrl = authManager.getOauth2GoogleUrl(request);

return ResponseEntity.ok(OAuth2UriResponse.from(googleLoginUrl));
}

@GetMapping(value = "/login/oauth2/code/kakao", produces = {"application/json"})
@Override
public ResponseEntity<TemporaryTokenResponse> getTemporaryTokenByKakao() {
throw new UnsupportedOperationException();
}

@GetMapping(value = "/login/oauth2/code/google", produces = {"application/json"})
@Override
public ResponseEntity<TemporaryTokenResponse> getTemporaryTokenByGoogle() {
throw new UnsupportedOperationException();
}

@PostMapping(
value = "/temporary-token/re-issue",
produces = {"application/json"},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package site.timecapsulearchive.core.domain.auth.service;

import jakarta.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
Expand All @@ -15,31 +14,10 @@
@RequiredArgsConstructor
public class AuthManager {

private static final String KAKAO_AUTHORIZATION_ENDPOINT = "/auth/login/kakao";
private static final String GOOGLE_AUTHORIZATION_ENDPOINT = "/auth/login/google";

private final TokenManager tokenManager;
private final MemberService memberService;
private final MessageVerificationService messageVerificationService;

public String getOAuth2KakaoUrl(final HttpServletRequest request) {
final String baseUrl = request.getRequestURL().toString();

return baseUrl.replace(
request.getRequestURI(),
request.getContextPath() + KAKAO_AUTHORIZATION_ENDPOINT
);
}

public String getOauth2GoogleUrl(final HttpServletRequest request) {
final String baseUrl = request.getRequestURL().toString();

return baseUrl.replace(
request.getRequestURI(),
request.getContextPath() + GOOGLE_AUTHORIZATION_ENDPOINT
);
}

public TemporaryTokenDto reIssueTemporaryToken(final String authId,
final SocialType socialType) {
final Long notVerifiedMemberId = memberService.findNotVerifiedMemberIdBy(authId,
Expand Down Expand Up @@ -78,12 +56,12 @@ public TokenDto validVerificationMessage(
final String certificationNumber,
final String receiver
) {
final byte[] plain = receiver.getBytes(StandardCharsets.UTF_8);
final byte[] phoneBytes = receiver.getBytes(StandardCharsets.UTF_8);

messageVerificationService.validVerificationMessage(memberId,
certificationNumber, plain);
certificationNumber, phoneBytes);

Long verifiedMemberId = memberService.updateVerifiedMember(memberId, plain);
Long verifiedMemberId = memberService.updateVerifiedMember(memberId, phoneBytes);

return tokenManager.createNewToken(verifiedMemberId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public record MemberDetailDto(
String profileUrl,
String tag,
SocialType socialType,
String email,
ByteArrayWrapper email,
ByteArrayWrapper phone,
Long friendCount,
Long groupCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ public record SignUpRequestDto(
SocialType socialType
) {

public MemberTemporary toMemberTemporary(final String tag) {
public MemberTemporary toMemberTemporary(final String tag, final byte[] email,
final byte[] emailHash) {
return MemberTemporary.builder()
.authId(authId)
.nickname(MakeRandomNickNameUtil.makeRandomNickName())
.email(email)
.profileUrl(profileUrl)
.socialType(socialType)
.tag(tag)
.email(email)
.emailHash(emailHash)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public record MemberDetailResponse(

public static MemberDetailResponse createOf(
final MemberDetailDto detailDto,
final Function<byte[], String> phoneDecryption
final Function<byte[], String> aesEncryptionManager
) {
return new MemberDetailResponse(
detailDto.nickname(),
detailDto.profileUrl(),
detailDto.tag(),
detailDto.socialType(),
detailDto.email(),
phoneDecryption.apply(detailDto.phone().data()),
aesEncryptionManager.apply(detailDto.email().data()),
aesEncryptionManager.apply(detailDto.phone().data()),
detailDto.friendCount(),
detailDto.groupCount(),
detailDto.tagSearchAvailable(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Email;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -17,7 +16,6 @@
import org.hibernate.annotations.Where;
import site.timecapsulearchive.core.global.entity.BaseEntity;
import site.timecapsulearchive.core.global.util.NullCheck;
import site.timecapsulearchive.core.global.util.TagGenerator;

@Entity
@Table(name = "member")
Expand Down Expand Up @@ -51,9 +49,11 @@ public class Member extends BaseEntity {
@Column(name = "notification_enabled", nullable = false)
private Boolean notificationEnabled;

@Email
@Column(name = "email", nullable = false)
private String email;
private byte[] email;

@Column(name = "email_hash", nullable = false)
private byte[] emailHash;

@Column(name = "fcm_token")
private String fcmToken;
Expand All @@ -80,23 +80,22 @@ public class Member extends BaseEntity {
private Boolean phoneSearchAvailable = Boolean.FALSE;

@Builder
private Member(String profileUrl, String nickname, SocialType socialType, String email,
String authId, String password, String tag, byte[] phone, byte[] phoneHash) {
private Member(String profileUrl, String nickname, SocialType socialType,
String authId, String password, String tag, byte[] phone, byte[] phoneHash,
byte[] email, byte[] emailHash
) {
this.profileUrl = NullCheck.validate(profileUrl, "Entity: profile");
this.nickname = NullCheck.validate(nickname, "Entity: nickname");
this.socialType = NullCheck.validate(socialType, "Entity: socialType");
this.email = NullCheck.validate(email, "Entity: email");
this.tag = NullCheck.validate(tag, "Entity: tag");
this.authId = NullCheck.validate(authId, "Entity: authId");
this.isVerified = true;
this.notificationEnabled = false;
this.password = password;
this.phone = phone;
this.phoneHash = phoneHash;
}

public void updateTagLowerCaseSocialType() {
this.tag = TagGenerator.lowercase(email, socialType);
this.email = email;
this.emailHash = emailHash;
}

public void updateData(String nickname, String tag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Email;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -17,7 +16,6 @@
import org.hibernate.annotations.Where;
import site.timecapsulearchive.core.global.entity.BaseEntity;
import site.timecapsulearchive.core.global.util.NullCheck;
import site.timecapsulearchive.core.global.util.TagGenerator;

@Entity
@Table(name = "member_temporary")
Expand All @@ -42,10 +40,6 @@ public class MemberTemporary extends BaseEntity {
@Enumerated(EnumType.STRING)
private SocialType socialType;

@Email
@Column(name = "email", nullable = false)
private String email;

@Column(name = "is_verified", nullable = false)
private Boolean isVerified;

Expand All @@ -55,13 +49,20 @@ public class MemberTemporary extends BaseEntity {
@Column(name = "tag", nullable = false, unique = true)
private String tag;

@Column(name = "email", nullable = false)
private byte[] email;

@Column(name = "email_hash", nullable = false)
private byte[] emailHash;

@Builder
public MemberTemporary(String profileUrl, String nickname, SocialType socialType, String email,
String authId, String tag) {
public MemberTemporary(String profileUrl, String nickname, SocialType socialType,
String authId, String tag, byte[] email, byte[] emailHash) {
this.profileUrl = NullCheck.validate(profileUrl, "Entity: profile");
this.nickname = NullCheck.validate(nickname, "Entity: nickname");
this.socialType = NullCheck.validate(socialType, "Entity: socialType");
this.email = NullCheck.validate(email, "Entity: email");
this.email = email;
this.emailHash = emailHash;
this.isVerified = false;
this.authId = NullCheck.validate(authId, "Entity: authId");
this.tag = NullCheck.validate(tag, "Entity: tag");
Expand All @@ -72,15 +73,12 @@ public Member toMember(final byte[] phoneHash, final byte[] phone) {
.profileUrl(profileUrl)
.nickname(nickname)
.socialType(socialType)
.email(email)
.authId(authId)
.tag(tag)
.phoneHash(phoneHash)
.phone(phone)
.emailHash(emailHash)
.email(email)
.build();
}

public void updateTagLowerCaseSocialType() {
this.tag = TagGenerator.lowercase(email, socialType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ public Optional<MemberDetailDto> findMemberDetailResponseDtoById(final Long memb
member.profileUrl,
member.tag,
member.socialType,
member.email,
Projections.constructor(
ByteArrayWrapper.class,
member.email
),
Projections.constructor(
ByteArrayWrapper.class,
member.phone
Expand Down
Loading

0 comments on commit 1c389e2

Please sign in to comment.