Skip to content

fix(auth): prefer the embedded session user in finalize/push_context (#879) - #106

Merged
ngjunsiang merged 1 commit into
mainfrom
fix/879-use-embedded-session-user
Oct 10, 2026
Merged

ngjunsiang merged 1 commit into
mainfrom
fix/879-use-embedded-session-user

Conversation

@ngjunsiang

Copy link
Copy Markdown
Contributor

Companion to campus#880 (server half of campus#879).

Problem

Auth.finalize() (step 4) and Auth.push_context() hydrate the signed-in user via GET /users/{id} with the app's own client credentials. Since campus#854 that route is operator-only, so every non-operator flask_campus app fails sign-in at /finalize_login (reproduced live on nyxchange-timetable-v2; diagnosis in campus#879).

Fix

The auth service now embeds the user record in session reads, finalization, and login-session reads for the session-owning client. This SDK change consumes it:

  • Session.finalize() returns (target, user) — the response's user is parsed explicitly, so it works even against older campus-suite installs without the model field. Only in-repo caller: Auth.finalize().
  • Auth.finalize() answers the user-exists check from the embed; users.get remains the fallback when no embed came back (pre-#879 services).
  • push_context() (both session and login branches) hydrates g.user from the embedded record with the same fallback; a getattr guard covers campus-suite installs that predate the model field.

Version-skew matrix: new SDK + new service → no users-route call for owning clients (the fix); new SDK + old service → fallback, behavior unchanged; old SDK + new service → unknown key ignored, unchanged.

Tests

  • New test_embedded_session_user.py (8): finalize embed/fallback, push_context session and login branches, and the model-without-field skew case.
  • Updated test_sessions.py and test_finalize_device_id.py for the tuple return.
  • Full unit suite: 284 pass.

…(#879)

The auth service now embeds the session user record in session reads,
finalization, and login-session reads for the session-owning client
(campus companion change for campus#879). finalize() answers the
user-exists check from the embed and push_context() hydrates g.user
from it, falling back to the operator-gated users route on pre-#879
services or campus-suite installs without the model field.

Session.finalize() returns (target, user) instead of target alone —
the only in-repo caller is Auth.finalize().
@ngjunsiang
ngjunsiang merged commit 98f5ff0 into main Oct 10, 2026
4 checks passed
@ngjunsiang
ngjunsiang deleted the fix/879-use-embedded-session-user branch October 10, 2026 04:08
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.

1 participant