diff --git a/src/main/java/com/gdg/kkia/auth/service/KakaoApiService.java b/src/main/java/com/gdg/kkia/auth/service/KakaoApiService.java index 0a1d304..a8b7c98 100644 --- a/src/main/java/com/gdg/kkia/auth/service/KakaoApiService.java +++ b/src/main/java/com/gdg/kkia/auth/service/KakaoApiService.java @@ -28,22 +28,20 @@ public class KakaoApiService { private final KakaoProperties kakaoProperties; public String getAuthorizationUrl(HttpServletRequest httpServletRequest) { -// String requestUrl = httpServletRequest.getHeader("Referer"); -// if (requestUrl == null) { -// throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다."); -// } -// String redirectUri; -// -// if (requestUrl.contains(LOCALHOST_URL)) { -// redirectUri = kakaoProperties.devRedirectUri(); -// } else if (requestUrl.contains(kakaoProperties.frontUriWithoutHttp())) { -// redirectUri = kakaoProperties.redirectUri(); -// } else { -// throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다. requestUrl : " + requestUrl); -// } - - String redirectUri = "https://kkia.backapi.site/redirection"; -// + String requestUrl = httpServletRequest.getHeader("Referer"); + if (requestUrl == null) { + throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다."); + } + String redirectUri; + + if (requestUrl.contains(LOCALHOST_URL)) { + redirectUri = kakaoProperties.devRedirectUri(); + } else if (requestUrl.contains(kakaoProperties.frontUriWithoutHttp())) { + redirectUri = kakaoProperties.redirectUri(); + } else { + throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다. requestUrl : " + requestUrl); + } + return KAKAO_AUTH_BASE_URL + "/authorize?response_type=code&client_id=" + kakaoProperties.clientId() + "&redirect_uri=" + redirectUri; } @@ -53,21 +51,19 @@ public KakaoTokenResponse getAccessToken(String authorizationCode, HttpServletRe HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); -// String requestUrl = httpServletRequest.getHeader("Origin"); -// if (requestUrl == null) { -// throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다."); -// } -// String redirectUri; -// -// if (requestUrl.contains(LOCALHOST_URL)) { -// redirectUri = kakaoProperties.devRedirectUri(); -// } else if (requestUrl.contains(kakaoProperties.frontUriWithoutHttp())) { -// redirectUri = kakaoProperties.redirectUri(); -// } else { -// throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다. requestUrl : " + requestUrl); -// } - - String redirectUri = "https://kkia.backapi.site/redirection"; + String requestUrl = httpServletRequest.getHeader("Origin"); + if (requestUrl == null) { + throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다."); + } + String redirectUri; + + if (requestUrl.contains(LOCALHOST_URL)) { + redirectUri = kakaoProperties.devRedirectUri(); + } else if (requestUrl.contains(kakaoProperties.frontUriWithoutHttp())) { + redirectUri = kakaoProperties.redirectUri(); + } else { + throw new BadRequestException("해당 도메인에서는 카카오 로그인이 불가합니다. requestUrl : " + requestUrl); + } LinkedMultiValueMap body = new LinkedMultiValueMap<>(); body.add("grant_type", "authorization_code"); diff --git a/src/main/java/com/gdg/kkia/common/config/WebConfig.java b/src/main/java/com/gdg/kkia/common/config/WebConfig.java index 8f95436..5272989 100644 --- a/src/main/java/com/gdg/kkia/common/config/WebConfig.java +++ b/src/main/java/com/gdg/kkia/common/config/WebConfig.java @@ -84,15 +84,9 @@ public CorsFilter corsFilter() { @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(jwtInterceptor) - .excludePathPatterns("/**"); - -// .excludePathPatterns("/redirection/**") -// .excludePathPatterns("/redirection") -// .excludePathPatterns("/oauth/**") -// .excludePathPatterns("/v2/**") -// .excludePathPatterns("/api/auth/**") -// .excludePathPatterns("/api/temp/**") -// .excludePathPatterns("/swagger-ui/**") -// .excludePathPatterns("/v3/api-docs/**"); + .excludePathPatterns("/api/auth/**") + .excludePathPatterns("/api/temp/**") + .excludePathPatterns("/swagger-ui/**") + .excludePathPatterns("/v3/api-docs/**"); } }