redirect_uri(예: http://localhost:8080/login/oauth2/code/google)로 인증 코드가 쿼리 파라미터로 담긴 채 리다이렉트됩니다[5][4].http://localhost:8080/login/oauth2/code/google 경로는 별도의 컨트롤러나 매핑을 만들 필요 없이/, /home 등).OAuth2SuccessHandler를 커스터마이즈해서 defaultSuccessUrl 등을 지정할 수 있습니다[3]./login/oauth2/code/google 경로에 컨트롤러를 직접 매핑하지 않습니다.@GetMapping 등으로 컨트롤러를 만들어서 RestTemplate 등으로 https://oauth2.googleapis.com/token 호출)하고 http://localhost:8080/login/oauth2/code/google 경로는 Spring Security가 자동으로 처리합니다.OAuth2SuccessHandler를 커스터마이즈하세요[3].결론:
Spring Security OAuth2 Client를 사용하면, 인증 코드가 담긴 URL로 리다이렉트된 후 자동으로 인증 및 로그인 처리가 되고, 원하는 페이지로 이동시킬 수 있습니다.
별도의 컨트롤러나 매핑을 만들 필요 없으며, 커스터마이즈가 필요하다면OAuth2SuccessHandler를 활용하세요.[1][3][5]
Citations:
[1] https://docs.spring.io/spring-security/reference/servlet/oauth2/client/authorization-grants.html
[2] https://www.javainuse.com/spring/spring-boot-oauth-authorization-code
[3] https://www.baeldung.com/spring-security-5-oauth2-login
[4] https://dzone.com/articles/authorization-code-grant-flow-with-spring-security
[5] https://developers.google.com/identity/protocols/oauth2/web-server
[6] https://spring.io/guides/tutorials/spring-boot-oauth2
[7] https://community.auth0.com/t/redirect-issue-in-spring-security-oauth2-login-flow/119388
[8] https://docs.spring.io/spring-security/reference/servlet/oauth2/login/advanced.html
[9] https://stackoverflow.com/questions/77295008/how-to-extract-access-token-from-oauth2-flow-in-spring-boot-client
[10] https://docs.spring.io/spring-security/site/docs/5.2.12.RELEASE/reference/html/oauth2.html
[11] https://www.youtube.com/watch?v=LM_Bnhf26Ew
[12] https://stackoverflow.com/questions/54101502/how-change-the-default-spring-boot-oauth-urls-login-oauth2-code-and-oauth2-au
[13] https://stackoverflow.com/questions/77222406/how-do-i-create-a-custom-redirect-controller-for-spring-boot-2-using-oauth2-clie
Answer from Perplexity: pplx.ai/share