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

Fix: oauth 로그인 시 id token에 이메일 필드가 없는 경우 에러 타입 변경 #308

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ private String extractAndValidateEmail(Claims claim, SocialType socialType) {
String email = (String) claim.get("email");
if (StringUtils.isBlank(email)) {
log.warn("Failed to get email from idToken! type: {}, claim: {}", socialType, claim);
throw new AuthException(ErrorType.FAILED_AUTHENTICATION, "Failed to get email from idToken");
throw new AuthException(
ErrorType.EMAIL_NOT_FOUND_IN_ID_TOKEN, socialType + ": subject: " + claim.getSubject());
}
return email;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.dnd.runus.application.oauth;

import com.dnd.runus.auth.exception.AuthException;
import com.dnd.runus.domain.member.Member;
import com.dnd.runus.domain.member.MemberRepository;
import com.dnd.runus.domain.member.SocialProfile;
import com.dnd.runus.domain.member.SocialProfileRepository;
import com.dnd.runus.global.constant.MemberRole;
import com.dnd.runus.global.constant.SocialType;
import com.dnd.runus.global.exception.BusinessException;
import com.dnd.runus.global.exception.type.ErrorType;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -32,7 +32,7 @@ public SocialProfile findOrThrow(SocialType socialType, String oauthId, String e
SocialProfile socialProfile = socialProfileRepository
.findBySocialTypeAndOauthId(socialType, oauthId)
.orElseThrow(() ->
new BusinessException(ErrorType.SOCIAL_MEMBER_NOT_FOUND, socialType + ", oauthId: " + oauthId));
new AuthException(ErrorType.SOCIAL_MEMBER_NOT_FOUND, socialType + ", oauthId: " + oauthId));

updateEmailIfChanged(socialProfile, email);
return socialProfile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum ErrorType {

// OauthErrorType
SOCIAL_MEMBER_NOT_FOUND(NOT_FOUND, DEBUG, "OAUTH_001", "찾을 수 없는 소셜 회원입니다"),
EMAIL_NOT_FOUND_IN_ID_TOKEN(BAD_REQUEST, DEBUG, "OAUTH_002", "ID 토큰 필드에 이메일이 없습니다"),

// DatabaseErrorType
ENTITY_NOT_FOUND(NOT_FOUND, DEBUG, "DB_001", "해당 엔티티를 찾을 수 없습니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class OauthController {
@ApiErrorType({
ErrorType.UNSUPPORTED_SOCIAL_TYPE,
ErrorType.SOCIAL_MEMBER_NOT_FOUND,
ErrorType.EMAIL_NOT_FOUND_IN_ID_TOKEN,
ErrorType.FAILED_AUTHENTICATION,
ErrorType.UNSUPPORTED_JWT_TOKEN
})
Expand Down