99import com .example .solidconnection .auth .dto .SignUpRequest ;
1010import com .example .solidconnection .auth .dto .oauth .OAuthCodeRequest ;
1111import com .example .solidconnection .auth .dto .oauth .OAuthResponse ;
12+ import com .example .solidconnection .auth .dto .oauth .OAuthSignInResponse ;
1213import com .example .solidconnection .auth .service .AuthService ;
1314import com .example .solidconnection .auth .service .CommonSignUpTokenProvider ;
1415import com .example .solidconnection .auth .service .EmailSignInService ;
2223import com .example .solidconnection .common .resolver .AuthorizedUser ;
2324import com .example .solidconnection .siteuser .domain .AuthType ;
2425import com .example .solidconnection .siteuser .domain .SiteUser ;
26+ import jakarta .servlet .http .HttpServletResponse ;
2527import jakarta .validation .Valid ;
2628import lombok .RequiredArgsConstructor ;
2729import org .springframework .http .ResponseEntity ;
@@ -45,28 +47,39 @@ public class AuthController {
4547 private final EmailSignUpService emailSignUpService ;
4648 private final EmailSignUpTokenProvider emailSignUpTokenProvider ;
4749 private final CommonSignUpTokenProvider commonSignUpTokenProvider ;
50+ private final RefreshTokenCookieManager refreshTokenCookieManager ;
4851
4952 @ PostMapping ("/apple" )
5053 public ResponseEntity <OAuthResponse > processAppleOAuth (
51- @ Valid @ RequestBody OAuthCodeRequest oAuthCodeRequest
54+ @ Valid @ RequestBody OAuthCodeRequest oAuthCodeRequest ,
55+ HttpServletResponse httpServletResponse
5256 ) {
5357 OAuthResponse oAuthResponse = appleOAuthService .processOAuth (oAuthCodeRequest );
58+ if (oAuthResponse instanceof OAuthSignInResponse signInResponse ) {
59+ refreshTokenCookieManager .setCookie (httpServletResponse , signInResponse .refreshToken ());
60+ }
5461 return ResponseEntity .ok (oAuthResponse );
5562 }
5663
5764 @ PostMapping ("/kakao" )
5865 public ResponseEntity <OAuthResponse > processKakaoOAuth (
59- @ Valid @ RequestBody OAuthCodeRequest oAuthCodeRequest
66+ @ Valid @ RequestBody OAuthCodeRequest oAuthCodeRequest ,
67+ HttpServletResponse httpServletResponse
6068 ) {
6169 OAuthResponse oAuthResponse = kakaoOAuthService .processOAuth (oAuthCodeRequest );
70+ if (oAuthResponse instanceof OAuthSignInResponse signInResponse ) {
71+ refreshTokenCookieManager .setCookie (httpServletResponse , signInResponse .refreshToken ());
72+ }
6273 return ResponseEntity .ok (oAuthResponse );
6374 }
6475
6576 @ PostMapping ("/email/sign-in" )
6677 public ResponseEntity <SignInResponse > signInWithEmail (
67- @ Valid @ RequestBody EmailSignInRequest signInRequest
78+ @ Valid @ RequestBody EmailSignInRequest signInRequest ,
79+ HttpServletResponse httpServletResponse
6880 ) {
6981 SignInResponse signInResponse = emailSignInService .signIn (signInRequest );
82+ refreshTokenCookieManager .setCookie (httpServletResponse , signInResponse .refreshToken ());
7083 return ResponseEntity .ok (signInResponse );
7184 }
7285
@@ -95,20 +108,24 @@ public ResponseEntity<SignInResponse> signUp(
95108
96109 @ PostMapping ("/sign-out" )
97110 public ResponseEntity <Void > signOut (
98- Authentication authentication
111+ Authentication authentication ,
112+ HttpServletResponse httpServletResponse
99113 ) {
100114 String accessToken = getAccessToken (authentication );
101115 authService .signOut (accessToken );
116+ refreshTokenCookieManager .deleteCookie (httpServletResponse );
102117 return ResponseEntity .ok ().build ();
103118 }
104119
105120 @ DeleteMapping ("/quit" )
106121 public ResponseEntity <Void > quit (
107122 @ AuthorizedUser SiteUser siteUser ,
108- Authentication authentication // todo: #299를 작업하며 인자를 (Authentication authentication)만 받도록 수정해야 함
123+ Authentication authentication , // todo: #299를 작업하며 인자를 (Authentication authentication)만 받도록 수정해야 함
124+ HttpServletResponse httpServletResponse
109125 ) {
110126 String accessToken = getAccessToken (authentication );
111127 authService .quit (siteUser , accessToken );
128+ refreshTokenCookieManager .deleteCookie (httpServletResponse );
112129 return ResponseEntity .ok ().build ();
113130 }
114131
0 commit comments