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:
Hyungi Ahn
2026-02-09 18:41:44 +09:00
parent 550633b89d
commit 6495b8af32
114 changed files with 1729 additions and 4335 deletions

View File

@@ -1,38 +1,77 @@
/**
* 공유 네비게이션 헤더
* 공유 네비게이션 헤더 + SSO 쿠키 유틸리티
*
* 각 시스템 페이지에서 import하여 통합 포털 네비게이션을 제공
* 각 시스템 페이지에서 import하여 SSO 인증 유틸 제공
* <script src="/shared/nav-header.js"></script>
*/
(function() {
const TOKEN_KEY = 'sso_token';
const USER_KEY = 'sso_user';
// 쿠키 헬퍼
function cookieGet(name) {
var match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
return match ? decodeURIComponent(match[1]) : null;
}
function cookieSet(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;
}
function cookieRemove(name) {
var cookie = name + '=; path=/; max-age=0';
if (window.location.hostname.includes('technicalkorea.net')) {
cookie += '; domain=.technicalkorea.net';
}
document.cookie = cookie;
}
/**
* SSO 토큰 가져오기
* SSO 인증 유틸리티 (쿠키 + localStorage 이중 지원)
*/
window.SSOAuth = {
getToken: function() {
return localStorage.getItem(TOKEN_KEY);
return cookieGet('sso_token') || localStorage.getItem('sso_token');
},
getUser: function() {
try {
return JSON.parse(localStorage.getItem(USER_KEY));
} catch {
return null;
}
var raw = cookieGet('sso_user') || localStorage.getItem('sso_user');
try { return JSON.parse(raw); } catch(e) { return null; }
},
isLoggedIn: function() {
return !!this.getToken();
var token = this.getToken();
return !!token && token !== 'undefined' && token !== 'null';
},
logout: function() {
localStorage.removeItem(TOKEN_KEY);
localStorage.removeItem(USER_KEY);
cookieRemove('sso_token');
cookieRemove('sso_user');
cookieRemove('sso_refresh_token');
localStorage.removeItem('sso_token');
localStorage.removeItem('sso_user');
localStorage.removeItem('sso_refresh_token');
window.location.href = '/login';
window.location.href = this.getLoginUrl();
},
/**
* 중앙 로그인 URL 반환
*/
getLoginUrl: function(redirect) {
var hostname = window.location.hostname;
var loginUrl;
if (hostname.includes('technicalkorea.net')) {
loginUrl = window.location.protocol + '//tkfb.technicalkorea.net/login';
} else {
// 개발 환경: Gateway 포트 (30000)
loginUrl = window.location.protocol + '//' + hostname + ':30000/login';
}
if (redirect) {
loginUrl += '?redirect=' + encodeURIComponent(redirect);
}
return loginUrl;
},
/**
@@ -41,7 +80,7 @@
fetch: function(url, options) {
options = options || {};
options.headers = options.headers || {};
const token = this.getToken();
var token = this.getToken();
if (token) {
options.headers['Authorization'] = 'Bearer ' + token;
}
@@ -49,27 +88,11 @@
},
/**
* 토큰 유효성 확인 (SSO 서비스 호출)
*/
validate: async function() {
const token = this.getToken();
if (!token) return false;
try {
const res = await fetch('/auth/validate', {
headers: { 'Authorization': 'Bearer ' + token }
});
return res.ok;
} catch {
return false;
}
},
/**
* 로그인 안 되어있으면 로그인 페이지로 리다이렉트
* 로그인 안 되어있으면 중앙 로그인 페이지로 리다이렉트
*/
requireLogin: function() {
if (!this.isLoggedIn()) {
window.location.href = '/login?redirect=' + encodeURIComponent(window.location.pathname);
window.location.href = this.getLoginUrl(window.location.href);
}
}
};