Skip to content
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 @@ -18,6 +18,7 @@
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

@Slf4j
@Service
Expand Down Expand Up @@ -57,6 +58,7 @@ public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2Authenticatio

OauthProvider oauthProvider = OauthProvider.valueOf(provider.toUpperCase());
OauthInfo oauthInfo = OauthInfo.createOauthInfo(oauthId, oauthProvider);
String resolvedEmail = resolveEmail(email, oauthId, oauthProvider);

log.info("[OIDC] 회원 조회 시작 - Provider: {}, OAuthId: {}", provider, oauthId);
Member member =
Expand All @@ -70,7 +72,7 @@ public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2Authenticatio
email);
Member newMember =
Member.createMember(
email,
resolvedEmail,
uniqueUtil.generateRandomNickname(),
oauthInfo);
memberRepository.save(newMember);
Expand Down Expand Up @@ -112,4 +114,23 @@ public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2Authenticatio
throw new OAuth2AuthenticationException(oauth2Error, e);
}
}

private String resolveEmail(String email, String oauthId, OauthProvider oauthProvider) {
if (StringUtils.hasText(email)) {
return email;
}

String safeOauthId = oauthId.replaceAll("[^a-zA-Z0-9._-]", "_");
if (safeOauthId.length() > 80) {
safeOauthId = safeOauthId.substring(0, 80);
}
String fallbackEmail =
oauthProvider.name().toLowerCase() + "_" + safeOauthId + "@noemail.local";
log.warn(
"[OIDC] Email claim missing. Fallback email is used - Provider: {}, OAuthId: {}, FallbackEmail: {}",
oauthProvider,
oauthId,
fallbackEmail);
return fallbackEmail;
}
}
1 change: 1 addition & 0 deletions clokey-api/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ spring:
client-authentication-method: client_secret_post
scope:
- openid
- email
provider: apple
provider:
kakao:
Expand Down
1 change: 1 addition & 0 deletions clokey-api/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ spring:
client-authentication-method: client_secret_post
scope:
- openid
- email
provider: apple
provider:
kakao:
Expand Down
1 change: 1 addition & 0 deletions clokey-api/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ spring:
client-authentication-method: client_secret_post
scope:
- openid
- email
provider: apple
provider:
kakao:
Expand Down