Skip to content

Commit

Permalink
Merge branch 'develop' into test/150-timeline-service-test
Browse files Browse the repository at this point in the history
  • Loading branch information
penrose15 committed Aug 3, 2024
2 parents 4826615 + f4d1e2b commit a6e4782
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.depromeet.dto.auth.AccountProfileResponse;

public interface SocialUseCase {
AccountProfileResponse getGoogleAccountProfile(String code);
AccountProfileResponse getGoogleAccountProfile(String code, String origin);

KakaoAccountProfile getKakaoAccountProfile(String code);
KakaoAccountProfile getKakaoAccountProfile(String code, String origin);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import com.depromeet.dto.auth.AccountProfileResponse;

public interface GooglePort {
AccountProfileResponse getGoogleAccountProfile(String code);
AccountProfileResponse getGoogleAccountProfile(String code, String origin);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import com.depromeet.auth.vo.kakao.KakaoAccountProfile;

public interface KakaoPort {
KakaoAccountProfile getKakaoAccountProfile(final String code);
KakaoAccountProfile getKakaoAccountProfile(final String code, String origin);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public class SocialService implements SocialUseCase {
private final GooglePort googlePort;

@Override
public AccountProfileResponse getGoogleAccountProfile(String code) {
return googlePort.getGoogleAccountProfile(code);
public AccountProfileResponse getGoogleAccountProfile(String code, String origin) {
return googlePort.getGoogleAccountProfile(code, origin);
}

@Override
public KakaoAccountProfile getKakaoAccountProfile(String code) {
return kakaoPort.getKakaoAccountProfile(code);
public KakaoAccountProfile getKakaoAccountProfile(String code, String origin) {
return kakaoPort.getKakaoAccountProfile(code, origin);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GoogleClient implements GooglePort {
@Value("${spring.security.oauth2.client.registration.google.client-secret}")
private String clientSecret;

@Value("${spring.security.oauth2.client.registration.google.redirect-uri}")
@Value("${spring.security.oauth2.client.registration.google.client-redirect-uri}")
private String redirectUri;

@Value("${spring.security.oauth2.client.registration.google.authorization-grant-type}")
Expand All @@ -41,12 +41,12 @@ public class GoogleClient implements GooglePort {

private final RestTemplate restTemplate;

public AccountProfileResponse getGoogleAccountProfile(final String code) {
final String accessToken = requestGoogleAccessToken(code);
public AccountProfileResponse getGoogleAccountProfile(final String code, String origin) {
final String accessToken = requestGoogleAccessToken(code, origin);
return requestGoogleAccountProfile(accessToken);
}

private String requestGoogleAccessToken(final String code) {
private String requestGoogleAccessToken(final String code, String origin) {
final String decodedCode = URLDecoder.decode(code, StandardCharsets.UTF_8);
final HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
Expand All @@ -56,7 +56,7 @@ private String requestGoogleAccessToken(final String code) {
decodedCode,
clientId,
clientSecret,
redirectUri,
origin + redirectUri,
authorizationCode),
headers);
final GoogleAccessTokenResponse response =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class KakaoClient implements KakaoPort {
@Value("${spring.security.oauth2.client.registration.kakao.client-secret}")
private String clientSecret;

@Value("${spring.security.oauth2.client.registration.kakao.redirect-uri}")
@Value("${spring.security.oauth2.client.registration.kakao.client-redirect-uri}")
private String redirectUri;

@Value("${spring.security.oauth2.client.registration.kakao.authorization-grant-type}")
Expand All @@ -42,15 +42,15 @@ public class KakaoClient implements KakaoPort {
private final RestTemplate restTemplate;
private final ObjectMapper objectMapper = new ObjectMapper();

public KakaoAccountProfile getKakaoAccountProfile(final String code) {
final String accessToken = requestKakaoAccessToken(code);
public KakaoAccountProfile getKakaoAccountProfile(final String code, String origin) {
final String accessToken = requestKakaoAccessToken(code, origin);
KakaoAccountProfileResponse response = requestKakaoAccountProfile(accessToken);

return KakaoAccountProfile.of(
response.getId(), response.getEmail(), response.getNickname());
}

private String requestKakaoAccessToken(final String code) {
private String requestKakaoAccessToken(final String code, String origin) {
final String decodedCode = URLDecoder.decode(code, StandardCharsets.UTF_8);
final HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
Expand All @@ -59,7 +59,7 @@ private String requestKakaoAccessToken(final String code) {
body.add("code", decodedCode);
body.add("client_id", clientId);
body.add("client_secret", clientSecret);
body.add("redirect_uri", redirectUri);
body.add("redirect_uri", origin + redirectUri);
body.add("grant_type", grantType);
final HttpEntity<MultiValueMap<String, String>> httpEntity =
new HttpEntity<>(body, headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.depromeet.dto.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
Expand All @@ -15,10 +16,13 @@
public interface AuthApi {
@Operation(summary = "ꡬ글 μ†Œμ…œλ‘œκ·ΈμΈ")
ApiResponse<JwtTokenResponse> loginByGoogle(
@Valid @RequestBody final GoogleLoginRequest request);
@Valid @RequestBody final GoogleLoginRequest request,
HttpServletRequest httpServletRequest);

@Operation(summary = "카카였 μ†Œμ…œλ‘œκ·ΈμΈ")
ApiResponse<JwtTokenResponse> loginByKakao(@Valid @RequestBody final KakaoLoginRequest request);
ApiResponse<JwtTokenResponse> loginByKakao(
@Valid @RequestBody final KakaoLoginRequest request,
HttpServletRequest httpServletRequest);

@Operation(summary = "Access 토큰 μž¬λ°œκΈ‰ μš”μ²­")
ApiResponse<JwtAccessTokenResponse> reissueAccessToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.depromeet.auth.facade.AuthFacade;
import com.depromeet.dto.response.ApiResponse;
import com.depromeet.type.auth.AuthSuccessType;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
Expand All @@ -19,15 +20,20 @@ public class AuthController implements AuthApi {

@PostMapping("/google")
public ApiResponse<JwtTokenResponse> loginByGoogle(
@Valid @RequestBody final GoogleLoginRequest request) {
@Valid @RequestBody final GoogleLoginRequest request,
HttpServletRequest httpServletRequest) {
String origin = getOrigin(httpServletRequest);
return ApiResponse.success(
AuthSuccessType.LOGIN_SUCCESS, authFacade.loginByGoogle(request));
AuthSuccessType.LOGIN_SUCCESS, authFacade.loginByGoogle(request, origin));
}

@PostMapping("/kakao")
public ApiResponse<JwtTokenResponse> loginByKakao(
@Valid @RequestBody final KakaoLoginRequest request) {
return ApiResponse.success(AuthSuccessType.LOGIN_SUCCESS, authFacade.loginByKakao(request));
@Valid @RequestBody final KakaoLoginRequest request,
HttpServletRequest httpServletRequest) {
String origin = getOrigin(httpServletRequest);
return ApiResponse.success(
AuthSuccessType.LOGIN_SUCCESS, authFacade.loginByKakao(request, origin));
}

@PostMapping("/refresh")
Expand All @@ -37,4 +43,8 @@ public ApiResponse<JwtAccessTokenResponse> reissueAccessToken(
AuthSuccessType.REISSUE_ACCESS_TOKEN_SUCCESS,
authFacade.getReissuedAccessToken(refreshToken));
}

private static String getOrigin(HttpServletRequest httpServletRequest) {
return httpServletRequest.getHeader("Origin");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public class AuthFacade {
private final SocialUseCase socialUseCase;
private final CreateTokenUseCase createTokenUseCase;

public JwtTokenResponse loginByGoogle(GoogleLoginRequest request) {
public JwtTokenResponse loginByGoogle(GoogleLoginRequest request, String origin) {
final AccountProfileResponse profile =
socialUseCase.getGoogleAccountProfile(request.code());
socialUseCase.getGoogleAccountProfile(request.code(), origin);
if (profile == null) {
throw new NotFoundException(AuthErrorType.NOT_FOUND);
}
Expand All @@ -39,8 +39,9 @@ public JwtTokenResponse loginByGoogle(GoogleLoginRequest request) {
return JwtTokenResponse.of(token);
}

public JwtTokenResponse loginByKakao(KakaoLoginRequest request) {
final KakaoAccountProfile profile = socialUseCase.getKakaoAccountProfile(request.code());
public JwtTokenResponse loginByKakao(KakaoLoginRequest request, String origin) {
final KakaoAccountProfile profile =
socialUseCase.getKakaoAccountProfile(request.code(), origin);
if (profile == null) {
throw new NotFoundException(AuthErrorType.NOT_FOUND);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.depromeet.memory.domain.Stroke;
import com.depromeet.pool.domain.Pool;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;
Expand All @@ -25,10 +26,19 @@ public class MemoryResponse {
private MemoryDetailResponse memoryDetail;
private List<StrokeResponse> strokes;
private List<ImageSimpleResponse> images;

@Schema(description = "μž‘μ„±μΌμž", example = "2024-08-01", maxLength = 10, type = "string")
private LocalDate recordAt;

@Schema(description = "μ‹œμž‘μ‹œκ°„", example = "11:00", maxLength = 8, type = "string")
private LocalTime startTime;

@Schema(description = "μ’…λ£Œμ‹œκ°„", example = "11:50", maxLength = 8, type = "string")
private LocalTime endTime;

@Schema(description = "μš΄λ™μ‹œκ°„", example = "00:50", maxLength = 8, type = "string")
private LocalTime duration;

private Short lane;
private Float totalLap;
private Integer totalMeter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ spring:
client-id: ${KAKAO_CLIENT_ID}
client-secret: ${KAKAO_CLIENT_SECRET}
redirect-uri: ${KAKAO_REDIRECT_URL}
client-redirect-uri: ${KAKAO_CLIENT_REDIRECT_URL}
authorization-grant-type: authorization_code
client-authentication-method: client_secret_post
client-name: kakao
Expand All @@ -22,6 +23,7 @@ spring:
client-id: ${GOOGLE_CLIENT_ID}
client-secret: ${GOOGLE_CLIENT_SECRET}
redirect-uri: ${GOOGLE_REDIRECT_URL}
client-redirect-uri: ${GOOGLE_CLIENT_REDIRECT_URL}
authorization-code: ${GOOGLE_AUTH_CODE}
scope: profile,email
access-token-url: https://oauth2.googleapis.com/token
Expand Down

0 comments on commit a6e4782

Please sign in to comment.