Skip to content

Add keycloak support#1274

Open
kernicPanel wants to merge 2 commits intomainfrom
keycloak
Open

Add keycloak support#1274
kernicPanel wants to merge 2 commits intomainfrom
keycloak

Conversation

@kernicPanel
Copy link
Member

@kernicPanel kernicPanel commented Jan 26, 2026

Purpose

Now that richie users could login with keycloak openid, we have to support the sent token.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for Keycloak-flavored OIDC/JWT tokens (different typ claim and user-identifying claim like preferred_username) so Joanie can correctly authenticate and synchronize users when Richie is configured with Keycloak.

Changes:

  • Introduces a Keycloak-compatible JWT token class and makes SimpleJWT settings configurable for Keycloak (ISSUER, JWK_URL, TOKEN_TYPE_CLAIM, USER_ID_CLAIM).
  • Centralizes username extraction from authenticated requests via a new get_authenticated_username helper and updates multiple endpoints/filters to use it.
  • Extends the test suite (and perf expectations) to cover Keycloak token shapes and resulting user-sync queries.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/backend/joanie/core/authentication.py Adds Keycloak token class and tweaks token→user field extraction logic.
src/backend/joanie/core/utils/api.py New helper to read the authenticated username from request/token claims.
src/backend/joanie/core/utils/jwt_tokens.py Generates Keycloak-shaped tokens when an issuer is configured.
src/backend/joanie/settings.py Makes SimpleJWT configurable for Keycloak and allows Keycloak token class.
src/backend/joanie/payment/api.py Uses shared username extraction helper for credit-card ownership operations.
src/backend/joanie/core/filters/client/certificate.py Uses shared username extraction helper in certificate filtering.
src/backend/joanie/core/api/client/init.py Replaces repeated auth-username extraction with the shared helper across many endpoints.
src/backend/joanie/tests/base.py Updates test token generation to support Keycloak token shapes.
src/backend/joanie/tests/core/test_api_base.py Adds coverage for token generation when Keycloak issuer is configured.
src/backend/joanie/tests/core/test_models_user.py Adds Keycloak-oriented user sync tests and settings patches.
src/backend/joanie/tests/core/test_models_user.perf.yml Updates perf expectations for user sync queries (incl. Keycloak case).
src/backend/joanie/tests/core/test_authentication_delegated_jwt_authentication.py Adds a Keycloak-focused test class for delegated JWT auth behavior.
src/backend/joanie/tests/core/test_api_courses_contract.perf.yml Updates perf expectations to include user sync UPDATE query.
src/backend/joanie/tests/core/test_api_course_accesses.perf.yml Updates perf expectations to include user sync UPDATE query.
src/backend/joanie/tests/core/test_api_contract.perf.yml Updates perf expectations to include user sync UPDATE query.
src/backend/joanie/tests/core/api/organizations/test_list.perf.yml Updates perf expectations to include user sync UPDATE query.
src/backend/joanie/tests/core/api/organizations/test_api_organizations_contract.perf.yml Updates perf expectations to include user sync UPDATE query.
src/backend/joanie/tests/core/api/organizations/test_api_organizations_agreements.perf.yml Updates perf expectations to include user sync UPDATE query.
src/backend/joanie/tests/core/api/organizations/test_api_organization_accesses.perf.yml Updates perf expectations to include user sync UPDATE query.
src/backend/joanie/tests/core/api/order/test_create.perf.yml Updates perf expectations to include user sync UPDATE query.
env.d/development/common.dist Documents env vars for Keycloak integration and JWT claim mapping.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kernicPanel kernicPanel force-pushed the keycloak branch 2 times, most recently from fa37e7a to 499c8fe Compare January 26, 2026 12:53
Replaced repetitive username extraction logic across views with a centralized
`get_authenticated_username` utility. This improves code readability and
reduces duplication.
Added support for Keycloak JWT tokens,
including custom claims and a dedicated `KeycloakAccessToken` class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants