From 2601d1c0f717c557ae860ca44eea041940cc36e1 Mon Sep 17 00:00:00 2001 From: gkfktkrh153 Date: Sat, 23 Mar 2024 11:57:55 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EC=87=BC=EC=85=9C=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=ED=9B=84=20User=EC=A0=95=EB=B3=B4=20=EB=81=8C?= =?UTF-8?q?=EC=96=B4=EB=8B=A4=EC=93=B0=EB=8F=84=EB=A1=9D=20=EC=9E=84?= =?UTF-8?q?=EC=8B=9C=EB=B0=A9=ED=8E=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/controller/MemberController.java | 7 ++++++- .../farmingsoon/domain/member/service/MemberService.java | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/api/farmingsoon/domain/member/controller/MemberController.java b/src/main/java/com/api/farmingsoon/domain/member/controller/MemberController.java index 800c6fc..c1e4710 100644 --- a/src/main/java/com/api/farmingsoon/domain/member/controller/MemberController.java +++ b/src/main/java/com/api/farmingsoon/domain/member/controller/MemberController.java @@ -54,5 +54,10 @@ public Response rotateToken(HttpServletRequest request, HttpServletRespons log.info(refreshToken); return Response.success(HttpStatus.OK, "토큰이 재발급 되었습니다."); } - + @LoginChecking + @GetMapping("/info") + public Response getUserInfo(){ + memberService.getUserInfo(); + return Response.success(HttpStatus.OK, "토큰이 재발급 되었습니다."); + } } diff --git a/src/main/java/com/api/farmingsoon/domain/member/service/MemberService.java b/src/main/java/com/api/farmingsoon/domain/member/service/MemberService.java index a79a3ad..21a60fb 100644 --- a/src/main/java/com/api/farmingsoon/domain/member/service/MemberService.java +++ b/src/main/java/com/api/farmingsoon/domain/member/service/MemberService.java @@ -5,6 +5,7 @@ import com.api.farmingsoon.common.exception.custom_exception.NotFoundException; import com.api.farmingsoon.common.security.jwt.JwtProvider; import com.api.farmingsoon.common.security.jwt.JwtToken; +import com.api.farmingsoon.common.util.AuthenticationUtils; import com.api.farmingsoon.common.util.CookieUtils; import com.api.farmingsoon.common.util.JwtUtils; import com.api.farmingsoon.common.util.Transaction; @@ -18,6 +19,7 @@ import com.api.farmingsoon.domain.member.event.TokenRotateEvent; import com.api.farmingsoon.domain.member.model.Member; import com.api.farmingsoon.domain.member.repository.MemberRepository; +import com.nimbusds.openid.connect.sdk.UserInfoResponse; import io.lettuce.core.RedisCommandTimeoutException; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; @@ -29,6 +31,7 @@ import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -150,4 +153,9 @@ public Member getMemberById(Long memberId) { return memberRepository.findById(memberId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MEMBER)); } + public LoginResponse getUserInfo() { + String userEmail = SecurityContextHolder.getContext().getAuthentication().getName(); + Member member = memberRepository.findByEmail(userEmail).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MEMBER)); + return LoginResponse.of(member); + } } From d8a104ae0d7b75372aebe54da38a9dd0477fa3ce Mon Sep 17 00:00:00 2001 From: gkfktkrh153 Date: Sat, 23 Mar 2024 12:03:09 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=8B=9C=20redirect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmingsoon/common/security/oauth/OAuthSuccessHandler.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/api/farmingsoon/common/security/oauth/OAuthSuccessHandler.java b/src/main/java/com/api/farmingsoon/common/security/oauth/OAuthSuccessHandler.java index ecab91c..cb10433 100644 --- a/src/main/java/com/api/farmingsoon/common/security/oauth/OAuthSuccessHandler.java +++ b/src/main/java/com/api/farmingsoon/common/security/oauth/OAuthSuccessHandler.java @@ -71,5 +71,6 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo response.getWriter().write( objectMapper.writeValueAsString(LoginResponse.of(member)) ); + response.sendRedirect("https://farmingsoon.site/"); } }