Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 소셜 로그인 정보 조회하기 기능 구현 #220

Merged
merged 7 commits into from
Jan 24, 2024

Conversation

uwoobeat
Copy link
Member

@uwoobeat uwoobeat commented Jan 24, 2024

🌱 관련 이슈

📌 작업 내용 및 특이사항

  • 멤버 테이블에 oauth_email 필드 추가해서 이메일 정보 저장되도록 함
  • id_token에서 이미 이메일 담아 보내주기 때문에 oidcUser에서 getEmail() 만 해주면 됨
  • 소셜 로그인 정보가 아예 없는 경우 jpa가 임베디드 타입을 null로 매핑해주므로, DTO 변환 시 NPE 회피하기 위해 validate 로직 추가해줌
  • 일부만 있는 경우 다음과 같이 검증함
    • 응답으로 OauthProvider enum을 직접 내려줌 (e.g. "provider": "KAKAO")
    • 이때 멤버 테이블의 oauth_provider에는 id_token의 issuer가 저장되는데, of 로 순회하면서 issuer로 프로바이더 enum을 결정함
    • 따라서 각 멤버가 어떤 프로바이더에 해당하는 지 결정할 수 있음
  • 테스트 코드 작성함. 테스트 코드 참고하면 로직 이해하는데 도움이 될듯 합니다

📝 참고사항

📚 기타

@uwoobeat uwoobeat requested review from kdomo and char-yb January 24, 2024 14:19
@uwoobeat uwoobeat self-assigned this Jan 24, 2024
Copy link

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

44 New issues
0 Security Hotspots
49.1% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Member

@kdomo kdomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

카카오는 확인했는데 애플의 경우에도 이메일이 항상 넘어오는지만 확인 부탁드립니당
고생하셨어용🙇🏻

Comment on lines +44 to +53
private void saveAndRegisterMember(OauthInfo oauthInfo) {
Member member = Member.createGuestMember(oauthInfo, "testNickname");
memberRepository.save(member);
member.register("testNickname");
PrincipalDetails principalDetails = new PrincipalDetails(1L, "USER");
Authentication authentication =
new UsernamePasswordAuthenticationToken(
principalDetails, null, principalDetails.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요렇게 메소드로 만들어두니까 깔끔하네용

Comment on lines +22 to +26
return Arrays.stream(values())
.filter(oauthProvider -> oauthProvider.issuer.equals(issuer))
.findFirst()
.orElseThrow(() -> new CustomException(ErrorCode.OAUTH_PROVIDER_NOT_FOUND));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Comment on lines +62 to +66
private void validateSocialInfoNotNull(Member member) {
if (member.getOauthInfo() == null) {
throw new CustomException(ErrorCode.MEMBER_SOCIAL_INFO_NOT_FOUND);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@uwoobeat
Copy link
Member Author

카카오는 확인했는데 애플의 경우에도 이메일이 항상 넘어오는지만 확인 부탁드립니당 고생하셨어용🙇🏻

애플 이메일 id token으로 넘어오는거 체크했습니다 감사용

@uwoobeat uwoobeat merged commit b9e0d04 into develop Jan 24, 2024
3 checks passed
@uwoobeat uwoobeat deleted the feature/213-social-info branch January 24, 2024 14:35
@github-actions github-actions bot added the merged 머지된 PR label Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged 머지된 PR
Projects
Status: 완료
Development

Successfully merging this pull request may close these issues.

✨ 소셜 로그인 정보 조회하기 기능 구현
2 participants