-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: Authorization Server로 부터 토큰 발급 기능 추가 #24
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
2cb3959
feat: 회원 엔티티 생성 및 테스트코드 추가
parksey 3c119f8
feat: 카카오 OAuth 환경변수 추가 및 클래스 바인딩
parksey 729d7d2
feat: authorization code를 받기 위한 queryString generator 추가
parksey 9cbfc2e
feat: Authorization code의 parameter 만드는 로직 분리 및 테스트 코드 추가
parksey e056905
feat: 회원 가입/로그인 요청 api 및 소셜 로그인 페이지 반환
parksey 0dc50e4
refactor: member관련 클래스 네이밍과 폴더 위치 변경
parksey 233661a
refactor: 로그인 페이지 요청 방식 Resttemplate -> response (redirect)하도록 변경
parksey 18f3496
style: 코드 포맷 재적용 및 사용하지 않는 클래스 삭제
parksey a1e7533
chore: config 파일 업데이트
parksey b5163eb
refactor: 테스트 코드 추가 및 코드 포맷 재적용
parksey 9c10d45
refactor: 사용하지 않는 코드 제거
parksey 92cb531
refactor: CRLF -> LF로 변경
parksey a7291a8
fix: config 커밋, config 최근 커밋으로 변경
parksey 47ef3ea
feat: 테스트 코드 추가 및 패키지 구조 변경
parksey 5a76a50
refactor: revert merge
parksey ab0063d
Merge branch 'develop' into feature/#5
parksey ab0b0ab
fix: merge confilt해결 및 예외처리 추가
parksey dff5e2e
test: oauth properties가 없을 때의 테스트코드 추가
parksey 31407ab
feat: 코드리뷰에 따른 기능 분리 및 테스트 코드 변경
parksey 448011e
fix: 테스트코드 관련 code smell 제거
parksey c421394
feat: Authorization grant 받기 예외 코드 및 테스트 코드 추가
parksey 40cac6f
refactor: develop브랜치 merge
parksey 36a64b1
feat: Authorization Token 요청 및 반환 코드, 에러 반환 테스트 코드 추가
parksey 1eb8eb4
refactor: AuthenticationService에서 서버에 요청보내는 로직 OAuth2AuthorizationSer…
parksey 5ef8308
test: 로그인 요청 테스트 코드 추가
parksey 82925fa
feat: 토큰 발급 요청 기능 테스트 코드 추가 및 RestTemplate 필드변수로 변경
parksey 95bea5d
refactor: develop 브랜치 merge
parksey 7e53464
test: restTemplate 및 서비스 테스트 추가
parksey 41b234b
refactor: 에러 메세지 이름 변경
parksey dffed00
refacotr: 변수명 및 entity default 명 변경
parksey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/com/moabam/api/application/OAuth2AuthorizationServerRequestService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.moabam.api.application; | ||
|
||
import java.io.IOException; | ||
|
||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import com.moabam.api.dto.AuthorizationTokenResponse; | ||
import com.moabam.global.common.util.GlobalConstant; | ||
import com.moabam.global.error.exception.BadRequestException; | ||
import com.moabam.global.error.model.ErrorMessage; | ||
|
||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
@Service | ||
public class OAuth2AuthorizationServerRequestService { | ||
|
||
private final RestTemplate restTemplate; | ||
|
||
public OAuth2AuthorizationServerRequestService() { | ||
restTemplate = new RestTemplate(); | ||
} | ||
|
||
public void loginRequest(HttpServletResponse httpServletResponse, String authorizationCodeUri) { | ||
try { | ||
httpServletResponse.setContentType(MediaType.APPLICATION_FORM_URLENCODED + GlobalConstant.CHARSET_UTF_8); | ||
httpServletResponse.sendRedirect(authorizationCodeUri); | ||
} catch (IOException e) { | ||
throw new BadRequestException(ErrorMessage.REQUEST_FAILED); | ||
} | ||
} | ||
|
||
public ResponseEntity<AuthorizationTokenResponse> requestAuthorizationServer(String tokenUri, | ||
MultiValueMap<String, String> uriParams) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add(HttpHeaders.CONTENT_TYPE, | ||
MediaType.APPLICATION_FORM_URLENCODED_VALUE + GlobalConstant.CHARSET_UTF_8); | ||
HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(uriParams, headers); | ||
|
||
ResponseEntity<AuthorizationTokenResponse> authorizationTokenResponse = restTemplate.exchange(tokenUri, | ||
HttpMethod.POST, httpEntity, AuthorizationTokenResponse.class); | ||
|
||
if (authorizationTokenResponse.getStatusCode().isError()) { | ||
throw new BadRequestException(ErrorMessage.REQUEST_FAILED); | ||
} | ||
|
||
return authorizationTokenResponse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
@Entity | ||
@Getter | ||
@Table(name = "member") | ||
@SQLDelete(sql = "UPDATE member SET deleted_at = CURRENT_TIMESTAMP where participant_id = ?") | ||
@SQLDelete(sql = "UPDATE member SET deleted_at = CURRENT_TIMESTAMP where id = ?") | ||
@Where(clause = "deleted_at IS NOT NULL") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Member extends BaseTimeEntity { | ||
|
@@ -72,7 +72,7 @@ public class Member extends BaseTimeEntity { | |
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "role", nullable = false) | ||
@ColumnDefault("USER") | ||
@ColumnDefault("'USER'") | ||
private Role role; | ||
|
||
@Column(name = "deleted_at") | ||
|
@@ -87,4 +87,24 @@ private Member(Long id, String socialId, String nickname, String profileImage, B | |
this.bug = requireNonNull(bug); | ||
this.role = Role.USER; | ||
} | ||
|
||
public void enterMorningRoom() { | ||
currentMorningCount++; | ||
} | ||
|
||
public void enterNightRoom() { | ||
currentNightCount++; | ||
} | ||
|
||
public void exitMorningRoom() { | ||
if (currentMorningCount > 0) { | ||
currentMorningCount--; | ||
} | ||
} | ||
|
||
public void exitNightRoom() { | ||
if (currentMorningCount > 0) { | ||
currentNightCount--; | ||
} | ||
Comment on lines
+90
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 넵! |
||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/moabam/api/dto/AuthorizationCodeResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.moabam.api.dto; | ||
|
||
public record AuthorizationCodeResponse( | ||
String code, | ||
String error, | ||
String errorDescription, | ||
String state | ||
) { | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/moabam/api/dto/AuthorizationTokenRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.moabam.api.dto; | ||
|
||
import static java.util.Objects.*; | ||
|
||
import lombok.Builder; | ||
|
||
public record AuthorizationTokenRequest( | ||
String grantType, | ||
String clientId, | ||
String redirectUri, | ||
String code, | ||
String clientSecret | ||
) { | ||
|
||
@Builder | ||
public AuthorizationTokenRequest(String grantType, String clientId, String redirectUri, String code, | ||
String clientSecret) { | ||
this.grantType = requireNonNull(grantType); | ||
this.clientId = requireNonNull(clientId); | ||
this.redirectUri = requireNonNull(redirectUri); | ||
this.code = requireNonNull(code); | ||
this.clientSecret = clientSecret; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/moabam/api/dto/AuthorizationTokenResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.moabam.api.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record AuthorizationTokenResponse( | ||
@JsonProperty("token_type") String tokenType, | ||
@JsonProperty("access_token") String accessToken, | ||
@JsonProperty("id_token") String idToken, | ||
@JsonProperty("expires_in") String expiresIn, | ||
@JsonProperty("refresh_token") String refreshToken, | ||
@JsonProperty("refresh_token_expires_in") String refreshTokenExpiresIn, | ||
@JsonProperty("scope") String scope | ||
) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
R: 제가 다음 PR에 Apache Commons Lang 3 추가했습니다.
StringUtils.isEmpty()로 쓰면 String을 null safe하게 검증할 수 있습니다.
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.
넵