-
Notifications
You must be signed in to change notification settings - Fork 0
feat(web): config-driven login auth options #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@evidence-browser/api": minor | ||
| --- | ||
|
|
||
| Add config-driven login rendering for issue #167 so deployments can expose OIDC SSO, local login, or both from `/api/auth/config`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| import { expect, test, type Page } from "@playwright/test"; | ||
|
|
||
| type AuthConfig = { | ||
| local: boolean; | ||
| oidc: { | ||
| enabled: boolean; | ||
| label: string; | ||
| }; | ||
| }; | ||
|
|
||
| async function stubLoginPrerequisites(page: Page) { | ||
| await page.route("**/api/auth/me", async (route) => { | ||
| await route.fulfill({ | ||
| status: 401, | ||
| contentType: "application/json", | ||
| body: JSON.stringify({ error: "Unauthenticated" }), | ||
| }); | ||
| }); | ||
| await page.route("**/api/setup/status", async (route) => { | ||
| await route.fulfill({ | ||
| status: 200, | ||
| contentType: "application/json", | ||
| body: JSON.stringify({ needsSetup: false, hasAdmin: true, hasWorkspace: true }), | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| async function stubAuthConfig(page: Page, config: AuthConfig) { | ||
| await page.route("**/api/auth/config", async (route) => { | ||
| await route.fulfill({ | ||
| status: 200, | ||
| contentType: "application/json", | ||
| body: JSON.stringify(config), | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| async function gotoLogin(page: Page, path: string, configuredBaseURL?: string) { | ||
| const baseURL = configuredBaseURL ?? process.env.PLAYWRIGHT_BASE_URL ?? "http://127.0.0.1:3000"; | ||
| await page.goto(new URL(path, baseURL).toString()); | ||
| } | ||
|
|
||
| test.beforeEach(async ({ page }) => { | ||
| await stubLoginPrerequisites(page); | ||
| }); | ||
|
|
||
| test("does not render sign-in controls while auth config is loading", async ({ page, baseURL }) => { | ||
| await page.route("**/api/auth/config", () => undefined); | ||
|
|
||
| await gotoLogin(page, "/login?callbackUrl=%2Fw%2Finfra", baseURL); | ||
|
|
||
| await expect(page.getByLabel("Username")).toHaveCount(0); | ||
| await expect(page.getByLabel("Password")).toHaveCount(0); | ||
| await expect(page.getByRole("button", { name: "Sign in" })).toHaveCount(0); | ||
| await expect(page.getByRole("link", { name: /SSO/ })).toHaveCount(0); | ||
| }); | ||
|
|
||
| test("renders the unchanged local-only login form", async ({ page, baseURL }) => { | ||
| await stubAuthConfig(page, { | ||
| local: true, | ||
| oidc: { enabled: false, label: "Sign in with SSO" }, | ||
| }); | ||
|
|
||
| await gotoLogin(page, "/login?callbackUrl=%2Fw%2Finfra", baseURL); | ||
|
|
||
| await expect(page.getByRole("heading", { name: "Sign in to your workspace" })).toBeVisible(); | ||
| await expect(page.getByText("Enter your credentials to access your workspace.")).toBeVisible(); | ||
| await expect(page.getByLabel("Username")).toBeVisible(); | ||
| await expect(page.getByLabel("Password")).toBeVisible(); | ||
| await expect(page.getByRole("button", { name: "Sign in" })).toBeVisible(); | ||
| await expect(page.getByRole("link", { name: "Sign in with SSO" })).toHaveCount(0); | ||
| await expect(page.getByRole("separator", { name: "or" })).toHaveCount(0); | ||
| }); | ||
|
|
||
| test("renders local form with divider and SSO button when both modes are enabled", async ({ page, baseURL }) => { | ||
| await stubAuthConfig(page, { | ||
| local: true, | ||
| oidc: { enabled: true, label: "Continue with Acme SSO" }, | ||
| }); | ||
|
|
||
| await gotoLogin(page, "/login?callbackUrl=%2Fw%2Finfra", baseURL); | ||
|
|
||
| await expect(page.getByLabel("Username")).toBeVisible(); | ||
| await expect(page.getByLabel("Password")).toBeVisible(); | ||
| await expect(page.getByRole("button", { name: "Sign in" })).toBeVisible(); | ||
| await expect(page.getByRole("separator", { name: "or" })).toBeVisible(); | ||
| await expect(page.getByRole("link", { name: "Continue with Acme SSO" })).toHaveAttribute( | ||
| "href", | ||
| "/api/auth/oidc/start?callbackUrl=%2Fw%2Finfra" | ||
| ); | ||
| }); | ||
|
|
||
| test("renders only the SSO button when local login is disabled", async ({ page, baseURL }) => { | ||
| await stubAuthConfig(page, { | ||
| local: false, | ||
| oidc: { enabled: true, label: "Continue with Company SSO" }, | ||
| }); | ||
|
|
||
| await gotoLogin(page, "/login?callbackUrl=%2Fadmin", baseURL); | ||
|
|
||
| await expect(page.getByText("Continue with single sign-on to access your workspace.")).toBeVisible(); | ||
| await expect(page.getByText("Enter your credentials to access your workspace.")).toHaveCount(0); | ||
| await expect(page.getByRole("link", { name: "Continue with Company SSO" })).toBeVisible(); | ||
| await expect(page.getByLabel("Username")).toHaveCount(0); | ||
| await expect(page.getByLabel("Password")).toHaveCount(0); | ||
| await expect(page.getByRole("button", { name: "Sign in" })).toHaveCount(0); | ||
| await expect(page.getByRole("separator", { name: "or" })).toHaveCount(0); | ||
| }); | ||
|
|
||
| test("uses full-page SSO navigation with the current callbackUrl", async ({ page, baseURL }) => { | ||
| await stubAuthConfig(page, { | ||
| local: false, | ||
| oidc: { enabled: true, label: "Continue with SSO" }, | ||
| }); | ||
| await page.route("**/api/auth/oidc/start**", async (route) => { | ||
| await route.fulfill({ | ||
| status: 204, | ||
| }); | ||
| }); | ||
|
|
||
| await gotoLogin(page, "/login?callbackUrl=%2Fw%2Finfra%3Ftab%3Dfiles", baseURL); | ||
|
|
||
| const requestPromise = page.waitForRequest("**/api/auth/oidc/start?callbackUrl=%2Fw%2Finfra%3Ftab%3Dfiles"); | ||
| await page.getByRole("link", { name: "Continue with SSO" }).click(); | ||
|
|
||
| expect((await requestPromise).url()).toContain("/api/auth/oidc/start?callbackUrl=%2Fw%2Finfra%3Ftab%3Dfiles"); | ||
| }); | ||
|
|
||
| test("renders safe OIDC error copy without raw error detail", async ({ page, baseURL }) => { | ||
| await stubAuthConfig(page, { | ||
| local: false, | ||
| oidc: { enabled: true, label: "Continue with SSO" }, | ||
| }); | ||
|
|
||
| await gotoLogin(page, "/login?error=oidc_failed&callbackUrl=%2F", baseURL); | ||
|
|
||
| const loginCard = page.locator(".relative.z-10"); | ||
| await expect(page.getByText("Single sign-on could not be completed. Try again or use another sign-in method.")).toBeVisible(); | ||
| await expect(loginCard).not.toContainText("oidc_failed"); | ||
| await expect(loginCard).not.toContainText("issuer"); | ||
| }); | ||
|
|
||
| test("falls back to local login when auth config fails", async ({ page, baseURL }) => { | ||
| await page.route("**/api/auth/config", async (route) => { | ||
| await route.fulfill({ | ||
| status: 503, | ||
| contentType: "application/json", | ||
| body: JSON.stringify({ error: "Config unavailable" }), | ||
| }); | ||
| }); | ||
|
|
||
| await gotoLogin(page, "/login?callbackUrl=%2F", baseURL); | ||
|
|
||
| await expect(page.getByText("Could not load sign-in options. Local sign-in is still available.")).toBeVisible(); | ||
| await expect(page.getByLabel("Username")).toBeVisible(); | ||
| await expect(page.getByLabel("Password")).toBeVisible(); | ||
| await expect(page.getByRole("button", { name: "Sign in" })).toBeVisible(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2 — changeset targets the wrong package.
This changeset bumps
@evidence-browser/api": minor, but every file this PR touches is underpackages/web/**(router.tsx,lib/api.ts,lib/types.ts, tests, e2e spec).packages/apihas no changes here — the/api/auth/configroute itself already shipped in #175 (bright-rivers-serve.md, correctly scoped to@evidence-browser/api).As written,
changeset versionwill bump@evidence-browser/apiwith an empty diff and give@evidence-browser/web— the package that actually changed — no version bump or CHANGELOG entry. Should be:Non-blocking for functionality, but worth a one-line fix before/at merge so the release changelog stays accurate.
Generated by Claude Code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in
89d85e9: the changeset now targets@evidence-browser/weband usespatch, matching the issue'schangeset:patchlabel.