From bf7c372e696eb6cec133345700efe7f04411ab9a Mon Sep 17 00:00:00 2001 From: min-0 Date: Mon, 19 Aug 2024 17:12:30 +0900 Subject: [PATCH] =?UTF-8?q?:art:=20=20AuthTokenController=20=EA=B5=AC?= =?UTF-8?q?=EC=A1=B0=20=EB=B0=8F=20=ED=98=95=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/controller/AuthTokenController.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/dnd/dndtravel/auth/controller/AuthTokenController.java b/src/main/java/com/dnd/dndtravel/auth/controller/AuthTokenController.java index d508762..d6f5b9f 100644 --- a/src/main/java/com/dnd/dndtravel/auth/controller/AuthTokenController.java +++ b/src/main/java/com/dnd/dndtravel/auth/controller/AuthTokenController.java @@ -2,37 +2,41 @@ import com.dnd.dndtravel.auth.apple.AppleOauthService; import com.dnd.dndtravel.auth.apple.dto.AppleUser; -import com.dnd.dndtravel.auth.domain.AuthToken; +import com.dnd.dndtravel.auth.config.JwtProvider; +import com.dnd.dndtravel.auth.repository.AuthTokenRepository; import com.dnd.dndtravel.auth.service.dto.request.AppleLoginRequest; import com.dnd.dndtravel.auth.service.dto.response.TokenResponse; -import com.dnd.dndtravel.auth.service.AuthTokenService; import com.dnd.dndtravel.member.domain.Member; import com.dnd.dndtravel.member.service.MemberService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.ResponseEntity; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -@Slf4j +import java.util.Collections; + @RequiredArgsConstructor -@RequestMapping("/api") @RestController public class AuthTokenController { - private final AuthTokenService authTokenService; - private final MemberService memberService; - private final AppleOauthService appleOauthService; + private final JwtProvider jwtProvider; + private final AuthTokenRepository authTokenRepository; @PostMapping("/login/oauth2/apple") - public ResponseEntity appleOauthLogin(@RequestBody final AppleLoginRequest appleLoginRequest) { + public TokenResponse appleOauthLogin(@RequestBody final AppleLoginRequest appleLoginRequest) { AppleUser appleUser = appleOauthService.createAppleUser(appleLoginRequest.getAppleToken()); Member member = memberService.saveMember(appleUser); - AuthToken authToken = authTokenService.issue(member); - return ResponseEntity.ok(new TokenResponse(authToken)); + + Authentication authentication = new UsernamePasswordAuthenticationToken(member.getId(), null, Collections.emptyList()); + String accessToken = jwtProvider.createToken(authentication); + String refreshToken = jwtProvider.createRefreshToken(member.getId()); + authTokenRepository.saveRefreshToken(member.getId(), refreshToken); // refreshToken은 DB에 저장 + + return new TokenResponse(accessToken); } -} +} \ No newline at end of file