-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs: 카카오 oauth2 로그인 설정(application.yml) Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: AuthController 리팩터링 - 기존의 토큰 로그인 방식에서 OAuth 로그인으로 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: AuthService 리팩터링 - 기존의 토큰 로그인 방식에서 OAuth 로그인으로 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * feat: OAuth 기능 구현(kakao) - 기존의 토큰 로그인 방식에서 OAuth 로그인으로 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 불필요한 로직 제거 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: SignupRequest를 LoginRequest로 리팩터링 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 인증 서버 이름을 PathVariable로 받던 방식을 body로 받도록 리팩터링 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: AuthService에서 사용하지 않는 NicknameGenerator 필드 제거 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 기본 생성자를 어노테이션으로 대체 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: OAuthAdapter 메서드의 역할 분리 - OAuthProperties 내부 클래스 이름 변경 (Client -> User) (yml 설정 파일과 일치 시키기 위한 변경) Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 클래스 이름 변경 - InMemoryProviderRepository -> OAuthProviderRepository Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: OAuth 로그인에 필요한 통신 로직 추상화 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 개행 추가 및 final 키워드 추가 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * remove: 불필요해진 클래스 제거 - OAuthTokenResponse Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: AuthService 리팩터링 - 불필요한 개행 삭제 - 메서드 분리 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 메서드 네이밍 변경 - getAccessToken -> getAccessTokenResponse Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 메서드 네이밍 수정 및 Json타입을 객체 타입으로 파싱하기 위한 Response 재생성 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * move: OAuth 설정 파일 경로 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: Member 로직과 Auth 로직을 분리 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * feat: 어노테이션으로 현재 OAuth 인증기관의 정보를 가져오는 기능 추가 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: OAuthConfig 파일 수정 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * move: 파일 구조 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: OAuthProperties 리팩터링 - 기존의 불필요했던 구조를 최적화 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * remove: 불필요해진 클래스 제거 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 기존의 id로 토큰을 만드는 방식을 이메일로 만들도록 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * feat: email, nickname 정보로 member를 생성하는 메서드 추가 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * feat: post 요청의 바디를 여러번 읽기 위한 설정 추가 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: RestTemplate 설정 추가 및 리팩터링 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 인증기관에서 받아오는 정보 변경으로 인한 리팩터링 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * feat: 인증 기관에 대한 모든 요청을 담당하는 클래스 추가 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * feat: Json 타입을 변환해주는 mapper 추가 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 컨트롤러 리팩터링 - 로그인 메서드 파라미터에 @OAuthAuthority 적용 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * docs: oauth2 구조 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * rename: 클래스명 변경 - RegisteredEvent -> ValidatedLoginEvent Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * feat: Json 데이터의 key 값으로 value를 찾아 반환하는 메서드 추가 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: event 관련 설정을 담당하는 클래스를 만들어 역할 분리 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * feat: OAuth 기관들을 관리하는 enum 클래스 생성 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * feat: request 메세지의 관한 처리를 담당하는 클래스 생성 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 기존의 http 요청 메세지 관련 작업을 RequestProcessor에서 하도록 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 설정 파일에서 사용하던 Setter 제거 및 인증 기관을 enum 타입으로 바인딩하도록 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: OAuthProvider 클래스를 레코드로 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 파일 구조 변경으로 인한 import 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 불필요해진 필드와 메서드 제거 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 설정 파일에 값을 손쉽게 바인딩하기 위해 @ConfigurationPropertiesScan을 추가 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * remove: 불필요해진 클래스 제거 - OAuthTokenResponse Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * move: 파일 계층 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * feat: 유효하지 않은 Json 데이터에 대한 예외처리 기능 추가 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 커스텀한 예외를 던지도록 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * test: 불필요한 테스트 클래스 제거 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * docs: 설정 파일 수정 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * test: 테스트 클래스 경로 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * test: 프로덕션 코드 수정으로 인한 테스트 코드 변경 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * test: KakaoOAuthRequesterTest 테스트 추가 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * test: MemberServiceTest 테스트 추가 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * test: 테스트를 쉽게 하기 위해 Fake 클래스 추가 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * test: 테스트를 쉽게 하기 위해 Fixture 클래스 추가 - OAuthProviderFixture Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * test: OAuthPropertiesTest 테스트 추가 Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> * refactor: 계층 변경 * refactor: 계층 변경 * remove: 불필요해진 클래스 제거 * refactor: 중복되는 메서드 제거 * feat: 회원 정보의 keyWord를 담는 DTO 클래스 생성 * refactor: 코트 최적화 및 네이밍 수 * docs: google 소셜 로그인 설정 추가 * test: 테스트 설정 파일 수정 * test: 프로덕션 코드 리팩터링으로 인한 테스트 코드 수정 * docs: 로그인 api 문서화 * remove: 불필요해진 클래스 제거 * refactor: 공백 제거 및 final 키워드 추가 * refactor: 토큰 만드는 메서드 네이밍 변경 및 @Getter 제거 * refactor: 기존에 모호하게 작성했던 변수명을 구체적으로 변경 - a, b -> parentPath, childPath * feat: 등록된 소셜 로그인 기관 중 해당 요청의 기관을 찾을 수 없을 때 발생시킬 예외 클래스 생성 * refactor: 등록된 소셜 기관이 없을 때 OAuthPlatformNotFountException를 던지도록 수정 * test: OAuthPlatformTest 테스트 클래스 추가 * docs: oauth2 client-secret 키 암호화 --------- Co-authored-by: devholic22 <hyunjoon.tech@gmail.com> Co-authored-by: sosow0212 <sosow0212@naver.com>
- Loading branch information
1 parent
3df4a84
commit 8928b38
Showing
57 changed files
with
813 additions
and
332 deletions.
There are no files selected for viewing
This file contains 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,25 @@ | ||
:toc: left | ||
:source-highlighter: highlightjs | ||
:sectlinks: | ||
:toclevels: 2 | ||
:sectlinks: | ||
:sectnums: | ||
|
||
== Member | ||
|
||
=== 로그인 | ||
|
||
==== 요청 | ||
|
||
include::{snippets}/auth-controller-web-mvc-test/do_signup/http-request.adoc[] | ||
include::{snippets}/auth-controller-web-mvc-test/do_signup/request-fields.adoc[] | ||
|
||
|
||
==== 응답 | ||
include::{snippets}/auth-controller-web-mvc-test/do_signup/http-response.adoc[] | ||
include::{snippets}/auth-controller-web-mvc-test/do_signup/request-fields.adoc[] | ||
|
||
|
||
|
||
|
||
|
This file contains 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 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 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
32 changes: 32 additions & 0 deletions
32
src/main/java/com/atwoz/member/application/auth/OAuth2Requester.java
This file contains 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,32 @@ | ||
package com.atwoz.member.application.auth; | ||
|
||
import com.atwoz.member.domain.auth.JsonMapper; | ||
import com.atwoz.member.domain.auth.OAuthConnectionManager; | ||
import com.atwoz.member.infrastructure.auth.dto.MemberInfoResponse; | ||
import com.atwoz.member.infrastructure.auth.dto.OAuthProviderRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class OAuth2Requester implements OAuthRequester { | ||
|
||
private static final String KEY = "access_token"; | ||
|
||
private final OAuthConnectionManager oAuthConnectionManager; | ||
private final JsonMapper jsonMapper; | ||
|
||
@Override | ||
public String getAccessToken(final String code, final OAuthProviderRequest provider) { | ||
String accessTokenResponse = oAuthConnectionManager.getAccessTokenResponse(provider, code); | ||
return jsonMapper.getValueByKey(accessTokenResponse, KEY); | ||
} | ||
|
||
@Override | ||
public MemberInfoResponse getMemberInfo(final String accessToken, final OAuthProviderRequest oAuthProviderRequest) { | ||
String memberInfoResponse = oAuthConnectionManager.getMemberInfoResponse(accessToken, | ||
oAuthProviderRequest.userInfoUri()); | ||
|
||
return jsonMapper.extractMemberInfoFrom(memberInfoResponse, oAuthProviderRequest.memberInfoKeyWordRequest()); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/atwoz/member/application/auth/OAuthRequester.java
This file contains 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,11 @@ | ||
package com.atwoz.member.application.auth; | ||
|
||
import com.atwoz.member.infrastructure.auth.dto.MemberInfoResponse; | ||
import com.atwoz.member.infrastructure.auth.dto.OAuthProviderRequest; | ||
|
||
public interface OAuthRequester { | ||
|
||
String getAccessToken(final String code, final OAuthProviderRequest provider); | ||
|
||
MemberInfoResponse getMemberInfo(final String accessToken, final OAuthProviderRequest oAuthProviderRequest); | ||
} |
This file contains 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
12 changes: 0 additions & 12 deletions
12
src/main/java/com/atwoz/member/application/auth/dto/SignupRequest.java
This file was deleted.
Oops, something went wrong.
5 changes: 2 additions & 3 deletions
5
...z/member/domain/auth/RegisteredEvent.java → ...pplication/event/ValidatedLoginEvent.java
This file contains 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 |
---|---|---|
@@ -1,14 +1,13 @@ | ||
package com.atwoz.member.domain.auth; | ||
package com.atwoz.member.application.event; | ||
|
||
import com.atwoz.global.event.Event; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class RegisteredEvent extends Event { | ||
public class ValidatedLoginEvent extends Event { | ||
|
||
private final Long memberId; | ||
private final String email; | ||
private final String nickname; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/atwoz/member/application/member/MemberEventHandler.java
This file contains 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,18 @@ | ||
package com.atwoz.member.application.member; | ||
|
||
import com.atwoz.member.application.event.ValidatedLoginEvent; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class MemberEventHandler { | ||
|
||
private final MemberService memberService; | ||
|
||
@EventListener | ||
public void registerIfNotMemberExist(final ValidatedLoginEvent event) { | ||
memberService.create(event.getEmail(), event.getNickname()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/atwoz/member/application/member/MemberService.java
This file contains 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,21 @@ | ||
package com.atwoz.member.application.member; | ||
|
||
import com.atwoz.member.domain.member.Member; | ||
import com.atwoz.member.domain.member.MemberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class MemberService { | ||
|
||
private final MemberRepository memberRepository; | ||
|
||
@Transactional | ||
public void create(final String email, final String nickname) { | ||
if (!memberRepository.existsByEmail(email)) { | ||
memberRepository.save(Member.createWithOAuthLogin(email, nickname)); | ||
} | ||
} | ||
} |
This file contains 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,20 @@ | ||
package com.atwoz.member.config; | ||
|
||
import com.atwoz.member.ui.auth.support.resolver.OAuthArgumentResolver; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
public class OAuthConfig implements WebMvcConfigurer { | ||
|
||
private final OAuthArgumentResolver oAuthArgumentResolver; | ||
|
||
@Override | ||
public void addArgumentResolvers(final List<HandlerMethodArgumentResolver> resolvers) { | ||
resolvers.add(oAuthArgumentResolver); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/atwoz/member/config/RestTemplateConfig.java
This file contains 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,19 @@ | ||
package com.atwoz.member.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.util.DefaultUriBuilderFactory; | ||
|
||
@Configuration | ||
public class RestTemplateConfig { | ||
|
||
@Bean | ||
public RestTemplate restTemplate() { | ||
DefaultUriBuilderFactory defaultUriBuilderFactory = new DefaultUriBuilderFactory(); | ||
defaultUriBuilderFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE); | ||
RestTemplate restTemplate = new RestTemplate(); | ||
restTemplate.setUriTemplateHandler(defaultUriBuilderFactory); | ||
return restTemplate; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/atwoz/member/domain/auth/JsonMapper.java
This file contains 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,12 @@ | ||
package com.atwoz.member.domain.auth; | ||
|
||
import com.atwoz.member.infrastructure.auth.dto.MemberInfoKeyWordRequest; | ||
import com.atwoz.member.infrastructure.auth.dto.MemberInfoResponse; | ||
|
||
public interface JsonMapper { | ||
|
||
String getValueByKey(final String json, final String key); | ||
|
||
MemberInfoResponse extractMemberInfoFrom(final String memberInfoResponse, | ||
final MemberInfoKeyWordRequest memberInfoKeyWordRequest); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/atwoz/member/domain/auth/OAuthConnectionManager.java
This file contains 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,10 @@ | ||
package com.atwoz.member.domain.auth; | ||
|
||
import com.atwoz.member.infrastructure.auth.dto.OAuthProviderRequest; | ||
|
||
public interface OAuthConnectionManager { | ||
|
||
String getAccessTokenResponse (final OAuthProviderRequest oAuthProviderRequest, final String code); | ||
|
||
String getMemberInfoResponse(final String accessToken, final String userInfoUrl); | ||
} |
This file contains 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 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.