Skip to content

Commit

Permalink
Merge pull request #13 from nhnacademy-be5-T3Team/feature/reissue
Browse files Browse the repository at this point in the history
feature:#12 Gateway에서 Reissue 진행시 request parameter 누락 해결
  • Loading branch information
joohyun1996 authored Apr 29, 2024
2 parents 50e73f3 + 7689d7c commit 1c8a697
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.URI;
import java.util.Objects;

/**
Expand Down Expand Up @@ -66,7 +65,13 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
WebClient webClient = WebClient.create();
Mono<ClientResponse> responseMono = webClient.post()
// 추후 profile별 url로 전송되게 해야함
.uri("http://localhost:8084/refresh")
.uri(uriBuilder -> uriBuilder
.scheme("http")
.host("localhost")
.port(8084)
.path("/refresh")
.query(exchange.getRequest().getURI().getQuery()) // 이전 요청의 쿼리 파라미터 추가
.build())
.header(HttpHeaders.AUTHORIZATION, "Bearer " + access)
.exchange();

Expand All @@ -75,7 +80,7 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
String receivedNewToken = resp.headers().asHttpHeaders().getFirst(HttpHeaders.AUTHORIZATION);

ServerHttpRequest originalReq = finalExchange.getRequest().mutate()
.uri(URI.create(originalUrl))
.uri(finalExchange.getRequest().getURI())
.header(HttpHeaders.AUTHORIZATION, receivedNewToken)
.build();

Expand All @@ -92,7 +97,13 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

WebClient webClient = WebClient.create();
Mono<ClientResponse> responseMono = webClient.post()
.uri("http://localhost:8084/refresh")
.uri(uriBuilder -> uriBuilder
.scheme("http")
.host("localhost")
.port(8084)
.path("/refresh")
.query(exchange.getRequest().getURI().getQuery()) // 이전 요청의 쿼리 파라미터 추가
.build())
.header(HttpHeaders.AUTHORIZATION, "Bearer " + access)
.exchange();

Expand All @@ -101,7 +112,7 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
String receivedNewToken = resp.headers().asHttpHeaders().getFirst(HttpHeaders.AUTHORIZATION);

ServerHttpRequest originalReq = finalExchange.getRequest().mutate()
.uri(URI.create(originalUrl))
.uri(finalExchange.getRequest().getURI())
.header(HttpHeaders.AUTHORIZATION, receivedNewToken)
.build();

Expand Down

0 comments on commit 1c8a697

Please sign in to comment.