Skip to content

Commit

Permalink
29 breaking change token response header에서 parameter로 변경 (#30)
Browse files Browse the repository at this point in the history
* fix: comment child Build.Default apply (#29)

* fix: token header -> parameter (#29)
  • Loading branch information
toychip authored Jan 5, 2024
1 parent 28f002a commit 097771b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'com.api'
version = '0.0.1-SNAPSHOT'
version = '0.3.3-token'

java {
sourceCompatibility = '17'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class Comment extends BaseEntity {
@JoinColumn(name = "parent_id")
private Comment parent;

@Builder.Default
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE, orphanRemoval = true)
private List<Comment> child = new ArrayList<>(); // 자식 댓글들

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void onAuthenticationSuccess(final HttpServletRequest request, final Http
() -> new ApiException(_SERVER_USER_NOT_FOUND));
String loginMemberId = String.valueOf(loginMember.getId());

registerHeaderToken(response, loginMemberId);
String token = generateToken(loginMemberId);

AuthResponse authResponse = AuthResponse.builder()
.memberId(loginMember.getId())
Expand All @@ -61,7 +61,7 @@ public void onAuthenticationSuccess(final HttpServletRequest request, final Http
.build();

// ToDo 아래는 임시 데이터, front와 협의 후 수정
registerResponse(response, authResponse);
registerResponse(response, authResponse, token);
}

private GithubUserInfo createGitHubUserInfo(final CustomOauth2User oauth2User) {
Expand All @@ -72,23 +72,22 @@ private GithubUserInfo createGitHubUserInfo(final CustomOauth2User oauth2User) {
.build();
}

private void registerHeaderToken(final HttpServletResponse response, final String loginMemberId) {
private String generateToken(final String loginMemberId) {
String ourToken = jwtProvider.generateJwtToken(loginMemberId);
// 어세스 토큰은 헤더에 담아서 응답으로 보냄
response.setHeader("Authorization", ourToken);
log.info("ourToken = " + ourToken);
return ourToken;
}

private void registerResponse(final HttpServletResponse response,
final AuthResponse authResponse) throws IOException {
final AuthResponse authResponse, String token) throws IOException {
String encodedMemberId = URLEncoder.encode(String.valueOf(authResponse.memberId()), StandardCharsets.UTF_8);
String encodedLoginId = URLEncoder.encode(authResponse.gitLoginId(), StandardCharsets.UTF_8);
String encodedGitProfileImageUrl = URLEncoder.encode(authResponse.gitProfileImageUrl(), StandardCharsets.UTF_8);

// 프론트엔드 페이지로 토큰과 함께 리다이렉트
String frontendRedirectUrl = String.format(
"%s/oauth2/github/code?memberId=%s&gitLoginId=%s&profileImgUrl=%s",
REDIRECT_URL, encodedMemberId, encodedLoginId, encodedGitProfileImageUrl
"%s/?token=%s&memberId=%s&gitLoginId=%s&profileImgUrl=%s",
REDIRECT_URL, token, encodedMemberId, encodedLoginId, encodedGitProfileImageUrl
);
response.sendRedirect(frontendRedirectUrl);
}
Expand Down

0 comments on commit 097771b

Please sign in to comment.