diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceTestSupporter.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceTestSupporter.java index cf415cb7..0731091e 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceTestSupporter.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceTestSupporter.java @@ -17,7 +17,7 @@ public class UserAcceptanceTestSupporter { protected ResultActions getLoginedUser(String token) throws Exception { return mockMvc.perform(MockMvcRequestBuilders - .get(API_VERSION + "/users/logined") + .get(API_VERSION + "/users/logins") .accept(MediaType.APPLICATION_JSON) .header(HttpHeaders.AUTHORIZATION, token) ); diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceValidator.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceValidator.java index bf074b3f..56504b3b 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceValidator.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/UserAcceptanceValidator.java @@ -6,11 +6,12 @@ public class UserAcceptanceValidator { - public static void assertIsLogined(ResultActions resultActions, Long targetId, String nickname) throws Exception { + public static void assertIsLogined(ResultActions resultActions, Long targetId, String nickname, String email) throws Exception { resultActions.andExpectAll( status().isOk(), jsonPath("$.target_id").value(targetId), - jsonPath("$.nickname").value(nickname) + jsonPath("$.nickname").value(nickname), + jsonPath("$.email").value(email) ); } diff --git a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/logined/LoginedTargetFindAcceptanceTest.java b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/logined/LoginedTargetFindAcceptanceTest.java index 176f5d65..f7271847 100644 --- a/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/logined/LoginedTargetFindAcceptanceTest.java +++ b/api/acceptance-test/src/test/java/me/nalab/luffy/api/acceptance/test/user/logined/LoginedTargetFindAcceptanceTest.java @@ -45,9 +45,12 @@ class LoginedTargetFindAcceptanceTest extends UserAcceptanceTestSupporter { void GET_LOGINED_USER_SUCCESS() throws Exception { // given String nickname = "devxb"; + String email = "email"; Long targetId = targetInitializer.saveTargetAndGetId(nickname, Instant.now()); String token = jwtUtils.createAccessToken(Set.of(new Payload(Payload.Key.NICKNAME, nickname), - new Payload(Payload.Key.USER_ID, 12345 + ""), new Payload(Payload.Key.TARGET_ID, targetId + ""))); + new Payload(Payload.Key.USER_ID, 12345 + ""), + new Payload(Payload.Key.TARGET_ID, targetId + ""), + new Payload(Payload.Key.EMAIL, email))); applicationEventPublisher.publishEvent( MockUserRegisterEvent.builder().expectedToken("bearer " + token).expectedId(targetId).build()); @@ -55,7 +58,7 @@ void GET_LOGINED_USER_SUCCESS() throws Exception { ResultActions resultActions = getLoginedUser("bearer " + token); // then - assertIsLogined(resultActions, targetId, nickname); + assertIsLogined(resultActions, targetId, nickname, email); } } diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/CreateAuthTokenRequest.java b/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/CreateAuthTokenRequest.java index 6c98c9d4..8c116802 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/CreateAuthTokenRequest.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/CreateAuthTokenRequest.java @@ -7,4 +7,5 @@ public class CreateAuthTokenRequest { private final String userId; private final String nickname; private final String targetId; + private final String email; } diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/Payload.java b/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/Payload.java index f6fff8d9..d4b79de8 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/Payload.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/common/dto/Payload.java @@ -15,5 +15,6 @@ public enum Key { USER_ID, TARGET_ID, NICKNAME, + EMAIL, } } diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/service/AuthTokenCreateService.java b/auth/auth-application/src/main/java/me/nalab/auth/application/service/AuthTokenCreateService.java index 29c7e6fd..ac85d748 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/service/AuthTokenCreateService.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/service/AuthTokenCreateService.java @@ -24,14 +24,17 @@ public AuthToken create(CreateAuthTokenRequest request) { var userId = request.getUserId(); var nickname = request.getNickname(); var targetId = request.getTargetId(); + var email = request.getEmail(); Assert.isTrue(userId != null && !userId.isBlank(), "Authentication token 생성 시 유저 식별자는 필수입니다."); Assert.isTrue(nickname != null && !nickname.isBlank(), "Authentication token 생성 시 유저의 별명은 필수입니다."); Assert.isTrue(targetId != null && !targetId.isBlank(), "Authentication token 생성 시 유저의 별명은 필수입니다."); + Assert.isTrue(email != null && !email.isBlank(), "Authentication token 생성 시 유저의 이메일은 필수입니다."); Set payload = new HashSet<>(); payload.add(new Payload(Payload.Key.USER_ID, userId)); payload.add(new Payload(Payload.Key.NICKNAME, nickname)); payload.add(new Payload(Payload.Key.TARGET_ID, targetId)); + payload.add(new Payload(Payload.Key.EMAIL, email)); String token = createToken(payload); return new AuthToken(token); diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/service/JwtLoginedDecryptService.java b/auth/auth-application/src/main/java/me/nalab/auth/application/service/JwtLoginedDecryptService.java index 8f79ead5..884703fe 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/service/JwtLoginedDecryptService.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/service/JwtLoginedDecryptService.java @@ -26,7 +26,8 @@ public LoginedInfo decryptToken(String encryptedToken) { String nickName = decodedJWT.getClaim(Payload.Key.NICKNAME.name()).asString(); Long userId = Long.valueOf(decodedJWT.getClaim(Payload.Key.USER_ID.name()).asString()); Long targetId = Long.valueOf(decodedJWT.getClaim(Payload.Key.TARGET_ID.name()).asString()); - return new LoginedInfo(nickName, targetId, userId); + String email = decodedJWT.getClaim(Payload.Key.EMAIL.name()).asString(); + return new LoginedInfo(nickName, targetId, userId, email); } @Override diff --git a/auth/auth-application/src/main/java/me/nalab/auth/application/service/SignInWithOAuthService.java b/auth/auth-application/src/main/java/me/nalab/auth/application/service/SignInWithOAuthService.java index 70866829..2e80a394 100644 --- a/auth/auth-application/src/main/java/me/nalab/auth/application/service/SignInWithOAuthService.java +++ b/auth/auth-application/src/main/java/me/nalab/auth/application/service/SignInWithOAuthService.java @@ -36,7 +36,7 @@ public AuthToken signInWithOAuth(SignInWithOAuthRequest request) { var userId = foundUser.orElseThrow(IllegalAccessError::new); var targetId = targetFindByUsernameUseCase.findTargetByUsername(request.getUsername()).orElseThrow().getId(); - var authTokenCreateRequest = new CreateAuthTokenRequest(userId.toString(), request.getUsername(), String.valueOf(targetId)); + var authTokenCreateRequest = new CreateAuthTokenRequest(userId.toString(), request.getUsername(), String.valueOf(targetId), email); return authTokenCreateUseCase.create(authTokenCreateRequest); } diff --git a/auth/auth-application/src/test/java/me/nalab/auth/application/service/AuthTokenCreateServiceTest.java b/auth/auth-application/src/test/java/me/nalab/auth/application/service/AuthTokenCreateServiceTest.java index eff30c90..a2151483 100644 --- a/auth/auth-application/src/test/java/me/nalab/auth/application/service/AuthTokenCreateServiceTest.java +++ b/auth/auth-application/src/test/java/me/nalab/auth/application/service/AuthTokenCreateServiceTest.java @@ -33,7 +33,8 @@ void THROW_EXCEPTION_WHEN_USER_ID_IS_BLANK(String userId) { // given var nickname = "nickname"; var targetId = "targetId"; - var request = new CreateAuthTokenRequest(userId, nickname, targetId); + var email = "email"; + var request = new CreateAuthTokenRequest(userId, nickname, targetId, email); // when var throwable = Assertions.catchThrowable(() -> authTokenCreateService.create(request)); @@ -49,7 +50,8 @@ void THROW_EXCEPTION_WHEN_NICKNAME_IS_BLANK(String nickname) { // given var userId = "userId"; var targetId = "targetId"; - var request = new CreateAuthTokenRequest(userId, nickname, targetId); + var email = "email"; + var request = new CreateAuthTokenRequest(userId, nickname, targetId, email); // when var throwable = Assertions.catchThrowable(() -> authTokenCreateService.create(request)); @@ -65,7 +67,25 @@ void THROW_EXCEPTION_WHEN_TARGET_ID_IS_BLANK(String targetId) { // given var userId = "userId"; var nickname = "nickname"; - var request = new CreateAuthTokenRequest(userId, nickname, targetId); + var email = "email"; + var request = new CreateAuthTokenRequest(userId, nickname, targetId, email); + + // when + var throwable = Assertions.catchThrowable(() -> authTokenCreateService.create(request)); + + // then + Assertions.assertThat(throwable).isInstanceOf(IllegalArgumentException.class); + } + + @ParameterizedTest + @NullAndEmptySource + @DisplayName("이메일이 비어있거나 null이면 예외를 발생시킨다.") + void THROW_EXCEPTION_WHEN_EMAIL_IS_BLANK(String email) { + // given + var userId = "userId"; + var targetId = "targetId"; + var nickname = "nickname"; + var request = new CreateAuthTokenRequest(userId, nickname, targetId, email); // when var throwable = Assertions.catchThrowable(() -> authTokenCreateService.create(request)); @@ -81,7 +101,8 @@ void RETURN_TOKEN_WHEN_VALID_REQUEST() { var userId = "userId"; var nickname = "nickname"; var targetId = "targetId"; - var request = new CreateAuthTokenRequest(userId, nickname, targetId); + var email = "email"; + var request = new CreateAuthTokenRequest(userId, nickname, targetId, email); var expectedToken = "token"; when(jwtUtils.createAccessToken(any())).thenReturn(expectedToken); diff --git a/support/e2e/v1_13_get_logined_target.hurl b/support/e2e/v1_13_get_logined_target.hurl new file mode 100644 index 00000000..8407dce4 --- /dev/null +++ b/support/e2e/v1_13_get_logined_target.hurl @@ -0,0 +1,29 @@ +POST http://nalab-server:8080/v1/oauth/default # Default provider를 통해서 로그인 진행 +{ + "nickname": "devxb", + "email": "get_logined_target@naver.com" +} + +HTTP 200 +[Asserts] +header "Content-type" == "application/json" + +jsonpath "$.access_token" exists +jsonpath "$.token_type" exists + +[Captures] +token_type: jsonpath "$.token_type" +auth_token: jsonpath "$.access_token" + +####### + +GET http://nalab-server:8080/v1/users/logins # Token에 해당하는 유저 조회 +Authorization: {{ token_type }} {{ auth_token }} + +HTTP 200 +[Asserts] +header "Content-type" == "application/json" + +jsonpath "$.target_id" exists +jsonpath "$.nickname" == "devxb" +jsonpath "$.email" == "get_logined_target@naver.com" diff --git a/user/user-application/src/main/java/me/nalab/user/application/common/dto/LoginedInfo.java b/user/user-application/src/main/java/me/nalab/user/application/common/dto/LoginedInfo.java index c636eec5..c71afb65 100644 --- a/user/user-application/src/main/java/me/nalab/user/application/common/dto/LoginedInfo.java +++ b/user/user-application/src/main/java/me/nalab/user/application/common/dto/LoginedInfo.java @@ -8,5 +8,5 @@ public class LoginedInfo { private final String nickName; private final Long targetId; private final Long userId; - + private final String email; } diff --git a/user/user-application/src/test/java/me/nalab/user/application/service/LoginedUserGetByTokenServiceTest.java b/user/user-application/src/test/java/me/nalab/user/application/service/LoginedUserGetByTokenServiceTest.java index 35423160..02796247 100644 --- a/user/user-application/src/test/java/me/nalab/user/application/service/LoginedUserGetByTokenServiceTest.java +++ b/user/user-application/src/test/java/me/nalab/user/application/service/LoginedUserGetByTokenServiceTest.java @@ -31,7 +31,7 @@ class LoginedUserGetByTokenServiceTest { @DisplayName("토큰을 이용해 로그인된 유저의 정보를 조회 성공 테스트") void GET_LOGINED_INFO_BY_TOKEN_SUCCESS() { // given - LoginedInfo expected = new LoginedInfo("hello", 12345L, 54321L); + LoginedInfo expected = new LoginedInfo("hello", 12345L, 54321L, "email"); String token = "hello token"; Mockito.when(loginedUserGetByTokenPort.decryptToken(token.split(" ")[1])).thenReturn(expected); diff --git a/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/LoginedUserGetController.java b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/LoginedUserGetController.java index 31b9dbfe..dba5afa6 100644 --- a/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/LoginedUserGetController.java +++ b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/LoginedUserGetController.java @@ -18,11 +18,11 @@ public class LoginedUserGetController { private final LoginedUserGetByTokenUseCase loginedUserGetByTokenUseCase; - @GetMapping("/users/logined") + @GetMapping("/users/logins") public LoginedInfoResponse getLoginedUserByToken(@RequestHeader(HttpHeaders.AUTHORIZATION) String token) { LoginedInfo loginedInfo = loginedUserGetByTokenUseCase.decryptToken(token); - return new LoginedInfoResponse(String.valueOf(loginedInfo.getTargetId()), loginedInfo.getNickName()); + return LoginedInfoResponse.of(loginedInfo); } } diff --git a/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/response/LoginedInfoResponse.java b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/response/LoginedInfoResponse.java index 7197cc1b..096dcf0f 100644 --- a/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/response/LoginedInfoResponse.java +++ b/user/user-web-adaptor/src/main/java/me/nalab/user/web/adaptor/logined/response/LoginedInfoResponse.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; +import me.nalab.user.application.common.dto.LoginedInfo; @Data public class LoginedInfoResponse { @@ -11,5 +12,13 @@ public class LoginedInfoResponse { private final String targetId; @JsonProperty("nickname") private final String nickName; + @JsonProperty("email") + private final String email; + + public static LoginedInfoResponse of(LoginedInfo loginedInfo) { + return new LoginedInfoResponse(String.valueOf(loginedInfo.getTargetId()), + loginedInfo.getNickName(), + loginedInfo.getEmail()); + } }