Skip to content

Comments

Be/oauth/main#121

Open
ghost wants to merge 9 commits intobe/mainfrom
be/oauth/main
Open

Be/oauth/main#121
ghost wants to merge 9 commits intobe/mainfrom
be/oauth/main

Conversation

@ghost
Copy link

@ghost ghost commented Jun 17, 2021

IOS쪽 App등록과
code를 받아오기, redirectUri 구현을 프론트 서버로 수정 해야 합니다.
token을 통해 GitHub Api로 userName, login, avatar정보를 받아옵니다.

  • 인터셉터와 loginRequired를 통해 ("/auht")로 시작하는 부분에 로그인 컨피그를 걸었는데 이부분에 대한 수정도 필요해 보입니다.

@ghost ghost added the backend Backend label Jun 17, 2021
@ghost ghost requested a review from Dae-Hwa June 17, 2021 07:43
@ghost ghost assigned Dae-Hwa and ghost Jun 17, 2021
Copy link
Collaborator

@Dae-Hwa Dae-Hwa left a comment

Choose a reason for hiding this comment

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

어노테이션으로 검증하게 만드셨군요
고생많으셨습니다!

절차적으로 작성 된 부분이 많은데,
한 번에 다 고치기는 힘들수도 있을 것 같아요
힘든 부분은 말씀해주시면 나눠서 고쳐보겠습니다.

implementation 'org.springframework.boot:spring-boot-starter-hateoas'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
ㄹ implementation 'org.projectlombok:lombok:1.18.16'
Copy link
Collaborator

Choose a reason for hiding this comment

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

문제 생기지 않았나요? 그리고 굳이 필요 없어 보입니다.

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

// NOTE: Login이 필요한 API일 경우 사용
Copy link
Collaborator

Choose a reason for hiding this comment

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

멋지네요. 어노테이션을 만드신거군요 ㅋㅋ

이런 주석은 java docs로 메모해두는게 더 좋을 것 같습니다.

//Fixme : front로 변경
@GetMapping("/callback")
public void callback(@RequestParam(value = "code") String code) throws AuthException {
auth(code);
Copy link
Collaborator

Choose a reason for hiding this comment

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

핸들러에서 핸들러를 호출하는 구조는 좀 어색해보이는데 이유가 있나요?

Copy link
Author

Choose a reason for hiding this comment

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

이 부분이 저도 절대 하면 안되는 걸 알지만... callback쪽은 프론트 단에서 구현해야하는 부분이라 생각해서 저렇게 구현을 했습니다

Comment on lines 35 to 45
GitHubAccessTokenResponse token = authService.getAccessToken(code);
String accessToken = token.getAccessToken();

UserDto userDto = authService.getUserFromGitHub(accessToken);

AuthResponse authResponse = new AuthResponse(JwtUtil.createJwt(userDto));

ResponseEntity<AuthResponse> authResponseResponseEntity = ResponseEntity.status(HttpStatus.CREATED).
body(new AuthResponse(JwtUtil.createJwt(userDto)));

return authResponseResponseEntity;
Copy link
Collaborator

Choose a reason for hiding this comment

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

서비스 로직으로 옮겨야 할 것 같습니다.
그리고 더 나아가면 도메인처럼 생각해볼 수도 있겠죠?

Comment on lines +3 to +13
public class AuthRequest {
private String code;

public AuthRequest(String code) {
this.code = code;
}

public String getCode() {
return code;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

이런 부분은 롬복으로 처리해도 충분하다고 봅니다

public UserDto getUserFromGitHub(String accessToken) throws AuthException {
RequestEntity<Void> request = RequestEntity
.get(gitHubUserUri)
.header("Accept", "application/json")
Copy link
Collaborator

Choose a reason for hiding this comment

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

이런 부분은 중복 제거 시도해볼 수도 있겠네요

Comment on lines +42 to +43
return Optional.ofNullable(response.getBody())
.orElseThrow(() -> new AuthException("Access Token 획득 실패"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

null 체크를 위한 용도면 Optional을 사용할 필요는 없는 것 같아요

import lombok.Data;

@Data
public class JwtUtil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

위에서도 말했지만, 객체로 만들 수 있을 것 같네요


import com.fasterxml.jackson.annotation.JsonProperty;

public class UserDto {
Copy link
Collaborator

Choose a reason for hiding this comment

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

깃헙유저에만 사용되지 않을까요?

}
}

public static UserDto decodeJwt(String token) throws JwtException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

throws 붙이신 이유가 뭔가요?

@Dae-Hwa Dae-Hwa changed the base branch from be/label/main to be/main June 18, 2021 03:13
FE, IOS타입에 따라서 clientId, secret의 값을 다르게 리턴
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.projectlombok:lombok:1.18.16'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
implementation 'org.projectlombok:lombok:1.18.16'

없애주세요

Comment on lines 30 to 31
annotationProcessor 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok'
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기에 의존성 등록 돼 있습니다~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants