-
Notifications
You must be signed in to change notification settings - Fork 0
[Chanyeol] Week9 미션 #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
coconutcococode
wants to merge
8
commits into
main
Choose a base branch
from
Chanyeol-week9
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Chanyeol] Week9 미션 #101
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dd6187c
feat: 로그인 API 구현
coconutcococode 0caf0b8
feat: filter 생성
coconutcococode 8fd8afe
feat: 토큰 기반 내 정보 조회 API 추가
coconutcococode 0005c4c
feat: 토큰 기반 API 사용 방식 정리
coconutcococode a958fe7
refactor: 세션 로그인 핸들러 제거
coconutcococode d38caf1
refactor: JWT 인증 흐름 정리
coconutcococode 0d83014
feat: 카카오 OAuth 로그인 흐름 구현
coconutcococode dc566d1
docs: 9주차 핵심 키워드 추가
coconutcococode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| - 세션과 토큰의 차이는? | ||
|
|
||
| ## **Session (세션)** | ||
|
|
||
| 세션은 클라이언트의 인증 정보를 **서버 측에 저장하고 관리**하는 방식입니다. | ||
|
|
||
| 사용자가 로그인할 때, 서버는 사용자의 아이디, 권한, 만료 시간 등의 정보를 서버의 메모리, 데이터베이스, 또는 Redis 같은 캐시 저장소에 보관합니다. 그리고 이 정보를 식별할 수 있는 **고유한 Session ID**만 클라이언트(브라우저)에게 쿠키 형태로 전달합니다. | ||
|
|
||
| 클라이언트는 이후 요청마다 이 Session ID를 자동으로 서버에 보내고, 서버는 해당 ID를 통해 저장된 사용자 정보를 찾아 인증을 처리합니다. 즉, **서버가 클라이언트의 상태를 직접 관리**하기 때문에 **Stateful(상태 유지)** 방식이라고 합니다. | ||
|
|
||
| ### 장점 | ||
|
|
||
| - 민감한 정보(사용자 권한, 개인정보 등)를 클라이언트가 아닌 서버에 보관하여 비교적 안전하다. | ||
| - 세션을 서버에서 직접 삭제하면 **즉시 로그아웃** 처리(강제 로그아웃)가 가능하다. | ||
| - 토큰에 비해 데이터 크기가 작아 네트워크 부하가 적다. | ||
|
|
||
| ### 단점 | ||
|
|
||
| - 사용자가 증가하면 서버가 관리해야 할 세션 데이터가 많아져 **메모리 및 DB 부하**가 커진다. | ||
| - 서버를 여러 대로 확장(Scale-out)할 때, 세션 공유 문제가 발생한다. (세션 클러스터링, Sticky Session, Redis 등의 중앙 저장소 필요) | ||
| - 서버가 다운되면 모든 세션이 사라질 위험이 있다. | ||
|
|
||
| --- | ||
|
|
||
| ## **Token (토큰)** | ||
|
|
||
| 토큰은 인증에 성공한 클라이언트에게 서버가 발급해주는 **디지털 서명된 문자열**입니다. | ||
|
|
||
| 대표적으로 **JWT(JSON Web Token)**가 많이 사용되며, 이 토큰 안에 사용자 ID, 권한, 만료시간 등의 정보를 직접 포함하고 있습니다. 클라이언트는 이 토큰을 안전한 곳(보통 localStorage 또는 HttpOnly 쿠키)에 저장했다가, 이후 API 요청 시 Authorization: Bearer <token> 헤더에 담아 서버로 보냅니다. | ||
|
|
||
| 서버는 토큰의 **서명을 검증**하기만 하면 되며, 별도로 사용자 정보를 DB에서 조회할 필요가 없습니다. 즉, **서버가 클라이언트의 상태를 유지하지 않는 Stateless(무상태)** 방식입니다. | ||
|
|
||
| ### 장점 | ||
|
|
||
| - 서버가 세션 정보를 저장하지 않아 **서버 부하가 적고**, 확장성(Scale-out)이 뛰어나다. | ||
| - 마이크로 서비스, 모바일 앱, 외부 API 연동에 매우 적합하다. | ||
| - 토큰 자체에 필요한 정보를 모두 담고 있어 DB 조회 횟수가 줄어든다. | ||
|
|
||
| ### 단점 | ||
|
|
||
| - 토큰의 크기가 세션 ID보다 훨씬 커서, 요청이 많아질수록 **네트워크 트래픽이 증가**할 수 있다. | ||
| - 토큰이 탈취당하면 만료시간까지 유효하기 때문에 대처가 어렵다. (Refresh Token을 함께 사용하는 이유) | ||
| - 토큰을 무효화(강제 로그아웃)하기가 세션에 비해 복잡하다. (블랙리스트, 짧은 만료시간 + Refresh Token 조합 등으로 보완) | ||
| - 엑세스 토큰과 리프레시 토큰이란? | ||
|
|
||
| ## **Access Token (엑세스 토큰)** | ||
|
|
||
| Access Token은 클라이언트가 실제로 서버의 보호된 리소스(예: 사용자 정보 조회, 글 작성 등)에 접근할 때 사용하는 **짧은 수명의 토큰**입니다. | ||
|
|
||
| 주로 JWT 형식으로 발급되며, 사용자 ID, 권한(Role), 만료시간(expiration) 등의 정보를 포함하고 있습니다. 클라이언트는 이 토큰을 Authorization: Bearer <access_token> 헤더에 담아 API 요청을 보냅니다. 서버는 토큰의 서명만 검증하면 인증이 완료됩니다. | ||
|
|
||
| 일반적으로 **15분 ~ 1시간** 정도의 매우 짧은 유효 기간을 가집니다. | ||
|
|
||
| ### 장점 | ||
|
|
||
| - 유효 기간이 짧아 토큰이 탈취당하더라도 피해를 최소화할 수 있다. | ||
| - 서버가 별도의 세션 저장소를 필요로 하지 않아 **확장성**이 뛰어나다. | ||
| - 요청마다 빠르게 인증 처리 가능 (Stateless) | ||
|
|
||
| ### 단점 | ||
|
|
||
| - 자주 만료되므로, 만료될 때마다 다시 로그인해야 하는 문제가 발생할 수 있다. | ||
| - 만료 시마다 새로운 Access Token을 발급받아야 하므로, Refresh Token과 함께 사용해야 한다. | ||
| - 토큰 크기가 커서 네트워크 트래픽에 약간의 영향을 줄 수 있다. | ||
|
|
||
| --- | ||
|
|
||
| ## **Refresh Token (리프레시 토큰)** | ||
|
|
||
| Refresh Token은 **Access Token이 만료되었을 때**, 새로운 Access Token을 발급받기 위해 사용하는 **긴 수명의 토큰**입니다. | ||
|
|
||
| Access Token과 달리 사용자 정보를 많이 포함하지 않고, 주로 토큰 식별자나 사용자 ID 정도만 담습니다. 보안을 위해 보통 **HttpOnly 쿠키**에 저장하며, JavaScript에서 접근할 수 없도록 처리합니다. | ||
|
|
||
| 유효 기간은 보통 **7일 ~ 30일** 정도로 Access Token보다 훨씬 길게 설정합니다. Refresh Token을 이용해 Access Token을 갱신하는 과정을 **Token Refresh** 또는 **Silent Refresh**라고 합니다. | ||
|
|
||
| ### 장점 | ||
|
|
||
| - 사용자가 매번 재로그인하지 않고도 오랜 기간 로그인 상태를 유지할 수 있다. | ||
| - Access Token의 수명을 짧게 유지하면서도 사용자 편의성을 높일 수 있다. | ||
| - Refresh Token을 서버에서 관리(블랙리스트, Rotation)하면 보안성을 크게 강화할 수 있다. | ||
|
|
||
| ### 단점 | ||
|
|
||
| - 유효 기간이 길어 탈취당할 경우 피해가 크다. | ||
| - Refresh Token 자체를 안전하게 보관해야 하며, 탈취 방지를 위한 추가적인 보안 조치가 필요하다. | ||
| - 서버에서 Refresh Token을 무효화하거나 관리하는 로직이 추가로 필요하다. | ||
|
|
||
| --- | ||
|
|
||
| ### **현대적인 추천 방식 (Access + Refresh Token 조합)** | ||
|
|
||
| 1. 로그인 성공 시 → **Access Token + Refresh Token** 동시 발급 | ||
| 2. 클라이언트는 Access Token으로 API 호출 | ||
| 3. Access Token 만료 → Refresh Token으로 새로운 Access Token 요청 | ||
| 4. Refresh Token도 만료되면 → 다시 로그인 유도 | ||
|
|
||
| 이 방식은 **세션의 편의성**과 **토큰의 확장성**을 동시에 잡을 수 있는 현재 가장 많이 사용되는 아키텍처입니다. | ||
|
|
||
| - OAuth 1.0과 OAuth 2.0의 차이는? | ||
|
|
||
| ## **OAuth 1.0** | ||
|
|
||
| OAuth 1.0은 2007년에 발표된 최초의 OAuth 버전으로, **외부 애플리케이션이 사용자 대신 서버의 리소스에 안전하게 접근**할 수 있도록 설계된 인증 프로토콜입니다. | ||
|
|
||
| 사용자가 로그인하면 **Request Token** → **Access Token**으로 교환하는 복잡한 과정을 거칩니다. 가장 큰 특징은 **디지털 서명(Signature)**을 사용한다는 점입니다. 매 요청마다 HMAC-SHA1 등의 알고리즘으로 서명을 생성하여 전송합니다. | ||
|
|
||
| ### 장점 | ||
|
|
||
| - HTTPS를 필수로 요구하지 않아도 어느 정도 보안이 가능하다 (서명 기반). | ||
| - 서명이 포함되어 있어 토큰이 탈취당하더라도 요청 내용을 위변조하기 어렵다. | ||
| - 비교적 엄격한 보안 모델을 제공한다. | ||
|
|
||
| ### 단점 | ||
|
|
||
| - 구현이 매우 복잡하고 어렵다 (서명 생성, nonce, timestamp 등). | ||
| - 모바일 앱이나 JavaScript 환경에서 사용하기 불편하다. | ||
| - 토큰 만료와 갱신이 제대로 지원되지 않아 보안 및 사용자 경험이 떨어진다. | ||
| - 현재는 거의 사용되지 않을 정도로 구식이다. | ||
|
|
||
| --- | ||
|
|
||
| ## **OAuth 2.0** | ||
|
|
||
| OAuth 2.0은 2012년에 발표된 OAuth 1.0의 후속 버전으로, **현대 웹과 모바일 환경에 최적화**된 인증 프레임워크입니다. | ||
|
|
||
| OAuth 1.0의 복잡성을 크게 개선하여 **Bearer Token** 방식을 주로 사용합니다. 다양한 인증 방식(Grant Type)을 지원하며, Access Token + Refresh Token 조합을 표준적으로 활용합니다. | ||
|
|
||
| 대표적인 Grant Type으로는 Authorization Code, Implicit, Client Credentials, Password, Refresh Token 등이 있다. | ||
|
|
||
| ### 장점 | ||
|
|
||
| - 구현이 OAuth 1.0에 비해 훨씬 간단하고 직관적이다. | ||
| - HTTPS를 기반으로 하여 보안성을 강화하면서도 개발 편의성이 높다. | ||
| - 다양한 클라이언트 환경(웹, 모바일, 서버 간 통신)에 적합한 Grant Type을 제공한다. | ||
| - Access Token의 짧은 수명 + Refresh Token으로 보안과 편의성을 동시에 달성할 수 있다. | ||
| - 현재 대부분의 서비스(Google, Kakao, Naver, GitHub 등)가 OAuth 2.0을 사용한다. | ||
|
|
||
| ### 단점 | ||
|
|
||
| - Bearer Token을 사용하므로 토큰이 탈취당하면 즉시 악용될 위험이 있다 (HTTPS 필수). | ||
| - OAuth 1.0보다 서버 측에서 상태 관리를 더 신경 써야 하는 경우가 있다 (Refresh Token 관리). | ||
| - 잘못 구현하면 보안 취약점이 발생하기 쉽다 (예: Implicit Grant의 보안 문제). | ||
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JWT는 서명 검증만으로 토큰 자체의 무결성과 만료 여부를 확인할 수 있지만, 현재 구현처럼
JwtAuthFilter에서 이메일로CustomUserDetailsService를 다시 호출하면 매 요청마다 DB 조회가 발생할 수 있습니다. 학습 정리에는 "JWT 방식은 서버 세션 저장소가 필요하지 않지만, 구현에 따라 사용자 상태 확인을 위해 DB 조회를 병행할 수 있습니다"처럼 구분해 두는 것을 권장합니다.