Skip to content

Commit

Permalink
fix: OAuth2 인증이 성공했을 때 사용자를 리다이렉트할 URL을 지정
Browse files Browse the repository at this point in the history
- http://localhost:3000/oauth2/callback
로 리다이렉트할 url 지정
- 프론트에서 code(인가코드)보내는 방식으로 변경
  • Loading branch information
khee2 committed Jul 28, 2024
1 parent 23372cf commit b5aa770
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
Expand Down Expand Up @@ -91,14 +93,17 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
// Spring Security에서 OAuth2 로그인을 설정
// OAuth2 인증이 성공적으로 완료된 후 리다이렉트할 URL을 설정
.oauth2Login(oauth2 -> oauth2
.defaultSuccessUrl("/api/auth/oauth2/code/kakao")
.successHandler(oauth2AuthenticationSuccessHandler())
);
// JWT 필터 추가
http.addFilterBefore(new JwtFilter(jwtTokenProvider), UsernamePasswordAuthenticationFilter.class);

return http.build();
}

@Bean
public AuthenticationSuccessHandler oauth2AuthenticationSuccessHandler() {
return new SimpleUrlAuthenticationSuccessHandler("http://localhost:3000/oauth2/callback");
}

/**
* CORS 설정 빈 등록
Expand Down

0 comments on commit b5aa770

Please sign in to comment.