미인증 진입 시 중간 화면 없이 곧장 Keycloak 로그인 폼으로 리다이렉트

- requireAuth: /login 거치지 않고 loginRedirect로 직접 Keycloak으로
- /login 라우트도 oidcReady면 즉시 리다이렉트
- OIDC discovery 실패 시에만 안내 페이지 폴백, /api/*는 401 유지

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-23 09:29:58 +09:00
parent 792b9b9c72
commit 35d5d70a1d
2 changed files with 17 additions and 4 deletions

View File

@@ -5,7 +5,7 @@ import { fileURLToPath } from "url";
import path from "path";
import { config } from "./config.js";
import { siteGroups } from "./sites.js";
import { initOidc, loginRedirect, handleCallback, requireAuth } from "./auth.js";
import { initOidc, loginRedirect, handleCallback, requireAuth, oidcReady } from "./auth.js";
import * as db from "./db.js";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -36,9 +36,14 @@ app.use((req, res, next) => {
app.get("/healthz", (_req, res) => res.json({ ok: true }));
// --- 인증 ---
// SSO 세션이 없으면 중간 페이지 없이 바로 Keycloak(커스텀 테마) 로그인으로 보낸다.
// (OIDC 초기화 실패 등으로 로그인 불가하면 안내용 login.ejs 로 폴백)
app.get("/login", (req, res) => {
if (req.session.user) return res.redirect("/");
res.render("login");
if (req.query.error) return res.render("login", { error: req.query.error });
// OIDC 준비됐으면 중간 화면 없이 곧장 Keycloak 로그인 폼으로
if (oidcReady()) return loginRedirect(req, res);
return res.render("login", { error: "로그인 서비스를 사용할 수 없습니다. 잠시 후 다시 시도해 주세요." });
});
app.get("/auth/login", (req, res) => loginRedirect(req, res));
app.get("/auth/callback", async (req, res) => {