-
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
Changes from 29 commits
2cb3959
3c119f8
729d7d2
9cbfc2e
e056905
0dc50e4
233661a
18f3496
a1e7533
b5163eb
9c10d45
92cb531
a7291a8
47ef3ea
5a76a50
ab0063d
ab0b0ab
dff5e2e
31407ab
448011e
c421394
40cac6f
36a64b1
1eb8eb4
5ef8308
82925fa
95bea5d
7e53464
41b234b
dffed00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} | ||
} |
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`") | ||||||
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. 이거 백틱이 아니라 작은 따옴표 써야하지 않나여?
Suggested change
|
||||||
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. 넵! |
||||||
} | ||||||
} |
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 stats | ||
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. 이거 혹시 오타인지? 아님말구~ |
||
) { | ||
|
||
} |
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; | ||
} | ||
} |
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 | ||
) { | ||
|
||
} |
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.
넵