-
Notifications
You must be signed in to change notification settings - Fork 0
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
🔀 :: google oauth2 로그인 #6
Conversation
@Value("${jwt.secret}") | ||
private String secretKey; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
직접 값을 받는 것 보단 Properties 클래스를 만들어서 따로 관리하는 게 어떨까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
말하신게 이렇게 만드는게 맞나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 @Value
말고 @ConfigurationProperties
써서 accessToken과 refreshToken을 받는 것을 말하는 거 였는데 죄송합니다
제가 너무 추상적으로 말한 것 같네요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했습니다
src/main/resources/application.yml
Outdated
secret: ${JWT_SECRET} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JwtTokenProvider 로직을 보니 AccessToken과 RefreshToken를 서명할 때 동일한 key를 사용하는 것으로 보여지는데 보안쪽 측면에서는 따로 Secret 값을 분리하는 게 좋을 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했어요
private static Key key; | ||
private final AuthDetailsService authDetailsService; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static Key key; | |
private final AuthDetailsService authDetailsService; | |
private static Key key; | |
private final AuthDetailsService authDetailsService; |
@PostMapping | ||
public ResponseEntity<TokenInfoResponseDto> test(@RequestBody SignInRequestDto signInRequestDto) { | ||
TokenInfoResponseDto res = signInService.execute(signInRequestDto); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트하시고 나서 메서드 이름을 안 바꾸신 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했어요
public class SignInRequestDto { | ||
private String code; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DTO를 정의할 때, 일반적으로 불변 필드만 선언할 수 있으며, 생성자, Getter, equals(), toString()을 자동으로 생성해 주는 record를 사용하는 것이 어떨까요? 이런 특징들이 DTO의 특성과도 잘 맞아 좋은 시너지를 낼 것 같다고 생각합니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했습니다!
public class TokenInfoResponseDto { | ||
private String accessToken; | ||
private String refreshToken; | ||
private LocalDateTime accessTokenExpiresIn; | ||
private LocalDateTime refreshTokenExpiresIn; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dto라고 했으니 Response에도 똑같이 적용해 주시면 될 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response 부분은 까먹었던것 같아요 수정했습니다
public class ErrorResponse { | ||
private HttpStatus status; | ||
private String message; | ||
|
||
public static ResponseEntity<ErrorResponse> toResponseEntity(ErrorCode e){ | ||
return ResponseEntity | ||
.status(e.getHttpStatus()) | ||
.body(ErrorResponse.builder() | ||
.status(e.getHttpStatus()) | ||
.message(e.getMessage()) | ||
.build() | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기도요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
뭔가 한번에 리뷰를 안남겨서 많이 불편하실 텐데 양해 부탁드립니다
|
||
HttpEntity<?> request = new HttpEntity<>(body, httpHeaders); | ||
|
||
ResponseEntity<Map> response = restTemplate.exchange(config.getUserInfoUri(), HttpMethod.GET, request, Map.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RestTemplate에서 반환받은 값의 타입을 지정할 때 제네릭을 사용하려면 ParameterizedTypeReference<반환받을 값 타입>() {}과 같이 사용해서 정확한 타입을 지정할 수 있어요
이 예시에서는 Map.class 대신에 new ParameterizedTypeReference<Map<String, String>() {}를 사용하면 될 것 같네요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정했어요
|
||
HttpEntity<?> request = new HttpEntity<>(body, httpHeaders); | ||
|
||
ResponseEntity<Map> response = restTemplate.postForEntity(config.getTokenUri(), request, Map.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기도 똑같이 적용해주시면 될 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
늦어서 죄송합니다. 수고하셨습니다!!
💡 배경 및 개요
google oauth 사용해서 로그인 기능 구현했습니다
Resolves: #5
📃 작업내용
🙋♂️ 리뷰노트
Authorization Code Grant
방식을 사용해서 oauth 구현했습니다jwt, security 설정을 같이해서 코드의 양이 많아서 천천히 확인 하셔도 괜찮을것 같아요
✅ PR 체크리스트
.env
,노션
,README
)"API 개발 완료됐어요"
,"환경값 추가되었어요"
)🎸 기타