feat: SSO 쿠키 인증 통합 + 서브도메인 라우팅 아키텍처
- Path-based 라우팅을 서브도메인 기반으로 전환 (tkfb/tkreport/tkqc.technicalkorea.net) - 3개 시스템 프론트엔드에 SSO 쿠키 인증 통합 (domain=.technicalkorea.net, localStorage 폴백) - Gateway: 포털+로그인+System1 프록시, 쿠키 SSO 설정 - System 1: 토큰키 통일, nginx.conf 생성, 신고페이지 리다이렉트 - System 2: api-base.js/app-init.js 생성, getSSOToken() 통합 - System 3: TokenManager 쿠키 지원, 중앙 로그인 리다이렉트 - docker-compose.yml에 cloudflared 서비스 추가 - DEPLOY-GUIDE.md 배포 가이드 작성 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -98,16 +98,39 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// SSO 쿠키 유틸리티
|
||||
var ssoCookie = {
|
||||
set: function(name, value, days) {
|
||||
var cookie = name + '=' + encodeURIComponent(value) + '; path=/';
|
||||
if (days) cookie += '; max-age=' + (days * 86400);
|
||||
if (window.location.hostname.includes('technicalkorea.net')) {
|
||||
cookie += '; domain=.technicalkorea.net; secure; samesite=lax';
|
||||
}
|
||||
document.cookie = cookie;
|
||||
},
|
||||
get: function(name) {
|
||||
var match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
|
||||
return match ? decodeURIComponent(match[1]) : null;
|
||||
},
|
||||
remove: function(name) {
|
||||
var cookie = name + '=; path=/; max-age=0';
|
||||
if (window.location.hostname.includes('technicalkorea.net')) {
|
||||
cookie += '; domain=.technicalkorea.net';
|
||||
}
|
||||
document.cookie = cookie;
|
||||
}
|
||||
};
|
||||
|
||||
async function handleLogin(e) {
|
||||
e.preventDefault();
|
||||
const btn = document.getElementById('submitBtn');
|
||||
const errEl = document.getElementById('errorMsg');
|
||||
var btn = document.getElementById('submitBtn');
|
||||
var errEl = document.getElementById('errorMsg');
|
||||
errEl.style.display = 'none';
|
||||
btn.disabled = true;
|
||||
btn.textContent = '로그인 중...';
|
||||
|
||||
try {
|
||||
const res = await fetch('/auth/login', {
|
||||
var res = await fetch('/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
@@ -116,21 +139,28 @@
|
||||
})
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
var data = await res.json();
|
||||
|
||||
if (!res.ok || !data.success) {
|
||||
throw new Error(data.error || '로그인에 실패했습니다');
|
||||
}
|
||||
|
||||
// 토큰과 유저 정보 저장
|
||||
// 쿠키에 토큰 저장 (서브도메인 공유)
|
||||
ssoCookie.set('sso_token', data.access_token, 7);
|
||||
ssoCookie.set('sso_user', JSON.stringify(data.user), 7);
|
||||
if (data.refresh_token) {
|
||||
ssoCookie.set('sso_refresh_token', data.refresh_token, 30);
|
||||
}
|
||||
|
||||
// localStorage에도 저장 (같은 도메인 내 호환성)
|
||||
localStorage.setItem('sso_token', data.access_token);
|
||||
localStorage.setItem('sso_user', JSON.stringify(data.user));
|
||||
if (data.refresh_token) {
|
||||
localStorage.setItem('sso_refresh_token', data.refresh_token);
|
||||
}
|
||||
|
||||
// 포털로 이동
|
||||
const redirect = new URLSearchParams(location.search).get('redirect');
|
||||
// redirect 파라미터가 있으면 해당 URL로, 없으면 포털로
|
||||
var redirect = new URLSearchParams(location.search).get('redirect');
|
||||
window.location.href = redirect || '/';
|
||||
} catch (err) {
|
||||
errEl.textContent = err.message;
|
||||
@@ -141,9 +171,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 이미 로그인 되어있으면 포털로
|
||||
if (localStorage.getItem('sso_token')) {
|
||||
window.location.href = '/';
|
||||
// 이미 로그인 되어있으면 포털로 (쿠키 또는 localStorage 체크)
|
||||
var existingToken = ssoCookie.get('sso_token') || localStorage.getItem('sso_token');
|
||||
if (existingToken && existingToken !== 'undefined' && existingToken !== 'null') {
|
||||
var redirect = new URLSearchParams(location.search).get('redirect');
|
||||
window.location.href = redirect || '/';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user