|
17 | 17 | import jakarta.servlet.http.HttpServletResponse; |
18 | 18 | import jakarta.servlet.http.HttpSession; |
19 | 19 | import jakarta.validation.Valid; |
20 | | -import java.util.List; |
21 | 20 | import java.util.Map; |
22 | 21 | import lombok.RequiredArgsConstructor; |
23 | 22 | import org.springframework.http.HttpStatus; |
24 | | -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
25 | | -import org.springframework.security.core.Authentication; |
26 | 23 | import org.springframework.security.core.annotation.AuthenticationPrincipal; |
27 | | -import org.springframework.security.core.authority.SimpleGrantedAuthority; |
28 | | -import org.springframework.security.core.context.SecurityContext; |
29 | 24 | import org.springframework.security.core.context.SecurityContextHolder; |
30 | | -import org.springframework.security.web.context.HttpSessionSecurityContextRepository; |
31 | 25 | import org.springframework.web.bind.annotation.GetMapping; |
32 | 26 | import org.springframework.web.bind.annotation.PostMapping; |
33 | 27 | import org.springframework.web.bind.annotation.RequestBody; |
@@ -64,31 +58,24 @@ public Map<String, AuthTokenResponse> kakaoLogin( |
64 | 58 |
|
65 | 59 | @Operation( |
66 | 60 | summary = "비회원 로그인", |
67 | | - description = "닉네임을 입력하면 비회원 세션이 생성되고 인증이 설정됩니다. 이후 모든 요청에 세션 인증이 적용됩니다.", |
68 | 61 | responses = { |
69 | 62 | @ApiResponse(responseCode = "201", description = "비회원 로그인 성공"), |
70 | 63 | @ApiResponse(responseCode = "400", description = "닉네임 누락 또는 유효성 검증 실패") |
71 | 64 | } |
72 | 65 | ) |
73 | 66 | @PostMapping("/guest") |
74 | 67 | @ResponseStatus(HttpStatus.CREATED) |
75 | | - public SessionInfoResponse guestLogin(@RequestBody @Valid GuestLoginRequest guestLoginRequest, |
76 | | - HttpServletRequest request) { |
77 | | - MemberDetails guest = authService.loadGuest(guestLoginRequest); |
| 68 | + public Map<String, AuthTokenResponse> guestLogin( |
| 69 | + @RequestBody @Valid GuestLoginRequest guestLoginRequest, |
| 70 | + HttpServletResponse response) { |
| 71 | + LoginResponse loginResponse = authService.loadGuest(guestLoginRequest); |
78 | 72 |
|
79 | | - Authentication authentication = new UsernamePasswordAuthenticationToken( |
80 | | - guest, null, List.of(new SimpleGrantedAuthority(guest.getRole())) |
81 | | - ); |
82 | | - |
83 | | - SecurityContext context = SecurityContextHolder.createEmptyContext(); |
84 | | - context.setAuthentication(authentication); |
85 | | - SecurityContextHolder.setContext(context); |
| 73 | + String refreshToken = loginResponse.refreshToken(); |
86 | 74 |
|
87 | | - request.getSession(true) |
88 | | - .setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, |
89 | | - context); |
| 75 | + JwtUtils.addRefreshTokenCookie(response, refreshToken, |
| 76 | + loginResponse.refreshTokenExpiresIn()); |
90 | 77 |
|
91 | | - return toSessionInfoResponse(guest); |
| 78 | + return Map.of("token", loginResponse.authTokenResponse()); |
92 | 79 | } |
93 | 80 |
|
94 | 81 | @Operation( |
|
0 commit comments