기존에 Spring Security OAuth에 대해서는 알고 있었으나 실제 사용해 본적은 없었다. 또 OAuth에 대해 정확한 개념을 모르다보니 우선 OAuth의 매커니즘에 대해 이해하고 스프링 시큐리티 기본 기능을 이용해 로그인 기능 구현을 최대한 간단히 하고자 하였다. -> 나중에 큰 고통을 받음
프로젝트 초반에 먼저 OAuth2.0의 개념을 확실히 잡고자 하였다. OAuth2.0(Open Authorization 2.0)의 핵심은 Third-party application(이 경우 나의 애플리케이션)이 자원 소유자(사용자)의 자원에 필요한 만큰만 접근할 수 있게 하는 것이다.
- Third-party applications are required to store the resource
owner's credentials for future use, typically a password in
clear-text.- Third-party applications gain overly broad access to the resource
owner's protected resources, leaving resource owners without any
ability to restrict duration or access to a limited subset of
resources
OAuth2.0의 흐름
스프링 시큐리티에서는 1, 2 과정을 OAuth2AuthorizationRequestRedirectFilter
가 처리하며 이때 기본으로 세팅된 url은 /oauth2/authorization/{registrationId}
이다.
이후 과정은 OAuth2LoginAuthenticationFilter
가 처리하는데, 이때 6번에 사용되는 redirect url은 기본적으로 /login/oauth2/code/{registrationId}
이다.
기존에 Spring Security를 어느정도 사용해봤기 때문에 OAuth2UserService, OAuth2User만 구현하면 된다고 생각했으나....
/login/oauth2/code/{registrationId}
을 지정하면 되지 않을까 싶었으나...Before Chrome 80, cookies were sent with cross-site requests by default, regardless of whether the request was made over HTTP or HTTPS. This could potentially lead to security vulnerabilities and cross-site request forgery (CSRF) attacks.
- SameSite=None; Secure: If a cookie has the SameSite=None; Secure attribute, it will be sent with cross-site requests made from both HTTP and HTTPS origins. This is usually used for cookies that are intended to be used by third-party services or widgets embedded on other sites.
- SameSite=Lax: If a cookie has the SameSite=Lax attribute, it will be sent with cross-site requests made from HTTPS origins, but not from HTTP origins. This is a more secure default behavior that helps prevent certain types of CSRF attacks.
- SameSite=Strict: If a cookie has the SameSite=Strict attribute, it will not be sent with any cross-site requests.