Skip to content
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

#270 [fix] /authorize 명세 수정 #271

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
package org.sopt.makers.operation.auth.api;

import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.EXPIRED_PLATFORM_CODE;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.EXPIRED_REFRESH_TOKEN;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.INVALID_GRANT_TYPE;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.INVALID_SOCIAL_TYPE;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.NOT_FOUNT_REGISTERED_TEAM;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.NOT_NULL_CODE;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.NOT_NULL_GRANT_TYPE;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.NOT_NULL_REFRESH_TOKEN;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.USED_PLATFORM_CODE;
import static org.sopt.makers.operation.code.success.auth.AuthSuccessCode.SUCCESS_GENERATE_TOKEN;
import static org.sopt.makers.operation.code.success.auth.AuthSuccessCode.SUCCESS_RETURN_REDIRECT_URL_WITH_PLATFORM_CODE;
import static org.sopt.makers.operation.jwt.JwtTokenType.PLATFORM_CODE;
import static org.sopt.makers.operation.jwt.JwtTokenType.REFRESH_TOKEN;
Comment on lines +3 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4

static import 문을 import 선언 섹션의 최하단이 아닌 최상단으로 옮기신 이유가 따로 있나요?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

자동 정렬이 시켰습니다..!
다시 변경할까 싶었는데, 변수를 선언할 때도 항상 상수를 위에 다 정의한 것이 떠올라 커밋했습니다..!


import java.util.concurrent.ConcurrentHashMap;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.sopt.makers.operation.auth.dto.request.AccessTokenRequest;
import org.sopt.makers.operation.auth.dto.response.AuthorizationCodeResponse;
import org.sopt.makers.operation.auth.dto.response.RedirectUrlResponse;
import org.sopt.makers.operation.auth.dto.response.TokenResponse;
import org.sopt.makers.operation.auth.service.AuthService;
import org.sopt.makers.operation.dto.BaseResponse;
Expand All @@ -20,29 +35,14 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ConcurrentHashMap;

import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.EXPIRED_PLATFORM_CODE;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.EXPIRED_REFRESH_TOKEN;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.INVALID_GRANT_TYPE;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.INVALID_SOCIAL_TYPE;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.NOT_FOUNT_REGISTERED_TEAM;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.NOT_NULL_CODE;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.NOT_NULL_GRANT_TYPE;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.NOT_NULL_REFRESH_TOKEN;
import static org.sopt.makers.operation.code.failure.auth.AuthFailureCode.USED_PLATFORM_CODE;
import static org.sopt.makers.operation.code.success.auth.AuthSuccessCode.SUCCESS_GENERATE_TOKEN;
import static org.sopt.makers.operation.code.success.auth.AuthSuccessCode.SUCCESS_GET_AUTHORIZATION_CODE;
import static org.sopt.makers.operation.jwt.JwtTokenType.PLATFORM_CODE;
import static org.sopt.makers.operation.jwt.JwtTokenType.REFRESH_TOKEN;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/auth")
public class AuthApiController implements AuthApi {

private static final String AUTHORIZATION_CODE_GRANT_TYPE = "authorizationCode";
private static final String REFRESH_TOKEN_GRANT_TYPE = "refreshToken";
private static final String REDIRECT_URL_WITH_CODE_FORMAT = "%s?code=%s";

private final ConcurrentHashMap<String, String> tempPlatformCode;
private final AuthService authService;
Expand All @@ -65,7 +65,8 @@ public ResponseEntity<BaseResponse<?>> authorize(

val userId = findUserIdBySocialTypeAndCode(type, code);
val platformCode = generatePlatformCode(clientId, redirectUri, userId);
return ApiResponseUtil.success(SUCCESS_GET_AUTHORIZATION_CODE, new AuthorizationCodeResponse(platformCode));
val redirectUrl = String.format(REDIRECT_URL_WITH_CODE_FORMAT, redirectUri, platformCode);
return ApiResponseUtil.success(SUCCESS_RETURN_REDIRECT_URL_WITH_PLATFORM_CODE, new RedirectUrlResponse(redirectUrl));
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.sopt.makers.operation.auth.dto.response;

public record RedirectUrlResponse(String redirectUrl) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SuccessTest {
@DisplayName("유효한 type, code, clientId, redirectUri 값이 들어왔을 때, 플랫폼 인가코드를 반환한다.")
@ParameterizedTest
@CsvSource({
"APPLE,code,clientId,redirectUri"
"APPLE,code,clientId,https://localhost:8080/auth/redirectUri"
})
void successTest(String type, String code, String clientId, String redirectUri) throws Exception {
// given
Expand All @@ -71,7 +71,8 @@ void successTest(String type, String code, String clientId, String redirectUri)
.param("clientId", clientId)
.param("redirectUri", redirectUri))
.andExpect(status().isOk())
.andExpect(jsonPath("$.message").value("플랫폼 인가코드 발급 성공"));
.andExpect(jsonPath("$.message").value("플랫폼 인가코드를 포함한 redirect url 반환 성공"))
.andExpect(jsonPath("$.data.redirectUrl").value("https://localhost:8080/auth/redirectUri?code=Platform Code"));
}

@DisplayName("grantType 이 authorizationCode 이고, 유효한 clientId, redirectUri, code 값이 들어왔을 때, 액세스 토큰과 리프레시 토큰을 발급한다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Getter
@RequiredArgsConstructor
public enum AuthSuccessCode implements SuccessCode {
SUCCESS_GET_AUTHORIZATION_CODE(OK, "플랫폼 인가코드 발급 성공"),
SUCCESS_RETURN_REDIRECT_URL_WITH_PLATFORM_CODE(OK, "플랫폼 인가코드를 포함한 redirect url 반환 성공"),
SUCCESS_GENERATE_TOKEN(OK, "토큰 발급 성공");
private final HttpStatus status;
private final String message;
Expand Down
Loading