diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md
index 9a7a9b92..00afb9b4 100644
--- a/DEVELOPMENT.md
+++ b/DEVELOPMENT.md
@@ -473,6 +473,15 @@ The login screen is **identifier-first** by default (username → password
prompt, or a 302 to the IdP when the identifier's email domain matches an OIDC
realm's `login_domains`); set the `login_mode` setting to `combined` (Admin →
Settings) for a classic combined form with per-realm OIDC buttons.
+`/auth/identify` routes by realm configuration alone, so a local account
+whose domain is a login domain is sent to the IdP like any other name. While
+a password realm is enabled (`password` in `/auth/login-options`), the
+identifier-first form therefore offers **Sign in with a password instead**:
+the password step for the entered username, without asking `/auth/identify`.
+The notice of a refused or failed OIDC sign-in (`/login?error=not_permitted`
+or `oidc_failed`) offers the same, as a username and password form. Both are
+shown for every username, so neither reveals whether an account exists, and
+`/auth/identify` stays as it is (`web/src/routes/Login.tsx`).
### Endpoints
diff --git a/docs/changes/2.2.0/531.fixed.md b/docs/changes/2.2.0/531.fixed.md
new file mode 100644
index 00000000..5bb09a3d
--- /dev/null
+++ b/docs/changes/2.2.0/531.fixed.md
@@ -0,0 +1,8 @@
+With the identifier-first login screen, an account with a password whose
+username is in an OIDC realm's login domain could not sign in from the
+browser: the screen sent it to the identity provider and never asked for
+the password. That locked out an administrator who added a realm with their
+own domain. While a password realm is enabled, the screen now offers **Sign
+in with a password instead**, for every username alike, and so does the
+notice of a sign-in the identity provider refused or failed. The routing by
+login domain and the combined screen are unchanged.
diff --git a/docs/deployment.md b/docs/deployment.md
index 2a846edd..05d1c7c0 100644
--- a/docs/deployment.md
+++ b/docs/deployment.md
@@ -607,7 +607,7 @@ wrong.
| Setting | Default | Meaning |
| --- | --- | --- |
| `anonymous_mode` | `off` | `off` or `all`: who is served without credentials. A repository is read anonymously only when it also allows it (**Allow anonymous read**, or a grant of the `anonymous` role). Under `all`, signed-in users also read what anonymous callers may. To let a network read without credentials, have the load balancer name a service account through a [trusted-header realm](#trusted-header-realms). |
-| `login_mode` | `identifier_first` | The login screen: the username first (then a password prompt or the identity provider whose login domains match), or `combined` (username and password, plus the OIDC button). |
+| `login_mode` | `identifier_first` | The login screen: the username first (then a password prompt or the identity provider whose login domains match), or `combined` (username and password, plus the OIDC button). While a password realm is enabled, the username-first screen also offers **Sign in with a password instead**, which asks for the password of any username, also one in a login domain; the notice of a sign-in the identity provider refused or failed offers the same. It is how an account with a password signs in when its domain goes to an identity provider that is down or not linked to it. It does not enforce anything either way: `POST /auth/login` takes a password realm's passwords whatever the screen shows. |
| `remember_accounts` | `true` | The login screen offers the accounts signed in on the device before, so signing in again is one click (see below). `false` for kiosks and shared computers. |
| `session_idle_ttl_seconds` | `28800` (8 h) | A browser session ends this long after its last use. |
| `session_absolute_ttl_seconds` | `604800` (7 d) | A browser session ends this long after sign-in. New lifetimes apply to sessions signed in afterwards; an open session's idle window moves to the new idle timeout on its next use. |
diff --git a/web/src/routes/Login.test.tsx b/web/src/routes/Login.test.tsx
index cd276b6b..f23907fe 100644
--- a/web/src/routes/Login.test.tsx
+++ b/web/src/routes/Login.test.tsx
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
-import { render, screen, waitFor } from '@testing-library/react'
+import { cleanup, render, screen, waitFor, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { QueryClientProvider } from '@tanstack/react-query'
import {
@@ -31,6 +31,10 @@ vi.mock('~/lib/navigation', () => ({ assignLocation: vi.fn() }))
* - a 401 from /auth/login shows the uniform inline error;
* - a failed OIDC callback (`?error=`) shows a generic message per
* code, never the raw parameter, with a "Try again" link that clears it;
+ * - "Sign in with a password instead" reaches the password prompt without
+ * `/auth/identify` (#531), from the identifier-first form and from the
+ * notice of a refused or failed OIDC sign-in, for every username alike and
+ * only while a password realm is enabled;
* - there is **no** registry-token sign-in: the UI always authenticates with
* username+password or via a realm;
* - accounts signed in on this device are remembered and offered as tiles
@@ -266,6 +270,226 @@ describe('Login', () => {
})
})
+ describe('sign in with a password instead (#531)', () => {
+ // An OIDC realm whose login domain takes every example.com username.
+ const toCorp = () =>
+ json({
+ mode: 'oidc_redirect',
+ realm: 'corp',
+ login_url: '/auth/oidc/login?realm=corp',
+ })
+ const session = (username: string) =>
+ json({ user_id: 1, username, is_admin: true, csrf_token: 'csrf-pw' })
+
+ it('signs in an account of an OIDC login domain with its password, without /auth/identify', async () => {
+ const user = userEvent.setup()
+ const identify = vi.fn(toCorp)
+ let loggedIn: unknown = null
+ mockAuthApi({
+ options: identifierFirst,
+ onIdentify: identify,
+ onLogin: (body) => {
+ loggedIn = body
+ return session('admin@example.com')
+ },
+ })
+
+ const router = await renderLogin()
+
+ await user.type(await screen.findByLabelText('Username'), 'admin@example.com')
+ await user.click(
+ screen.getByRole('button', { name: 'Sign in with a password instead' }),
+ )
+
+ // The password step of the entered username, as after /auth/identify.
+ expect(await screen.findByText('admin@example.com')).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'Change' })).toBeInTheDocument()
+ await user.type(screen.getByLabelText('Password'), 'hunter2')
+ await user.click(screen.getByRole('button', { name: 'Sign in' }))
+
+ await waitFor(() =>
+ expect(loggedIn).toEqual({ username: 'admin@example.com', password: 'hunter2' }),
+ )
+ await waitFor(() => expect(router.state.location.pathname).toBe('/'))
+ expect(getCsrfToken()).toBe('csrf-pw')
+ expect(identify).not.toHaveBeenCalled()
+ expect(assignLocation).not.toHaveBeenCalled()
+ // Remembered as a password account, with no realm (none was named).
+ expect(listAccounts()).toMatchObject([
+ { identifier: 'admin@example.com', method: 'password' },
+ ])
+ expect(listAccounts()[0].realm).toBeUndefined()
+ })
+
+ it('is offered the same way for every username, before one is entered', async () => {
+ const user = userEvent.setup()
+ const identify = vi.fn(toCorp)
+ mockAuthApi({ options: identifierFirst, onIdentify: identify })
+
+ await renderLogin()
+
+ // Offered with the empty form: nothing about an account decides it.
+ await screen.findByLabelText('Username')
+ expect(
+ screen.getByRole('button', { name: 'Sign in with a password instead' }),
+ ).toBeInTheDocument()
+
+ for (const name of ['nobody@example.com', 'someone@elsewhere.test', 'plain']) {
+ await user.type(screen.getByLabelText('Username'), name)
+ await user.click(
+ screen.getByRole('button', { name: 'Sign in with a password instead' }),
+ )
+ expect(await screen.findByLabelText('Password')).toBeInTheDocument()
+ expect(screen.getByText(name)).toBeInTheDocument()
+ await user.click(screen.getByRole('button', { name: 'Change' }))
+ await user.clear(await screen.findByLabelText('Username'))
+ }
+ expect(identify).not.toHaveBeenCalled()
+ })
+
+ it('asks for the username first', async () => {
+ const user = userEvent.setup()
+ mockAuthApi({ options: identifierFirst })
+
+ await renderLogin()
+
+ await screen.findByLabelText('Username')
+ await user.click(
+ screen.getByRole('button', { name: 'Sign in with a password instead' }),
+ )
+
+ expect(await screen.findByRole('alert')).toHaveTextContent('Enter your username.')
+ expect(screen.queryByLabelText('Password')).not.toBeInTheDocument()
+ })
+
+ it('still routes by /auth/identify on Continue', async () => {
+ const user = userEvent.setup()
+ mockAuthApi({ options: identifierFirst, onIdentify: toCorp })
+
+ await renderLogin()
+
+ await user.type(await screen.findByLabelText('Username'), 'admin@example.com')
+ await user.click(screen.getByRole('button', { name: 'Continue' }))
+
+ await waitFor(() =>
+ expect(assignLocation).toHaveBeenCalledWith(
+ '/auth/oidc/login?realm=corp&login_hint=admin%40example.com',
+ ),
+ )
+ })
+
+ it('is not offered without a password realm', async () => {
+ mockAuthApi({ options: { ...identifierFirst, password: false } })
+
+ await renderLogin('/login?error=not_permitted')
+
+ await screen.findByLabelText('Username')
+ expect(
+ screen.queryByRole('button', { name: 'Sign in with a password instead' }),
+ ).toBeNull()
+ })
+
+ it.each(['not_permitted', 'oidc_failed'])(
+ 'the %s notice offers it next to "Try again", and signs in',
+ async (code) => {
+ const user = userEvent.setup()
+ const identify = vi.fn(toCorp)
+ let loggedIn: unknown = null
+ mockAuthApi({
+ options: identifierFirst,
+ onIdentify: identify,
+ onLogin: (body) => {
+ loggedIn = body
+ return session('admin@example.com')
+ },
+ })
+
+ const router = await renderLogin(`/login?error=${code}&redirect=%2Ftokens`)
+
+ const alert = await screen.findByRole('alert')
+ expect(within(alert).getByRole('link', { name: 'Try again' })).toBeInTheDocument()
+ await user.click(
+ await within(alert).findByRole('button', {
+ name: 'Sign in with a password instead',
+ }),
+ )
+
+ // The username and the password at once; the notice stays, without
+ // the offer just taken.
+ await user.type(await screen.findByLabelText('Username'), 'admin@example.com')
+ await user.type(screen.getByLabelText('Password'), 'hunter2')
+ expect(screen.queryByRole('button', { name: 'Continue' })).toBeNull()
+ expect(
+ screen.queryByRole('button', { name: 'Sign in with a password instead' }),
+ ).toBeNull()
+ await user.click(screen.getByRole('button', { name: 'Sign in' }))
+
+ await waitFor(() =>
+ expect(loggedIn).toEqual({ username: 'admin@example.com', password: 'hunter2' }),
+ )
+ await waitFor(() => expect(router.state.location.pathname).toBe('/tokens'))
+ expect(identify).not.toHaveBeenCalled()
+ expect(assignLocation).not.toHaveBeenCalled()
+ },
+ )
+
+ it('the notice offers it over the remembered accounts too', async () => {
+ const user = userEvent.setup()
+ rememberAccount({ identifier: 'admin@example.com', method: 'password', realm: 'local' })
+ mockAuthApi({ options: identifierFirst, onIdentify: toCorp })
+
+ await renderLogin('/login?error=not_permitted')
+
+ await screen.findByRole('list', { name: 'Remembered accounts' })
+ await user.click(
+ screen.getByRole('button', { name: 'Sign in with a password instead' }),
+ )
+
+ expect(await screen.findByLabelText('Password')).toBeInTheDocument()
+ expect(screen.queryByRole('list', { name: 'Remembered accounts' })).toBeNull()
+
+ await user.click(screen.getByRole('button', { name: 'Back to your accounts' }))
+ expect(
+ await screen.findByRole('list', { name: 'Remembered accounts' }),
+ ).toBeInTheDocument()
+ })
+
+ it('"Try again" goes back to the username step', async () => {
+ const user = userEvent.setup()
+ mockAuthApi({ options: identifierFirst })
+
+ await renderLogin('/login?error=oidc_failed')
+
+ await user.click(
+ await screen.findByRole('button', { name: 'Sign in with a password instead' }),
+ )
+ await screen.findByLabelText('Password')
+ await user.click(screen.getByRole('link', { name: 'Try again' }))
+
+ await waitFor(() => expect(screen.queryByRole('alert')).toBeNull())
+ expect(screen.queryByLabelText('Password')).toBeNull()
+ expect(screen.getByRole('button', { name: 'Continue' })).toBeInTheDocument()
+ })
+
+ it('leaves the other notices and the combined form as they are', async () => {
+ mockAuthApi({ options: identifierFirst })
+ await renderLogin('/login?error=username_not_upn')
+ const alert = await screen.findByRole('alert')
+ await screen.findByLabelText('Username')
+ expect(
+ within(alert).queryByRole('button', { name: 'Sign in with a password instead' }),
+ ).toBeNull()
+ cleanup()
+
+ mockAuthApi({ options: combined })
+ await renderLogin('/login?error=not_permitted')
+ await screen.findByLabelText('Password')
+ expect(
+ screen.queryByRole('button', { name: 'Sign in with a password instead' }),
+ ).toBeNull()
+ })
+ })
+
describe('lockout and return-to', () => {
it('shows a lockout message (not "server unreachable") on a 429', async () => {
const user = userEvent.setup()
diff --git a/web/src/routes/Login.tsx b/web/src/routes/Login.tsx
index 8c8e83bc..6aa1c1b6 100644
--- a/web/src/routes/Login.tsx
+++ b/web/src/routes/Login.tsx
@@ -163,6 +163,17 @@ export const Route = createFileRoute('/login')({
* opens reaches the app (`completePendingSignIn`).
* A failed OIDC callback lands here with `?error=`: a short, generic
* message is shown above the form with a "Try again" link that clears it.
+ *
+ * Identifier-first routing is decided by realm configuration alone, so a
+ * username in an OIDC realm's login domain always goes to the identity
+ * provider, also when its account signs in with a password. While a password
+ * realm is enabled (`password`), the identifier-first form therefore offers
+ * "Sign in with a password instead", which asks for the password without
+ * `/auth/identify`, and so does the notice of a sign-in the identity provider
+ * refused or failed (`not_permitted`, `oidc_failed`). Both are offered
+ * whatever the username is, so they tell nothing about an account. (Linking
+ * an identity to an existing account at sign-in, #530, is a step of its own
+ * and does not come back here as `not_permitted`.)
* Signing in with a registry token is intentionally not offered: the UI always
* authenticates with username+password or via a realm. Tokens are minted on
* the Tokens screen for NuGet clients only.
@@ -184,10 +195,22 @@ function Login() {
const [accounts, setAccounts] = useState(listAccounts)
const [picked, setPicked] = useState{claim} claim.
+ +
+ )} )} @@ -264,6 +306,8 @@ function Login() { onForget={forget} onAnother={() => setAnother(true)} /> + ) : passwordInstead ? ( +Forge checks which sign-in your account uses. With your organization’s single sign-on you continue at its sign-in page; @@ -307,6 +354,9 @@ function Login() { ) } +/** The way to the password prompt that does not ask `/auth/identify`. */ +const PASSWORD_INSTEAD = 'Sign in with a password instead' + /** * Append the post-login destination to an OIDC login URL so the server can * send the browser back after the IdP round-trip @@ -421,15 +471,23 @@ function FormError({ children }: { children: React.ReactNode }) { * with a back link) or navigates the browser to the IdP, with the username * as its login hint. With `initialRealm` (a remembered account `identify` * already routed to a password realm) it starts at step 2. + * + * With `passwordOffered` (a password realm is enabled), step 1 also offers + * "Sign in with a password instead": step 2 for the entered username without + * asking `/auth/identify`, for an account whose domain goes to an identity + * provider that cannot sign it in (it is down, or the account is not linked + * to it). It is offered for every username alike. */ function IdentifierFirstLogin({ redirect, remember, + passwordOffered, initialUsername, initialRealm, }: { redirect?: string remember: boolean + passwordOffered: boolean initialUsername?: string initialRealm?: string }) { @@ -472,6 +530,18 @@ function IdentifierFirstLogin({ } } + function onPasswordInstead() { + if (!username.trim()) { + setError('Enter your username.') + return + } + // No realm: `/auth/identify` was not asked, and `/auth/login` tries the + // password realms in their order. + setRealm(undefined) + setError(null) + setStep('password') + } + function onPassword(e: React.FormEvent) { e.preventDefault() if (!password) { @@ -496,6 +566,16 @@ function IdentifierFirstLogin({ + {passwordOffered && ( + + )} ) }