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

[Mod] 토큰 전달 방식 변경 #192

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from

Conversation

seokjun01
Copy link
Contributor

@seokjun01 seokjun01 commented Mar 1, 2025

개요

토큰 전달 방식을 기존의 쿠키방식에서 헤더를 통해 전달하는 방식으로 변경하였습니다.

기존의 로직 : 프론트 측에서 클라이언트를 구글로그인으로 리다이렉션 하면, 서버에서 인증/인가로직을 다 마치고 발급된 토큰을 쿠키에 담아서 전달해주는 방식

변경 후 : 프론트 측 구글로그인으로 리다이렉션 -> 인가코드를 서버에 전달 (api호출) -> 인증 후 토큰 발급하여 헤더에 담아 전달

로컬에서 테스트하면서 구글 정책위반 (invalid_request) 에러가 많이떠서,
Google_Client_ID, 시크릿 값을 환경변수에 넣어서처리 하면 에러가 발생함을 인지하였습니다.
하드코딩하여 테스트해본 결과 토큰 발급이 정상적으로 처리되었고, 야믈파일의 값을 그대로 불러오는 properties 파일을 생성하여 토큰 발급 서비스 로직에 주입하여 사용하였습니다.

커밋은 자주하지 않았으나 , 수정이 잦아 파일이 다소 난잡할 수 있는점 양해부탁드립니다.😢
문법오류나 , 궁금한 점 있으시면 리뷰 달아주시고 3일 후 머지하겠습니다.

PR 유형

어떤 변경 사항이 있나요?

  • 새로운 기능 추가
  • 버그 수정
  • CSS 등 사용자 UI 디자인 변경
  • 코드에 영향을 주지 않는 변경사항(오타 수정, 탭 사이즈 변경, 변수명 변경)
  • 코드 리팩토링
  • 주석 추가 및 수정
  • 문서 수정
  • 테스트 추가, 테스트 리팩토링
  • 빌드 부분 혹은 패키지 매니저 수정
  • 파일 혹은 폴더명 수정
  • 파일 혹은 폴더 삭제

PR Checklist

PR이 다음 요구 사항을 충족하는지 확인하세요.

  • 커밋 메시지 컨벤션에 맞게 작성했습니다.
  • 변경 사항에 대한 테스트를 했습니다.(버그 수정/기능에 대한 테스트).

📣 To Reviewers

@seokjun01 seokjun01 added mod 코드 및 내부 파일 수정 석준 labels Mar 1, 2025
@seokjun01 seokjun01 self-assigned this Mar 1, 2025
@seokjun01 seokjun01 requested review from ehs208, jj0526 and dyk-im and removed request for ehs208 and jj0526 March 1, 2025 18:48
Copy link
Member

@ehs208 ehs208 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다..!
PR 내용 중 야믈파일의 값을 그대로 불러오는 properties 파일을 생성하여 라는 부분이 이해가 안가는데 혹시 다시 설명해주실 수 있을까요?
그리고 추가로 yaml파일을 생성/변경 하셨다면 GitHub Actions 스크립트 혹은 Secret 수정 해주셔야 할거 같습니다!

Copy link
Member

Choose a reason for hiding this comment

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

이 파일은 사용안하신다면 지워주셔도 될거같습니다

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 삭제하겠습니다

// JWT를 **응답 헤더에 추가**
jwtService.sendAccessAndRefreshToken(response, accessToken, refreshToken);

// 클라이언트로 리디렉트 (토큰은 헤더에 포함됨)
response.sendRedirect("https://develop.d4u0qurydeei4.amplifyapp.com/intro/oauth2/callback");
Copy link
Member

Choose a reason for hiding this comment

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

저희 도메인 구매했기때문에 도메인으로 변경해도 될거같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

콜백페이지는 아직 프론트 구현되었는지 확인해봐야하는거 아닌지 여쭤보고 싶습니다.
그냥 저희 구매한 도메인 붙이고 /intro/oauth2/callback 이렇게 쓰면 될까요?

Copy link
Member

Choose a reason for hiding this comment

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

