Skip to content
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

머지 #112

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client:3.2.4'
implementation 'org.springframework.security:spring-security-oauth2-client:6.2.3'

// webClient
implementation 'org.springframework.boot:spring-boot-starter-webflux'

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriComponentsBuilder;

import javax.servlet.http.*;
import java.net.URI;
import reactor.core.publisher.Mono;

@Controller
public class Auth0Controller {

@Value("${auth0.domain}")
private String auth0Domain;

@Value("${auth0.clientId}")
private String clientId;

@Value("${auth0.callbackUrl}")
private String redirectUri;

@GetMapping("/auth")
public void authProxy(HttpServletRequest request, HttpServletResponse response) throws Exception {
String queryString = request.getQueryString();
Expand All @@ -41,25 +37,18 @@ public void authProxy(HttpServletRequest request, HttpServletResponse response)
public ResponseEntity<String> tokenProxy(HttpServletRequest request) throws Exception {
String tokenEndpoint = "https://" + auth0Domain + "/oauth/token";

// 요청의 form 데이터를 그대로 전달
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

// 요청 파라미터 가져오기
String formData = request.getReader().lines()
.reduce("", (accumulator, actual) -> accumulator + actual);

HttpEntity<String> entity = new HttpEntity<>(formData, headers);

ResponseEntity<String> response = restTemplate.exchange(
tokenEndpoint,
HttpMethod.POST,
entity,
String.class
);
WebClient webClient = WebClient.create();
Mono<String> response = webClient.post()
.uri(tokenEndpoint)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.bodyValue(formData)
.retrieve()
.bodyToMono(String.class);

return ResponseEntity.status(response.getStatusCode())
.body(response.getBody());
return ResponseEntity.ok(response.block());
}
}
Loading