JWT + OAuth 2

김준영·2023년 5월 18일
2

Code States

목록 보기
25/33

Frontend와 Backend 간의 OAuth 2 인증 처리 흐름


  1. Resource Owner가 웹 브라우저에서 Google 로그인 링크를 클릭.

  2. Frontend 애플리케이션에서 Backend 애플리케이션의 http://localhost:8080/oauth2/authorization/google로 request를 전송. -> 이 URI의 request는 OAuth2LoginAuthenticationFilter가 처리.

  3. Google의 로그인 화면을 요청하는 URI로 리다이렉트합니다. 이때 Authorization Server가 Backend 애플리케이션 쪽으로 Authorizaiton Code를 전송할 Redirect URI(http://localhost:8080/oauth2/authorization/google)를 쿼리 파라미터로 전달합니다. Redirect URI는 Spring Security가 내부적으로 제공합니다.

  4. Google 로그인 화면을 오픈.

  5. Resource Owner가 Google 로그인 인증 정보를 입력해서 로그인을 수행합니다.

  6. 로그인에 성공하면 (3)에서 전달한 Backend Redirect URI(http://localhost:8080/oauth2/authorization/google)로 Authorization Code를 요청합니다.

  7. Authorization Server가 Backend 애플리케이션에게 Authorization Code를 응답으로 전송합니다.

  8. Backend 애플리케이션이 Authorization Server에 Access Token을 요청합니다.

  9. Authorization Server가 Backend 애플리케이션에게 Access Token을 응답으로 전송합니다.

  10. Backend 애플리케이션은 JWT로 구성된 Access Token과 Refresh Token을 생성한 후, Frontend 애플리케이션에 JWT를 전달하기 위해 Frontend 애플리케이션 (http://localhost?access_token={jwt-access-token}&refresh_token={jwt-refresh-token})으로 Redirect합니다.

⭐ 동작 흐름이 아주 복잡해 보이지만 (6)부터 (11)까지는 Spring Security에서 내부적으로 알아서 처리해 주기 때문에 기본적으로는 우리가 건드릴 필요가 없습니다.

profile
ㅎㅎ

0개의 댓글