From aa5a128ae9255737ceeaeb58785078d739c5e668 Mon Sep 17 00:00:00 2001 From: wuseong Date: Tue, 6 Feb 2024 11:21:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EA=B0=9C=EB=B0=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=94=84=EB=9D=BC=20=ED=99=98=EA=B2=BD=EC=97=90=20=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=20=EC=8B=9C=20resuorces=EC=97=90=20=ED=82=A4=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .ebextensions_dev/00-makeFiles.config | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.ebextensions_dev/00-makeFiles.config b/.ebextensions_dev/00-makeFiles.config index 7cdf32c..c9b62f1 100644 --- a/.ebextensions_dev/00-makeFiles.config +++ b/.ebextensions_dev/00-makeFiles.config @@ -7,6 +7,9 @@ files: #!/usr/bin/env bash JAR_PATH=/var/app/current/application.jar + # Copy keyfile from S3 + aws s3 cp s3://onnoff-dev-s3/auth/AuthKey_5P49UCUSNW.p8 /var/app/current/src/main/resources/AuthKey_5P49UCUSNW.p8 + # run app killall java java -Dfile.encoding=UTF-8 -jar $JAR_PATH \ No newline at end of file From 8531c472dcb49c2128553dddeab5019cdc154f6b Mon Sep 17 00:00:00 2001 From: wuseong Date: Tue, 6 Feb 2024 11:22:06 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EC=95=A0=ED=94=8C=20=EC=95=A1?= =?UTF-8?q?=EC=84=B8=EC=8A=A4=20=ED=86=A0=ED=81=B0=20=EC=96=BB=EC=96=B4?= =?UTF-8?q?=EC=98=A4=EB=8A=94=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95(redirectUri=20=ED=95=84=EC=9A=94=20x)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onnoff/auth/controller/LoginController.java | 15 +++++++-------- .../onnoff/auth/service/AppleLoginService.java | 6 +----- src/main/resources/application.yml | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/onnoff/onnoff/auth/controller/LoginController.java b/src/main/java/com/onnoff/onnoff/auth/controller/LoginController.java index e9f76f8..a3545d6 100644 --- a/src/main/java/com/onnoff/onnoff/auth/controller/LoginController.java +++ b/src/main/java/com/onnoff/onnoff/auth/controller/LoginController.java @@ -18,12 +18,7 @@ import com.onnoff.onnoff.domain.user.converter.UserConverter; import com.onnoff.onnoff.domain.user.dto.UserResponseDTO; import com.onnoff.onnoff.domain.user.service.UserService; -import io.jsonwebtoken.ExpiredJwtException; -import io.jsonwebtoken.InvalidClaimException; -import io.jsonwebtoken.MalformedJwtException; -import io.jsonwebtoken.UnsupportedJwtException; import io.swagger.v3.oas.annotations.Operation; -import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -77,7 +72,8 @@ public ResponseEntity getAccessToken(@RequestParam(name = "code") String 4. 응답 헤더에 Jwt 토큰 추가 */ - @Operation(summary = "소셜 토큰 검증 API",description = "토큰을 검증 하고 이에 대한 결과를 응답합니다. 추가 정보 입력 여부도 같이 응답 합니다.") + @Operation(summary = "카카오 소셜 토큰 검증 API",description = "추가정보와 ID토큰을 받으면 ID토큰을 검증하고 통과 시" + + "서버에서 발급한 토큰을 받습니다. 회원가입을 하지 않은 사용자의 경우 회원가입을 시킵니다.") @ResponseBody @PostMapping("/oauth2/kakao/token/validate") public ApiResponse validateKakoToken(@RequestBody LoginRequestDTO.KakaoTokenValidateDTO requestDTO) { @@ -106,11 +102,14 @@ public ApiResponse validateKakoToken(@RequestBody Logi return ApiResponse.onSuccess(UserConverter.toLoginDTO(token.getAccessToken(), token.getRefreshToken())); } + @Operation(summary = "애플 소셜 토큰 검증 API",description = "추가정보와 ID토큰을 받으면 ID토큰을 검증하고 통과 시" + + "액세스/리프레시 토큰을 얻어서 저장시키고. 응답으로 서버에서 발급한 토큰을 받습니다. 회원가입을 하지 않은 사용자의 경우 회원가입을 시킵니다.") @ResponseBody @PostMapping("/oauth2/apple/token/validate") public ApiResponse validateAppleToken(@RequestBody LoginRequestDTO.AppleTokenValidateDTO requestDTO) { // 검증하기 appleLoginService.validate(requestDTO.getIdentityToken()); + log.info("애플 ID 토큰 검증 성공"); // 검증 성공 시 리프레시 토큰 발급받아 저장(기한 무제한, 회원탈퇴 시 필요) TokenResponse tokenResponse = appleLoginService.getAccessTokenByCode(requestDTO.getAuthorizationCode()); // 유저 정보 조회 및 저장 @@ -124,7 +123,7 @@ public ApiResponse validateAppleToken(@RequestBody Log user.setAppleRefreshToken(tokenResponse.getRefreshToken()); user = userService.create(user); } - // 응답헤더에 토큰 추가 + // 응답본문에 토큰 추가 JwtToken token = jwtUtil.generateToken(String.valueOf(user.getId())); return ApiResponse.onSuccess(UserConverter.toLoginDTO(token.getAccessToken(), token.getRefreshToken())); } @@ -164,4 +163,4 @@ public ResponseEntity testAfterGetToken(){ log.info("authenticatedUser = {}", UserContext.getUser()); // 테스트 성공 return ResponseEntity.ok(""); } -} +} \ No newline at end of file diff --git a/src/main/java/com/onnoff/onnoff/auth/service/AppleLoginService.java b/src/main/java/com/onnoff/onnoff/auth/service/AppleLoginService.java index 045358c..f15ad85 100644 --- a/src/main/java/com/onnoff/onnoff/auth/service/AppleLoginService.java +++ b/src/main/java/com/onnoff/onnoff/auth/service/AppleLoginService.java @@ -46,8 +46,6 @@ public class AppleLoginService implements LoginService{ private String iss; @Value("${apple.team-id}") private String teamId; - @Value("${apple.redirect-uri}") - private String redirectUri; @Override public TokenResponse getAccessTokenByCode(String code) { // client secret 만들기 @@ -56,9 +54,8 @@ public TokenResponse getAccessTokenByCode(String code) { MultiValueMap urlEncoded = TokenRequest.builder() .clientId(clientId) .clientSecret(clientSecret) - .code("authorization_code_value") + .code(code) .grantType("authorization_code") - .redirectUri(redirectUri) .build().toUrlEncoded(); return appleAuthClient.getToken(urlEncoded); } @@ -94,7 +91,6 @@ public String getAccessTokenByRfToken(String code) { .clientSecret(clientSecret) .refreshToken(appleRefreshToken) .grantType("refresh_token") - .redirectUri(redirectUri) .build().toUrlEncoded(); TokenResponse response = appleAuthClient.getToken(urlEncoded); return null; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3a7742c..b9eec07 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -19,7 +19,7 @@ apple: team-id: ${APPLE_TEAM_ID} # = ID prefix key: id: ${APPLE_KEY_ID} - path: classpath:/apple/AuthKey_${APPLE_KEY_ID}.p8 # 나중에 src/main/resources/apple/에 키 파일 저장, 그냥 문자열로 가져와도 될 것 같기도 + path: classpath:/AuthKey_${APPLE_KEY_ID}.p8 # 나중에 src/main/resources/apple/에 키 파일 저장, 그냥 문자열로 가져와도 될 것 같기도 kakao: redirect-uri: ${KAKAO_REDIRECT_URI} iss: https://kauth.kakao.com