Skip to content

Commit

Permalink
fix: fix kakao login
Browse files Browse the repository at this point in the history
  • Loading branch information
GitJIHO committed Nov 15, 2024
1 parent d994536 commit d289a40
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 41 deletions.
58 changes: 27 additions & 31 deletions src/main/java/com/gdg/kkia/auth/service/KakaoApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<String, String> body = new LinkedMultiValueMap<>();
body.add("grant_type", "authorization_code");
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/com/gdg/kkia/common/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/**");
}
}

0 comments on commit d289a40

Please sign in to comment.