2828import jakarta .servlet .http .HttpSession ;
2929import jakarta .validation .Valid ;
3030import lombok .RequiredArgsConstructor ;
31+ import lombok .extern .slf4j .Slf4j ;
3132import org .springframework .web .bind .annotation .*;
3233import org .springframework .beans .factory .annotation .Value ;
3334import org .springframework .web .util .UriComponentsBuilder ;
4445@ RestController
4546@ RequestMapping ("/auth" )
4647@ RequiredArgsConstructor
48+ @ Slf4j
4749public class OAuth2AuthController {
4850 private static final String preSignupIdCookieName = "pre_signup_id" ;
4951 private final OAuth2LoginService oauth2LoginService ;
@@ -91,10 +93,7 @@ public DataResponseDto<Void> signup(@Valid @RequestBody SignupRequest signupRequ
9193 public void authorize (@ RequestParam ("provider" ) ProviderType providerType ,
9294 @ RequestParam ("redirect" ) String redirectFront , HttpSession session ,
9395 HttpServletResponse response ) throws IOException {
94- List <String > origins = Arrays .stream (corsProperties .getAllowedOrigins ().split ("," ))
95- .map (String ::trim )
96- .filter (s -> !s .isBlank ())
97- .toList ();
96+ List <String > origins = corsProperties .getAllowedOrigins ();
9897
9998 if (origins .stream ().noneMatch (redirectFront ::startsWith )) {
10099 response .sendError (400 , "invalid front url" );
@@ -121,6 +120,8 @@ public void oauth2Callback(
121120 OauthValidateUtil .validateState (request , state );
122121 OAuthLoginResponse oauthLoginResponse = oauth2LoginService .processOAuth2Callback (providerType , code , state );
123122
123+ log .info ("[OAuth Controller] Callback Service 정상 실행 - status: {}" , oauthLoginResponse .getStatus ());
124+
124125 if (oauthLoginResponse .getStatus () == SignStatus .EXISTING_USER ) { //기존유저 - RefreshToken 및 DiviceId만 쿠키에 포함해서 리다이렉트
125126 queryService .setLoginCookie (request , response , oauthLoginResponse );
126127 } else if (oauthLoginResponse .getStatus () == SignStatus .SIGNUP_REQUIRED ) { //신규유저 - preSignupUd를 쿠키에 포함해서 리다이렉트
@@ -129,14 +130,24 @@ public void oauth2Callback(
129130 throw new GeneralException (Code .BAD_REQUEST );
130131 }
131132
133+ log .info ("[OAuth Controller] 쿠키 셋팅 완료" );
134+
132135 //https://{프론트}/auth?status={}'으로 redirect
133136 HttpSession session = request .getSession ();
134137 String redirectFront = (String ) session .getAttribute ("redirect_front" );
135- if (redirectFront == null || corsProperties .getAllowedOrigins ().lines ().noneMatch (redirectFront ::startsWith )) {
138+ log .info ("[OAuth Controller] redirectFront : {}" , redirectFront );
139+ log .info ("Allowed origins list:" );
140+ List <String > origins = corsProperties .getAllowedOrigins ();
141+ for (String str : origins ) log .info ("-> {}" ,str );
142+
143+ log .info ("true or false : {}, {}" ,redirectFront == null , !origins .contains (redirectFront ));
144+ if (redirectFront == null || !origins .contains (redirectFront )) {
136145 response .sendError (400 , "invalid redirect front url" );
137146 return ;
138147 }
139148
149+ log .info ("[OAuth Controller] 리다이렉트 셋팅하기" );
150+
140151 session .removeAttribute ("redirect_front" );
141152 session .removeAttribute ("oauth2_state" );
142153
@@ -147,6 +158,7 @@ public void oauth2Callback(
147158 .build ()
148159 .toUriString ();
149160
161+ log .info ("[OAuth Controller] 리다이렉트 꼬" );
150162 response .sendRedirect (frontUrl );
151163 }
152164
0 commit comments