안녕하세요. 답변에 감사드립니다.
하지만 포스트맨에서 카카오 로그인을 진행한 것은 아닙니다…!
Spring Security를 사용하여 oauth2 로그인을 진행했고 http://localhost:3000/main 화면으로 리다이렉트까지 완료했습니다.
그 후에 제가 개발에서 사용하는 API 아무거나 사용해도 kakao login html이 뜹니다.
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width">
<meta name="next-head-count" content="2">
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta content="website" property="og:type">
<meta content="카카오계정" property="og:title">
<meta content="https://accounts.kakaocdn.net/images/og_kakao.png" property="og:image">
<script type="text/javascript" src="//t1.daumcdn.net/tiara/js/v1/tiara.min.js" defer></script>
<link rel="preload" href="https://accounts.kakaocdn.net/_next/static/css/9771546e3178239c.css" as="style">
<link rel="stylesheet" href="https://accounts.kakaocdn.net/_next/static/css/9771546e3178239c.css" data-n-g="">
<link rel="preload" href="https://accounts.kakaocdn.net/_next/static/css/aa36f5129b871672.css" as="style">
<link rel="stylesheet" href="https://accounts.kakaocdn.net/_next/static/css/aa36f5129b871672.css" data-n-p="">
<link rel="preload" href="https://accounts.kakaocdn.net/_next/static/css/ace5cd78e5997324.css" as="style">
<link rel="stylesheet" href="https://accounts.kakaocdn.net/_next/static/css/ace5cd78e5997324.css" data-n-p="">
<noscript data-n-css=""></noscript>
<script defer nomodule="" src="https://accounts.kakaocdn.net/_next/static/chunks/polyfills-5cd94c89d3acac5f.js">
</script>
<script src="https://accounts.kakaocdn.net/_next/static/chunks/webpack-775174cedae781f8.js" defer></script>
<script src="https://accounts.kakaocdn.net/_next/static/chunks/framework-f8115f7fae64930e.js" defer></script>
<script src="https://accounts.kakaocdn.net/_next/static/chunks/main-a7d45bce11193232.js" defer></script>
<script src="https://accounts.kakaocdn.net/_next/static/chunks/pages/_app-b23efa0eb85a011c.js" defer></script>
<script src="https://accounts.kakaocdn.net/_next/static/chunks/29107295-f5d3d9a71e7e292a.js" defer></script>
<script src="https://accounts.kakaocdn.net/_next/static/chunks/70368-58b0a348debb6a04.js" defer></script>
<script src="https://accounts.kakaocdn.net/_next/static/chunks/69695-9ee32dd2295c9b6f.js" defer></script>
<script src="https://accounts.kakaocdn.net/_next/static/chunks/74534-ef40f6ad4c13b9c2.js" defer></script>
<script src="https://accounts.kakaocdn.net/_next/static/chunks/70224-19e687475e621ef1.js" defer></script>
<script src="https://accounts.kakaocdn.net/_next/static/chunks/3889-727e358a678e140d.js" defer></script>
<script src="https://accounts.kakaocdn.net/_next/static/chunks/pages/login/login-adfc2432b308a5cc.js" defer>
</script>
<script src="https://accounts.kakaocdn.net/_next/static/MtCeP08OTF9ONzZYVHnoR/_buildManifest.js" defer></script>
<script src="https://accounts.kakaocdn.net/_next/static/MtCeP08OTF9ONzZYVHnoR/_ssgManifest.js" defer></script>
<script src="https://accounts.kakaocdn.net/_next/static/MtCeP08OTF9ONzZYVHnoR/_middlewareManifest.js" defer>
</script>
</head>
<body class="os_other pc type_responsive">
<div id="__next" data-reactroot=""></div>
<script id="__NEXT_DATA__" type="application/json">
{"props":{"pageProps":{"pageContext":{"commonContext":{"locale":"ko","uaClass":"os_other pc","responsiveView":true,"responsivePopup":false,"mobile":false,"webview":{"app":"web","webViewType":"none","appVersion":"","os":"other","osVersion":"","supportNavigation":false,"supportFilePicker":true,"supportExecUrlScheme":false,"supportMarketUrlScheme":true},"supportRefererMetaTag":false,"showHeader":false,"showFooter":true,"linkParams":{},"showDarkMode":null,"_csrf":"3a4ee3d2-81e7-48e0-8948-e0e8c9cb0bc1","kage_file_max_size":100,"upload_kage_url":"https://up-api1-kage.kakao.com/up/kaccount-p/","p":"0mauVEPOFjLBn0DsRnWy9v8AtHz-RLgdpaAmpj4l3_8"},"context":{"webType":"web","defaultEmail":null,"showStaySignIn":true,"defaultStaySignIn":false,"appendStaySignedIn":false,"defaultCountryCode":"KR_82","showQrLogin":true,"showWebTalkLogin":false,"showDeviceFormLogin":false,"needCaptcha":false,"showIpSecurity":false,"loginUrl":"/login?continue=https%3A%2F%2Fkauth.kakao.com%2Foauth%2Fauthorize%3Fscope%3Dprofile_nickname%2520profile_image%2520account_email%26response_type%3Dcode%26state%3DxqnTVTa1fwwGM2EYVYrlKa1Tw-4grav3xJN6Ie1AmCE%253D%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A8080%252Flogin%252Foauth2%252Fcode%252Fkakao%26through_account%3Dtrue%26client_id%3D1ca922b87213dcdd6ecc7bc89a84113f","continueUrl":"https://kauth.kakao.com/oauth/authorize?scope=profile_nickname%20profile_image%20account_email&response_type=code&state=xqnTVTa1fwwGM2EYVYrlKa1Tw-4grav3xJN6Ie1AmCE%3D&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Flogin%2Foauth2%2Fcode%2Fkakao&through_account=true&client_id=1ca922b87213dcdd6ecc7bc89a84113f","useSimpleLogin":true,"exceedSimpleLoginLimit":false,"defaultSaveSignIn":false,"isTalkLoginError":false,"linkParams":{"lang":["ko"]},"requests":{"check_daum_sso":["get","https://logins.daum.net/accounts/endpoint/favicon.ico"]}}}}},"page":"/login/login","query":{},"buildId":"MtCeP08OTF9ONzZYVHnoR","assetPrefix":"https://accounts.kakaocdn.net","nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}
</script>
</body>
</html>
또한, http://localhost:3000/main 에서도 cors 오류가 뜨면서 accounts.kakao.com에서의 fetch가 실패했다고 뜹니다…
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*");
}
}
CORS 관리는 모두 허용해놓았는데 혹시 여기에서 더 추가해야 하는 부분이 있을까요?
정리하자면
- 로그인 이후 어떤 API 사용에서도 kakao login html이 뜬다.
- 로그인 이후 리다이렉트된 http://localhost:3000/main에서 호출하는 API에서 account.kakao.com에서 fetch가 실패했다며 CORS 오류가 나온다.
- 로그인 이후 frontend에서 로그인 되었다는 것을 판단하는 부분이 있는지, 아니면 따로 JWT같은 추가적인 보안을 구현하여 로그인을 판단하는 것인지
너무 많은 것을 여쭤보아서 죄송합니다… 정말 구글을 열심히 보아도 해결책이 나오지 않아서 혹시나 아시는 부분이 있는지 궁금하여 한번 여쭤봅니다…!