Commit Graph

30 Commits

Author SHA1 Message Date
Juan Garces
316734b3fb style(auth): trim the PKCE comment and docstrings to repo convention
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>
2026-08-22 13:08:07 -05:00
Juan Garces
eadd8fe5c3 fix(auth): send PKCE on the OIDC authorization request
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>
2026-08-22 12:47:26 -05:00
Georges-Antoine Assi
f26c3234d7 fix(auth): return 401 for unauthenticated requests, keep 403 for missing scopes
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
2026-08-01 14:12:40 -04:00
Georges-Antoine Assi
389025942f changes from bot review 2026-06-21 17:42:25 -04:00
copilot-swe-agent[bot]
ff1c8b680e Fix OIDC login with Google by adding OIDC_SERVER_METADATA_URL config option
Co-authored-by: gantoine <3247106+gantoine@users.noreply.github.com>
2026-03-09 17:39:43 +00:00
Georges-Antoine Assi
fc5897822e cleanup code 2025-10-06 09:43:07 -04:00
Marius Luca
3eb89c76df - add OIDC_CLAIM_ROLES to the requested scope in order for it to be filled in the token userinfo 2025-10-06 13:30:00 +03:00
Michael Manganiello
e4e3928d1b misc: Apply import sorting 2025-09-04 11:17:00 -03:00
Georges-Antoine Assi
6c95a03746 Read-only kiosk mode for viewers 2025-02-06 09:04:41 -05:00
Georges-Antoine Assi
45e11acfa2 [ROMM-1442] Add OIDC_TLS_CACERTFILE path to mounted certfile 2025-01-09 21:20:10 -05:00
Michael Manganiello
865370ec13 misc: Move auth constants to separate file
This simplifies avoiding circular imports when trying to use auth
handlers.
2025-01-08 22:16:31 -03:00
Michael Manganiello
47fb3bdd33 fix: Do not fail when OIDC server application URL has a trailing slash
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.
2025-01-08 01:32:24 -03:00
zurdi
7baf1c7937 Fix typo in OIDC_PROVIDER variable name across configuration and authentication files 2024-12-23 16:02:19 +00:00
Georges-Antoine Assi
c3f50d1f12 Add oidc provider name and icon to login page 2024-12-23 09:28:00 -05:00
Georges-Antoine Assi
f2f8956ad4 more cleanup of unneded oauth code 2024-11-29 09:26:03 -05:00
Georges-Antoine Assi
3abf50b056 changes from self review 2024-11-27 23:28:54 -05:00
Georges-Antoine Assi
11923786be fetch and use rsa key 2024-11-27 22:40:02 -05:00
Georges-Antoine Assi
bc5c2e45f3 wokring oidc setup with authentik 2024-11-26 23:57:15 -05:00
Georges-Antoine Assi
3a91b7ba54 Merge branch 'master' into openid-connect 2024-11-26 19:52:18 -05:00
Michael Manganiello
beeb9f0c31 misc: Create enum for authorization scopes
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.
2024-10-18 23:57:42 -03:00
Michael Manganiello
a85c84a7d4 misc: Use single SQLAlchemy engine and session maker
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
2024-08-21 09:56:28 -03:00
Georges-Antoine Assi
0fae870837 start work with fake openid add for testing 2024-08-04 00:41:34 -04:00
Georges-Antoine Assi
b2085f87a8 bunch of fixes for trunk 2024-05-21 17:10:11 -04:00
Georges-Antoine Assi
880345f20c ruff-only pre-commit 2024-05-18 12:05:57 -04:00
Georges-Antoine Assi
2756121f06 Merge branch 'master' into python-pkg-drop 2024-05-14 09:22:59 -04:00
Georges-Antoine Assi
555dfaca16 backend updates 2024-05-12 21:40:18 -04:00
Georges-Antoine Assi
9ad28f3294 more refactoring again 2024-05-05 16:32:40 -04:00
Zurdi
42065aec7c backend refactor as RESTful 2024-01-15 13:34:18 +01:00
Zurdi
1d2c9e7d05 standarized GET endpoints for roms and platforms 2024-01-14 02:34:37 +01:00
Zurdi
4b9e76f550 backend structure refactor 2024-01-12 23:44:27 +01:00