네 프론트 구현여부에 상관없을거 같습니다..!


import lombok.Data;

@Data
Copy link
Member

Choose a reason for hiding this comment

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

자동으로 getter, setter, equals, hashCode, toString를 생성해주는 메서드라고 하는데, 필요한 메소드만 생성하는 방향으로 변경해주시면 좋을 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 반영하겠습니다!

Copy link
Member

Choose a reason for hiding this comment

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

DTO 객체인가요? 맞다면 파일명에 Dto임을 인지할수 있게 명시해주면 좋을 것 같습니다.
@JsonProperty는 JSON에서 Key값 지정해주는 어노테이션으로 보여지는데 불필요한 어노테이션 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네 맞습니다. DTO로 사용하기 위해 dto 디렉토리안에 생성하였습니다. 파일명 변경하겠습니다!
@JsonProperty에 관해서는 구글 토큰 발급 Client 영역에서 넘어오는 Snake Case 문법을 Camel Case로 바꾸는 데에 사용하였습니다

Comment on lines 69 to 86
@PostMapping("/google")
public ResponseEntity<?> googleOAuthLogin(@RequestParam("code") String code) {
if (code == null || code.isEmpty()) {
return ResponseEntity.badRequest().body("인가 코드가 없습니다.");
}

log.info("Google OAuth2 로그인 요청, 원본 인가코드: {}", code);

OAuthToken tokenResponse = googleOAuth2Service.getGoogleAccessToken(code);
String googleAccessToken = tokenResponse.getAccessToken(); // 정상적으로 접근 가능

log.info("Google Access Token 발급 완료: {}", googleAccessToken);

// Google 사용자 정보 가져오기
UserLoginResponseDto response = googleOAuth2Service.processGoogleUserLogin(googleAccessToken);

return ResponseEntity.ok().body(response);
}
Copy link
Member

Choose a reason for hiding this comment

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

저희가 사용하던 방식과 같이 GlobalResponseDto 객체 포함하여 리턴하는 메소드로 변경해 주시면 좋을 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 이부분 수정하겠습니다

@@ -76,15 +73,15 @@ public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();

configuration.setAllowedOrigins(Arrays.asList(
"http://localhost:3000/",
"http://localhost:3000",
"https://develop.d4u0qurydeei4.amplifyapp.com"
Copy link
Member

Choose a reason for hiding this comment

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

저희가 구입한 도메인도 추가해주시면 좋을거 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

넵 추가하겠습니다!

Copy link
Contributor

@dyk-im dyk-im left a comment

Choose a reason for hiding this comment

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

수정된 로직 모두 확인했습니다. 고생 많으셨습니다. 궁금한 점 일부 남겨뒀습니다. 그리고 기존의 토큰 방식에서 헤더방식으로 바꾼 이유 그리고 최초 시도에서는 헤더 토큰 방식이 안됐었던 것으로 기억하는데 지금 방식과의 차이에 대해 설명 해주시면 감사하겠습니다!!

@seokjun01
Copy link
Contributor Author

고생하셨습니다..! PR 내용 중 야믈파일의 값을 그대로 불러오는 properties 파일을 생성하여 라는 부분이 이해가 안가는데 혹시 다시 설명해주실 수 있을까요? 그리고 추가로 yaml파일을 생성/변경 하셨다면 GitHub Actions 스크립트 혹은 Secret 수정 해주셔야 할거 같습니다!

개발 당시 처음에@value 어노테이션을 사용하여서, yaml파일의 값을 불러오려고 했는데 google 보안 정책 에러가 자꾸 떠서
실제 값을 하드코딩해서 테스트 해보니까 정상 작동하였습니다. 그래서 @value 어노테이션 말고 다르게 주입할 방법을 찾다가 properties 파일을 만들어서 @ConfigurationProperties어노테이션을 통해 값을 불러오는 방법을 선택했습니다
yml파일 변경 여부 확인후 변경 사항있을 시 수정해두겠습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod 코드 및 내부 파일 수정 석준
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[mod] 토큰 전달 방식 변경
3 participants