Skip to content

Commit

Permalink
Merge staging
Browse files Browse the repository at this point in the history
  • Loading branch information
BYEONGRYEOL committed Aug 25, 2024
2 parents cd853f3 + a62c8f1 commit 5f5cf27
Show file tree
Hide file tree
Showing 30 changed files with 413 additions and 409 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/cicd-ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,17 @@ jobs:
cd ./genti-external/src/main
mkdir -p ./resources && cd ./resources
touch ./AuthKey_ZRZMQQX883.p8
echo "${{ secrets.APPLE_PRIVATE_KEY }}" > AuthKey_ZRZMQQX883.p8
echo "${{ secrets.APPLE_PRIVATE_KEY }}" > ./AuthKey_ZRZMQQX883.p8
shell: bash

# - name: make fcm private key
# run: |
# cd ./genti-external/src/main
# mkdir -p ./resources && cd ./resources
# touch ./firebase-genti.json
# echo "${{ secrets.FIREBASE_PRIVATE_KEY }}" > ./firebase-genti.json
# shell: bash

- name: make staging docker-compose file
if: contains(github.ref, 'staging')
run: |
Expand Down Expand Up @@ -139,7 +147,7 @@ jobs:
run: |
docker build -f ./Dockerfile_deploy -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
- name: Upload docker-compose, appspec, afterInstall file to S3
if: contains(github.ref, 'main')
Expand All @@ -149,15 +157,15 @@ jobs:
cp -r ./scripts/* temp_dir/scripts/
cp appspec.yml temp_dir/
cp ./docker/deploy/docker-compose.yml temp_dir/docker-compose.yml
# Navigate to the temporary directory and create the zip file
cd temp_dir
zip -r ../$GITHUB_SHA.zip ./*

# Move back to the initial directory and upload the zip file to S3
cd ..
aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME

# Clean up the temporary directory
rm -rf temp_dir
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ application-staging.yml
application-staging.yaml

docker/db/
docker/redis/

other/genti-sbl-iam_accessKeys.csv

Expand All @@ -63,4 +64,5 @@ firebase-genti.json

*.pem

AuthKey_ZRZMQQX883.p8
AuthKey_ZRZMQQX883.p8
/genti-api/src/main/resources/static/swagger.json
21 changes: 13 additions & 8 deletions genti-api/src/main/java/com/gt/genti/auth/api/AuthApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.view.RedirectView;

import com.gt.genti.auth.dto.request.TokenRefreshRequestDto;
import com.gt.genti.auth.dto.response.AuthUriResponseDto;
import com.gt.genti.auth.dto.response.OauthJwtResponse;
import com.gt.genti.error.ResponseCode;
import com.gt.genti.jwt.TokenResponse;
Expand All @@ -19,20 +19,20 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;

@Tag(name = "[AuthController] 인증 컨트롤러", description = "로그인을 처리한 후 토큰을 전달합니다.")
public interface AuthApi {
@Operation(summary = "oauth 로그인 페이지 호출", description = "카카오 oauth 로그인 페이지 로 Redirect, 이후 로그인 성공시 다시 admin page로 redirect됩니다.(Genti token은 cookie에)")
RedirectView login(

@Operation(summary = "Oauth 로그인 페이지 주소 얻기", description = "Oauth 로그인 페이지 주소 얻기")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK),
})
ResponseEntity<ApiResult<AuthUriResponseDto>> getAuthUri(
@Parameter(description = "호출할 Oauth platform 종류", example = "KAKAO", schema = @Schema(allowableValues = {
"KAKAO"}))
@RequestParam(name = "oauthPlatform") OauthPlatform oauthPlatform);
Expand All @@ -58,8 +58,13 @@ ResponseEntity<ApiResult<OauthJwtResponse>> loginKakao(
@RequestBody @Valid KakaoAccessTokenDto tokenDto
);

ResponseEntity<ApiResult<OauthJwtResponse>> kakaoRedirectLogin(
@Operation(summary = "Kakao 웹 로그인", description = "Kakao 로그인 api")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK),
})
ResponseEntity<ApiResult<OauthJwtResponse>> loginKakaoWeb(
HttpServletResponse response,
@Parameter(name = "code", description = "kakao 로그인페이지 로그인 성공 후 url에서 추출한 code값")
@RequestParam(name = "code") String code);

@Operation(summary = "테스트용 jwt 토큰 발급", description = "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@

import static com.gt.genti.response.GentiResponse.*;

import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Map;

import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.view.RedirectView;

import com.gt.genti.auth.api.AuthApi;
import com.gt.genti.auth.dto.request.AppleAuthTokenDto;
import com.gt.genti.auth.dto.request.KakaoAccessTokenDto;
import com.gt.genti.auth.dto.request.KakaoAuthorizationCodeDto;
import com.gt.genti.auth.dto.request.TokenRefreshRequestDto;
import com.gt.genti.auth.dto.response.AuthUriResponseDto;
import com.gt.genti.auth.dto.response.OauthJwtResponse;
import com.gt.genti.auth.dto.response.SocialWebLoginResponse;
import com.gt.genti.auth.service.AuthService;
import com.gt.genti.jwt.JwtTokenProvider;
import com.gt.genti.jwt.TokenGenerateCommand;
Expand All @@ -29,15 +28,13 @@
import com.gt.genti.model.LogItem;
import com.gt.genti.model.LogRequester;
import com.gt.genti.model.Logging;
import com.gt.genti.response.GentiResponse;
import com.gt.genti.picturegeneraterequest.service.PictureGenerateFailedEventPublisher;
import com.gt.genti.picturegenerateresponse.service.PGRESCompleteEventPublisher;
import com.gt.genti.user.model.OauthPlatform;
import com.gt.genti.user.model.UserRole;
import com.gt.genti.auth.dto.request.AppleAuthTokenDto;
import com.gt.genti.auth.dto.request.KakaoAccessTokenDto;

import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
Expand All @@ -52,21 +49,23 @@ public class AuthController implements AuthApi {

private final JwtTokenProvider jwtTokenProvider;
private final AuthService authService;
private final PGRESCompleteEventPublisher pGRESCompleteEventPublisher;
private final PictureGenerateFailedEventPublisher pictureGenerateFailedEventPublisher;

@GetMapping("/login/oauth2")
@Logging(item = LogItem.OAUTH_WEB, action = LogAction.LOGIN, requester = LogRequester.ANONYMOUS)
public RedirectView login(
public ResponseEntity<ApiResult<AuthUriResponseDto>> getAuthUri(
@Parameter(description = "호출할 Oauth platform 종류", example = "KAKAO", schema = @Schema(allowableValues = {
"KAKAO"}))
@RequestParam(name = "oauthPlatform") OauthPlatform oauthPlatform) {
return new RedirectView(authService.getOauthRedirect(oauthPlatform));
return success(AuthUriResponseDto.of(oauthPlatform.getStringValue(), authService.getOauthUri(oauthPlatform)));
}

@PostMapping("/login/oauth2/token/apple")
@Logging(item = LogItem.OAUTH_APPLE, action = LogAction.LOGIN, requester = LogRequester.ANONYMOUS)
public ResponseEntity<ApiResult<OauthJwtResponse>> loginApple(
@RequestBody @Valid AppleAuthTokenDto request) {
return success(authService.appleLogin(request).token());
return success(authService.appleLogin(request));
}

@PostMapping("/login/oauth2/token/kakao")
Expand All @@ -77,35 +76,12 @@ public ResponseEntity<ApiResult<OauthJwtResponse>> loginKakao(
return success(authService.kakaoAppLogin(tokenDto));
}

@GetMapping("/login/oauth2/code/kakao")
@GetMapping("/login/oauth2/web/kakao")
@Logging(item = LogItem.OAUTH_KAKAO, action = LogAction.LOGIN, requester = LogRequester.ANONYMOUS)
public ResponseEntity<ApiResult<OauthJwtResponse>> kakaoRedirectLogin(
public ResponseEntity<ApiResult<OauthJwtResponse>> loginKakaoWeb(
HttpServletResponse response,
@RequestParam(name = "code") final String code) {
SocialWebLoginResponse socialWebLoginResponse = authService.kakaoWebLogin(KakaoAuthorizationCodeDto.of(code));

return success(socialWebLoginResponse.getToken());
// TODO: 2024-08-18 0818 운영테스트 하고 다시 돌려놓기

// String accessToken = socialWebLoginResponse.getToken().accessToken();
// String refreshToken = socialWebLoginResponse.getToken().refreshToken();
// accessToken = accessToken.substring("Bearer ".length());
// refreshToken = refreshToken.substring("Bearer ".length());
// Cookie accessTokenCookie = new Cookie("Access-Token", accessToken);
// accessTokenCookie.setHttpOnly(true);
// accessTokenCookie.setPath("/");
//
// Cookie refreshTokenCookie = new Cookie("Refresh-Token", refreshToken);
// refreshTokenCookie.setHttpOnly(true);
// refreshTokenCookie.setPath("/");
//
// response.addCookie(accessTokenCookie);
// response.addCookie(refreshTokenCookie);
// try {
// response.sendRedirect("http://localhost:5173/login/kakao/success");
// } catch (IOException e) {
// throw new RuntimeException("서버에서 redirect중 에러가 발생했습니다.");
// }
return success(authService.kakaoWebLogin(KakaoAuthorizationCodeDto.of(code)));
}

@GetMapping("/login/testjwt")
Expand All @@ -131,4 +107,16 @@ public ResponseEntity<ApiResult<TokenResponse>> reissue(
return success(authService.reissue(tokenRefreshRequestDto));
}

@PostMapping("/fcmtest/userId/{userId}")
public ResponseEntity<ApiResult<Boolean>> fcmtest(
@RequestParam(name = "success") String success,
@PathVariable Long userId) {

if ("success".equals(success)) {
pGRESCompleteEventPublisher.publishPictureGenerateCompleteEvent(userId);
} else {
pictureGenerateFailedEventPublisher.publishPictureGenerateFailedEvent(userId);
}
return success(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ public class AppleAuthTokenDto {
@NotBlank
@Schema(description = "id_token", example = "id_token")
String identityToken;

@NotBlank
@Schema(description = "fcm token", example = "FCM 서버로부터 받은 기기의 fcm token")
String fcmToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ public class KakaoAccessTokenDto {
@NotBlank
@Schema(description = "accessToken", example = "accessToken")
private String accessToken;

@NotBlank
@Schema(description = "fcm token", example = "FCM 서버로부터 받은 기기의 fcm token")
String fcmToken;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.gt.genti.auth.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(name = "[Auth][Anonymous] 소셜로그인 uri 응답 Dto")
public record AuthUriResponseDto(
@Schema(description = "접두사를 포함한 액세스 토큰")
String oauthPlatform,
@Schema(description = "접두사를 포함한 액세스 토큰")
String uri
) {

public static AuthUriResponseDto of(String oauthPlatForm, String uri) {
return new AuthUriResponseDto(oauthPlatForm, uri);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

import com.gt.genti.constants.JWTConstants;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

@Schema(name = "[Auth][Anonymous] 소셜 로그인 응답 Dto")
public record OauthJwtResponse(
@Schema(description = "접두사를 포함한 액세스 토큰")
String accessToken,
@Schema(description = "접두사를 포함한 리프레시 토큰")
String refreshToken,
@Schema(description = "접두사를 포함한 리프레시 토큰", allowableValues = {"OAUTH_FIRST_JOIN", "ADMIN", "USER"})
String userRoleString
) {
public static OauthJwtResponse of(String accessToken, String refreshToken, String userRoleString) {
return new OauthJwtResponse(JWTConstants.JWT_PREFIX + accessToken, JWTConstants.JWT_PREFIX + refreshToken,
userRoleString);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.gt.genti.auth.dto.request.KakaoAuthorizationCodeDto;
import com.gt.genti.auth.dto.request.TokenRefreshRequestDto;
import com.gt.genti.auth.dto.response.OauthJwtResponse;
import com.gt.genti.auth.dto.response.SocialWebLoginResponse;
import com.gt.genti.jwt.JwtTokenProvider;
import com.gt.genti.jwt.TokenResponse;
import com.gt.genti.user.model.OauthPlatform;
Expand All @@ -27,19 +26,19 @@ public class AuthService {
private final KakaoOauthStrategy kakaoOauthStrategy;
private final JwtTokenProvider jwtTokenProvider;

public SocialWebLoginResponse kakaoWebLogin(final KakaoAuthorizationCodeDto request) {
public OauthJwtResponse kakaoWebLogin(final KakaoAuthorizationCodeDto request) {
return kakaoOauthStrategy.webLogin(request);
}

public SocialWebLoginResponse appleLogin(final AppleAuthTokenDto request) {
public OauthJwtResponse appleLogin(final AppleAuthTokenDto request) {
return appleOauthStrategy.login(request);
}

public OauthJwtResponse kakaoAppLogin(final KakaoAccessTokenDto request) {
return kakaoOauthStrategy.tokenLogin(request).getToken();
return kakaoOauthStrategy.tokenLogin(request);
}

public String getOauthRedirect(OauthPlatform oauthPlatform) {
public String getOauthUri(OauthPlatform oauthPlatform) {
return switch (oauthPlatform) {
case KAKAO -> kakaoOauthStrategy.getAuthUri();
// case APPLE -> appleOauthStrategy.getAuthUri();
Expand Down
Loading

0 comments on commit 5f5cf27

Please sign in to comment.