CLAUDE.md caps a comment at one or two lines and a docstring at one
sentence. The rationale that was inline (the failure mode, the
backwards-compatibility argument, the OAuth 2.1 reference) belongs in the
PR body, so what stays is the one fact the code cannot convey: Authlib
derives no code_verifier unless code_challenge_method is set.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Authlib only derives a code_verifier when `code_challenge_method` is set
on the client, so the OIDC client registered in `decorators/auth.py` sent
no `code_challenge` at all. Against a provider that mandates PKCE the user
authenticates successfully and is then redirected back without a `code`,
which surfaces as a generic login failure with nothing useful in the logs.
Set `code_challenge_method: "S256"` in `client_kwargs`. Providers that do
not support PKCE ignore the extra parameters (OIDC Core 3.1.2.1), so this
is backwards-compatible, and OAuth 2.1 requires PKCE of every client.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Protected routes answered 403 both when there was no session and when the
authenticated user lacked the required scope. The frontend read every 403
as session expiry, cleared the session cookie and redirected to /login, so
a permission denial (for instance saving a state without the save scope)
tore down whatever the user was doing, including a running emulator.
`protected_route` now uses its own scope guard that raises 401 with a
`WWW-Authenticate` header when the caller is unauthenticated, and 403 when
the caller is authenticated but under-scoped. The axios interceptor only
redirects on 401 and lets 403s surface inline to the caller, refreshing the
CSRF cookie when the backend rejected the CSRF token.
Endpoint assertions for unauthenticated requests move from 403 to 401;
authenticated under-scoped cases stay 403.
Fixes#4045
Use `authlib` util `get_well_known_url` to get the well-known URL for
the OIDC server metadata. This will ensure that the URL is correctly
formatted and does not fail when the OIDC server application URL has a
trailing slash.
Fixes#1430.
Instead of using just strings, this change converts the scopes to a
`StrEnum`, to be compatible with places where a string is expected. This
avoids typos when using these scopes, simplifies searching for usages,
and improves type hints.
An extra change was the fix to the Firmware download endpoint, which
wasn't respecting the `DISABLE_DOWNLOAD_ENDPOINT_AUTH` flag.
As recommended by SQLAlchemy [1], this change makes a single
instantiation of the database engine and session maker, instead of one
entity per handler.
It also uses the provided `URL` constructor to better define the
database URL structure.
[1] https://docs.sqlalchemy.org/en/20/core/connections.html#basic-usage