-
Notifications
You must be signed in to change notification settings - Fork 1
[배포] KMC 회원, 카카오 중복 회원가입 에러 처리 #343
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package life.mosu.mosuserver.global.exception; | ||
|
|
||
| import org.springframework.security.core.AuthenticationException; | ||
|
|
||
| public class OAuthException extends AuthenticationException { | ||
|
|
||
| public OAuthException(String msg) { | ||
| super(msg); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package life.mosu.mosuserver.global.handler; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public enum OAuthErrorType { | ||
| CANCELED("CANCELED"), | ||
| DUPLICATE("DUPLICATE"), | ||
| UNKNOWN("UNKNOWN"); | ||
|
|
||
| private final String message; | ||
|
|
||
| OAuthErrorType(String message) { | ||
| this.message = message; | ||
| } | ||
|
|
||
| public static OAuthErrorType from(String text) { | ||
| if (text == null) { | ||
| return UNKNOWN; | ||
| } | ||
| return switch (text) { | ||
| case "DUPLICATE" -> DUPLICATE; | ||
| case "[access_denied] User denied access" -> CANCELED; | ||
| default -> UNKNOWN; | ||
| }; | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,11 @@ | ||||||||||||||
| package life.mosu.mosuserver.global.handler; | ||||||||||||||
|
|
||||||||||||||
| public record OAuthFailureResponse( | ||||||||||||||
| Boolean isProfileRegistered, | ||||||||||||||
| String errorCode | ||||||||||||||
| ) { | ||||||||||||||
|
|
||||||||||||||
| public static OAuthFailureResponse from(String errorCode) { | ||||||||||||||
| return new OAuthFailureResponse(null, errorCode); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+8
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| } | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재
from메소드는 예외 메시지 문자열"[access_denied] User denied access"에 직접 의존하고 있어, Spring Security 버전 변경 등에 따라 메시지가 바뀌면 코드가 오작동할 위험이 있습니다. 보다 안정적인 방법은OAuth2LoginFailureHandler에서exception객체의 타입을 확인하여OAuth2AuthenticationException인 경우getError().getErrorCode()를 통해access_denied와 같은 에러 코드를 얻어오고, 그 코드를 이from메소드에 전달하는 것입니다. 이렇게 하면 외부 라이브러리의 메시지 변경에 영향을 받지 않는 견고한 코드를 만들 수 있습니다.아래와 같이
from메소드를 수정하고,OAuth2LoginFailureHandler도 함께 수정하는 것을 권장합니다.OAuth2LoginFailureHandler.java수정 예시: