From 58a5a8567cdfa1e9ec45701ffbb4e0033c5ede81 Mon Sep 17 00:00:00 2001 From: yerim <86309538+yerimm99@users.noreply.github.com> Date: Mon, 19 Feb 2024 22:47:34 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20oauth2=20redirect=20uri?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aromanticcat/umcproject/security/SecurityConfig.java | 5 ++--- .../security/oauth/MyAuthenticationFailureHandler.java | 2 +- .../security/oauth/MyAuthenticationSuccessHandler.java | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/aromanticcat/umcproject/security/SecurityConfig.java b/src/main/java/aromanticcat/umcproject/security/SecurityConfig.java index 0449554..3d38c56 100644 --- a/src/main/java/aromanticcat/umcproject/security/SecurityConfig.java +++ b/src/main/java/aromanticcat/umcproject/security/SecurityConfig.java @@ -38,15 +38,14 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .and() .authorizeRequests() // 요청에 대한 인증 설정 .antMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-resources/**").permitAll() - .antMatchers("/", "/login/**", "/signUp", "/nangman-collection/", + .antMatchers("/", "/login", "/signUp", "/nangman-collection/", "/nangman-collection/{nangmanLetterId}/like", "/nangman-collection/{nangmanLetterId}").permitAll() - .antMatchers("/token/**", "/oauth2/**").permitAll() // 토큰 발급을 위한 경로는 모두 허용 + .antMatchers("/token/**").permitAll() // 토큰 발급을 위한 경로는 모두 허용 .antMatchers("/css/**", "/images/**", "/js/**", "/favicon.ico", "/h2-console/**").permitAll() .anyRequest().authenticated() // 그 외의 모든 요청은 인증이 필요하다. .and() .oauth2Login() // OAuth2 로그인 설정시작 - .loginPage("https://dev.nangmancat.shop/login") .userInfoEndpoint().userService(customOAuth2UserService) // OAuth2 로그인시 사용자 정보를 가져오는 엔드포인트와 사용자 서비스를 설정 .and() .failureHandler(oAuth2LoginFailureHandler) // OAuth2 로그인 실패시 처리할 핸들러를 지정해준다. diff --git a/src/main/java/aromanticcat/umcproject/security/oauth/MyAuthenticationFailureHandler.java b/src/main/java/aromanticcat/umcproject/security/oauth/MyAuthenticationFailureHandler.java index 1e47608..b0ebf41 100644 --- a/src/main/java/aromanticcat/umcproject/security/oauth/MyAuthenticationFailureHandler.java +++ b/src/main/java/aromanticcat/umcproject/security/oauth/MyAuthenticationFailureHandler.java @@ -16,7 +16,7 @@ public class MyAuthenticationFailureHandler implements AuthenticationFailureHand public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { // 인증 실패시 메인 페이지로 이동 - response.sendRedirect("https://dev.nangmancat.shop/"); + response.sendRedirect("http://localhost:3000/"); } } diff --git a/src/main/java/aromanticcat/umcproject/security/oauth/MyAuthenticationSuccessHandler.java b/src/main/java/aromanticcat/umcproject/security/oauth/MyAuthenticationSuccessHandler.java index 330f2e6..fc63dbd 100644 --- a/src/main/java/aromanticcat/umcproject/security/oauth/MyAuthenticationSuccessHandler.java +++ b/src/main/java/aromanticcat/umcproject/security/oauth/MyAuthenticationSuccessHandler.java @@ -48,8 +48,8 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo log.info("jwtToken = {}", token.getAccessToken()); // accessToken을 쿼리스트링에 담는 url을 만들어준다. - String targetUrl = UriComponentsBuilder.fromUriString("https://dev.nangmancat.shop/") - .queryParam("accessToken", token.getAccessToken()) + String targetUrl = UriComponentsBuilder.fromUriString("http://localhost:3000/") +// .queryParam("accessToken", token.getAccessToken()) .build() .encode(StandardCharsets.UTF_8) .toUriString(); @@ -72,7 +72,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo } else { // 회원이 존재하지 않을경우, 서비스 제공자와 email을 쿼리스트링으로 전달하는 url을 만들어준다. - String targetUrl = UriComponentsBuilder.fromUriString("https://dev.nangmancat.shop/signUp") + String targetUrl = UriComponentsBuilder.fromUriString("http://localhost:3000/CreateAccount") .queryParam("email", (String) oAuth2User.getAttribute("email")) .queryParam("provider", provider) .build()