Skip to content

Commit

Permalink
Merge pull request #271 from sopt-makers/feat/#270_T-10863
Browse files Browse the repository at this point in the history
#270 [fix] /authorize 명세 수정
  • Loading branch information
KWY0218 authored Jun 26, 2024
2 parents cf70d1b + 0859f5d commit d0cbcad
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 25 deletions.
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;

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

0 comments on commit d0cbcad

Please sign in to comment.