Skip to content

Commit

Permalink
hotfix: 소셜 로그인 리다이렉트 URI가 작동하지 않는 문제 수정 (#689)
Browse files Browse the repository at this point in the history
fix: 추가 파라미터에서 리다이렉트 URI로 수정
  • Loading branch information
uwoobeat authored Aug 26, 2024
1 parent 52c4a44 commit 0b16b50
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import static com.gdschongik.gdsc.global.common.constant.SecurityConstant.*;

import jakarta.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizationRequestResolver;
import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestResolver;
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
import org.springframework.web.util.UriComponentsBuilder;

public class CustomOAuth2AuthorizationRequestResolver implements OAuth2AuthorizationRequestResolver {

Expand All @@ -35,15 +34,17 @@ private OAuth2AuthorizationRequest customizeAuthorizationRequest(
HttpServletRequest request, OAuth2AuthorizationRequest authorizationRequest) {

String referer = request.getHeader("Referer");

if (referer == null || referer.isEmpty()) {
return authorizationRequest;
}

Map<String, Object> additionalParameters = new HashMap<>();
additionalParameters.put(OAUTH_TARGET_URL_PARAM_NAME, referer);
String redirectUri = UriComponentsBuilder.fromHttpUrl(authorizationRequest.getRedirectUri())
.queryParam(OAUTH_TARGET_URL_PARAM_NAME, referer)
.toUriString();

return OAuth2AuthorizationRequest.from(authorizationRequest)
.additionalParameters(additionalParameters)
.redirectUri(redirectUri)
.build();
}
}

0 comments on commit 0b16b50

Please sign in to comment.