1
0
forked from baron/baron-sso

Align RP auto login launch behavior

This commit is contained in:
2026-04-30 16:36:40 +09:00
parent 28a440734c
commit d16f6cdcb4
7 changed files with 76 additions and 21 deletions

View File

@@ -22,7 +22,13 @@ export default function AuthGuard() {
}
if (!auth.isAuthenticated) {
return <Navigate to="/login" replace />;
const returnTo = `${location.pathname}${location.search}`;
return (
<Navigate
to={`/login?returnTo=${encodeURIComponent(returnTo)}`}
replace
/>
);
}
// 조직도 앱은 일반 사용자(user)도 볼 수 있어야 하므로 접근 제한을 해제합니다.

View File

@@ -18,7 +18,7 @@ function LoginPage() {
const [searchParams] = useSearchParams();
const autoStartedRef = useRef(false);
const returnTo = searchParams.get("returnTo") || "/chart";
const shouldAutoLogin = searchParams.get("auto") === "1";
const shouldAutoLogin = searchParams.get("auto") !== "0";
useEffect(() => {
if (auth.isAuthenticated) {

View File

@@ -56,8 +56,8 @@ export function getOrgChartUserDisplayName(
const { jobTitle, position } = getUserOrgProfile(user, tenant);
const baseName = user.name.trim();
if (jobTitle && position) return `${baseName} ${position}[${jobTitle}]`;
if (jobTitle) return `${baseName}[${jobTitle}]`;
if (jobTitle && position) return `${baseName}(${jobTitle}) ${position}`;
if (jobTitle) return `${baseName}(${jobTitle})`;
if (position) return `${baseName} ${position}`;
return baseName;
}

View File

@@ -1,8 +1,6 @@
import { expect, test } from "@playwright/test";
import { expect, test, type Page } from "@playwright/test";
test("orgfront login auto parameter starts OIDC authorization", async ({
page,
}) => {
async function stubOidcAuthorization(page: Page) {
let authorizationURL = "";
await page.route(
@@ -32,11 +30,19 @@ test("orgfront login auto parameter starts OIDC authorization", async ({
},
);
await page.goto("/login?auto=1&returnTo=%2Fpicker");
return {
authorizationURL: () => authorizationURL,
};
}
await expect.poll(() => authorizationURL).toContain("/oauth2/auth");
test("orgfront login defaults to OIDC authorization", async ({ page }) => {
const oidc = await stubOidcAuthorization(page);
const parsed = new URL(authorizationURL);
await page.goto("/login");
await expect.poll(oidc.authorizationURL).toContain("/oauth2/auth");
const parsed = new URL(oidc.authorizationURL());
expect(parsed.searchParams.get("client_id")).toBe("orgfront");
expect(parsed.searchParams.get("redirect_uri")).toBe(
"http://localhost:5175/auth/callback",
@@ -44,3 +50,32 @@ test("orgfront login auto parameter starts OIDC authorization", async ({
expect(parsed.searchParams.get("response_type")).toBe("code");
expect(parsed.searchParams.get("scope") ?? "").toContain("openid");
});
test("orgfront login auto parameter starts OIDC authorization", async ({
page,
}) => {
const oidc = await stubOidcAuthorization(page);
await page.goto("/login?auto=1&returnTo=%2Fpicker");
await expect.poll(oidc.authorizationURL).toContain("/oauth2/auth");
const parsed = new URL(oidc.authorizationURL());
expect(parsed.searchParams.get("client_id")).toBe("orgfront");
expect(parsed.searchParams.get("redirect_uri")).toBe(
"http://localhost:5175/auth/callback",
);
expect(parsed.searchParams.get("response_type")).toBe("code");
expect(parsed.searchParams.get("scope") ?? "").toContain("openid");
});
test("orgfront login can opt out of default OIDC authorization", async ({
page,
}) => {
const oidc = await stubOidcAuthorization(page);
await page.goto("/login?auto=0");
await page.waitForTimeout(500);
expect(oidc.authorizationURL()).toBe("");
});