Add dual-auth dependency for jersey and checkout routes #255
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ldraney/basketball-api#255
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Feature
Lineage
Child of
forgejo_admin/westside-landing#196(spike: player self-service jersey ordering).Story: WS-S18 — "As a parent, I want to receive a branded email with jersey ordering link so that I can order without bringing cash"
Repo
forgejo_admin/basketball-apiUser Story
As a logged-in parent
I want to access jersey ordering and checkout using my Keycloak session
So that I can order directly from my profile without needing the email token link
Context
The jersey and checkout routes currently authenticate exclusively via
Parent.registration_tokenpassed as a?token=query param. This works for email-link flows but blocks self-service ordering from the SPA where parents are already authenticated via Keycloak JWT.The account route (
account.pyline 57) already demonstrates the pattern:Parent.email.ilike(user.email)resolves a Parent from a Keycloak session. This ticket creates a reusable dependency that accepts EITHER auth method.register.pyandtryouts.pyalso useregistration_tokenbut in completely separate code paths with no shared helpers — zero blast radius.File Targets
Files the agent should modify or create:
src/basketball_api/auth.py— addget_parent_dual_auth(token: str | None, credentials, db)dependency that tries token first, then Keycloak JWT + email lookupsrc/basketball_api/routes/jersey.py— lines 109-122 (jersey_player_info) and lines 227-235 (jersey_checkout): replace inlineParent.registration_tokenlookup with new dependencysrc/basketball_api/routes/checkout.py— lines 115-122 (create_checkout_session): replace inlineParent.registration_tokenlookup with new dependencytests/— add tests for both auth pathsFiles the agent should NOT touch:
src/basketball_api/routes/register.py— usesregistration_tokenin separate code pathssrc/basketball_api/routes/tryouts.py— usesregistration_tokenin separate code pathsAcceptance Criteria
/jersey/player-info?token=abc123, then the existing token auth works unchanged/jersey/player-infowith a Keycloak Bearer token (no?token=), then it resolves the parent via email match/jersey/checkoutor/checkout/create-sessionwith either auth method, then both workTest Expectations
get_parent_dual_authreturns Parent when given valid registration tokenget_parent_dual_authreturns Parent when given valid Keycloak JWT with matching emailget_parent_dual_authraises 401 when neither auth method providedget_parent_dual_authraises 404 when Keycloak email matches no parent/jersey/player-infoworks with both auth methodspytest tests/ -k "dual_auth or jersey or checkout"Constraints
tokenquery param must remain optional (not removed) for backwards compatibilityauth.py(get_current_user)Parent.playersrelationship (usejoinedload)Checklist
Related
westside-basketball— project this affectsforgejo_admin/westside-landing#196— parent spike issue