-
Notifications
You must be signed in to change notification settings - Fork 0
[Hyeonu] Week9 미션 #99
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
base: Hyeonu
Are you sure you want to change the base?
Changes from all commits
7b6dd04
591549d
90074ba
eae3b62
bf625a0
d1fdf40
f4e8c49
34b76bb
be1f287
89f89d7
272e7a1
462e5ac
5941632
23e31fe
72b1311
1d669cf
b36f639
2a4f073
b115f9b
23936bd
d35a759
fa60ede
e114058
5f3909f
d788e2b
0bd8310
db73402
cf7a1ab
03dbccc
4af0329
fcfbf0c
5592953
50c9b0d
48a7b66
7f558a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,3 +39,5 @@ out/ | |
|
|
||
| ### VS Code ### | ||
| .vscode/ | ||
| # 인텔리제이 모듈 설정 파일 무시 | ||
| *.xml | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| - 세션과 토큰의 차이는? | ||
|
|
||
| | 구분 | 세션 기반 인증 | 토큰 기반 인증 | | ||
| | --- | --- | --- | | ||
| | 인증 정보 저장 위치 | 서버 |클라이언트(브라우저/앱) | | ||
| | 상태 유지 | Stateful(상태 유지) | Stateless(상태 없음) | | ||
| | 인증 방식 | 서버가 세션 ID 기억 | 토큰 자체로 사용자 인증 | | ||
| | 저장 형태 | 쿠키(JSESSIONID) | JWT 등 토큰 | | ||
| | 확장성 | 서버 늘어나면 관리 복잡 | 서버 확장 쉬움 | | ||
| | 보안 | 상대적으로 안전 | 토큰 탈취 시 위험 | | ||
|
|
||
| **세션은 서버가 로그인 상태를 기억하고, 토큰은 토큰 자체가 인증 정보를 가진다.** | ||
|
|
||
|
|
||
| - 엑세스 토큰과 리프레시 토큰이란? | ||
|
|
||
| **Access Token** | ||
|
|
||
| 실제 인증에 사용하는 메인 토큰 | ||
|
|
||
| - API 요청 시 사용 | ||
| - Authorization 헤더에 담아 전송 | ||
| - 유효기간이 짧음 | ||
|
|
||
| **Refresh Token** | ||
|
|
||
| - 로그인 유지 목적 | ||
| - Access Token 만료 시 새 토큰 발급 | ||
| - 유효기간이 김 (2주~ 1개월) | ||
|
|
||
| 흐름 | ||
|
|
||
| - 로그인 성공 | ||
| - Access + Refresh Token 발급 | ||
| - Access Token 만료 | ||
| - Refresh Token으로 재발급 | ||
| - 재로그인 없이 계속 사용 | ||
|
|
||
|
|
||
| - OAuth 1.0과 OAuth 2.0의 차이는? | ||
|
|
||
| **OAuth** | ||
|
|
||
| 비밀번호를 직접 공유하지 않고 제 3자 서비스가 권한을 위임받는 인증 방식 | ||
|
|
||
| 예) 카카오, 구글, 네이버 로그인 | ||
|
|
||
| | 구분 | OAuth 1.0 | OAuth 2.0 | | ||
| | --- | --- | --- | | ||
| | 보안 방식 | 복잡한 서명(Signature) | HTTPS 기반 | | ||
| | 구현 난이도 | 어려움 | 쉬움 | | ||
| | 성능 | 느림 | 빠름 | | ||
| | 사용성 | 낮음 | 높음 | | ||
| | 현재 사용 | 거의 안 씀 | 대부분 사용 | | ||
|
|
||
| OAuth 1.0은 서명 기반으로 복잡하고, OAuth 2.0은 토큰 기반으로 단순하고 확장성이 좋다. | ||
|
|
||
| OAuth 2.0은 OAuth 1.0의 복잡한 서명 방식을 제거하고 Access Token 기반 인증을 도입하여 구현이 단순해지고 확장성이 향상된 방식이다. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import com.example.umc10th.domain.member.dto.MemberReqDTO; | ||
| import com.example.umc10th.domain.member.dto.MemberResDTO; | ||
| import com.example.umc10th.domain.member.entity.Member; | ||
| import com.example.umc10th.global.security.dto.OAuthDTO; | ||
|
|
||
| public class MemberConverter { | ||
| public static MemberResDTO.GetInfo toGetInfo(Member member) { | ||
|
|
@@ -36,4 +37,20 @@ public static Member toMember(MemberReqDTO.SignUpReqDTO dto, String encodedPassw | |
| public static MemberResDTO.SignUpResDTO toSignUpResDTO(Member member) { | ||
| return new MemberResDTO.SignUpResDTO(member.getId()); | ||
| } | ||
|
|
||
| // 로그인 | ||
| public static MemberResDTO.LoginResDTO toLoginResDTO(String token){ | ||
| return MemberResDTO.LoginResDTO.builder() | ||
| .accessToken(token) | ||
| .build(); | ||
| } | ||
|
|
||
| public static Member toMember(OAuthDTO dto) { | ||
| return Member.builder() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OAuth 회원을 |
||
| .email(dto.getSocialEmail()) | ||
| .name(dto.getName()) | ||
| .socialType(dto.getSocialType()) | ||
| .socialUid(dto.getSocialUid()) | ||
|
Comment on lines
+49
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 문제는 Useful? React with 👍 / 👎. |
||
| .build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,4 +23,10 @@ public record SignUpReqDTO( | |
| String email, | ||
| String password | ||
| ){} | ||
|
|
||
| // 로그인 | ||
| public record LoginReqDTO( | ||
| String email, | ||
| String password | ||
| ){} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. email 필드의 검증 조건이 없다면, swagger에서 확인했을 때 예시 값이 'string'으로 보여 email 형식으로 로그인을 강제하고 있는지 판단하기 어렵습니다. Reqeust DTO는 항상 검증 조건을 체크해야 합니다. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.example.umc10th.domain.member.enums; | ||
|
|
||
| public enum SocialType { | ||
| KAKAO | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,18 @@ | ||
| package com.example.umc10th.domain.member.repository; | ||
|
|
||
| import com.example.umc10th.domain.member.entity.Member; | ||
| import com.example.umc10th.domain.member.enums.SocialType; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
|
|
||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface MemberRepository extends JpaRepository<Member,Long> { | ||
| @Query("SELECT m FROM Member m WHERE m.name=:name AND m.deletedAt IS NULL") | ||
| Optional<Member> findActiveMember(String name); | ||
|
|
||
| Optional<Member> findByEmail(String username); | ||
|
|
||
| Optional<Member> findBySocialTypeAndSocialUid(SocialType socialType, String socialUid); | ||
| } |
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.
OAuth 2.0을 Access Token 기반이라고만 정리하면 핵심 흐름이 다소 단순화됩니다. Authorization Code Grant 기준으로 client, resource owner, authorization server, resource server의 역할과 redirect URI, scope가 왜 필요한지까지 함께 정리하는 것을 권장합니다.