Skip to content

fix: make auth logout() best-effort and never fail local logout - #58

Merged
nycomp merged 1 commit into
mainfrom
bugfix/logout-best-effort
Oct 1, 2026
Merged

nycomp merged 1 commit into
mainfrom
bugfix/logout-best-effort

Conversation

@nycomp

@nycomp nycomp commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Fixes the server-side half of nyjc-computing/campus-admin#14: GET /logout 500 (NotFoundError: No session ID in client).

What happened

The auth service's DELETE /auth/v1/logins/<id> requires the client's own {provider}_session_id cookie (_verify_session_id in campus/auth/resources/login.py), returning 404 "No session ID in client" when absent. The Campus client keeps its cookie jar in a per-process requests.Session, so with multi-worker gunicorn (or after any deploy/restart) the login POST and the logout DELETE can hit different processes — the cookie is gone, the DELETE 404s, and raise_for_status() blew up the app's /logout route.

Fix

AuthAPI.logout() now treats remote revocation as best-effort:

  • attempt the revoke as before;
  • on any failure, log a warning and clear the stored login session id from the Flask session instead of raising;
  • flask.g.pop(..., None) so a direct logout() outside the usual request flow cannot KeyError.

Apps always get a local logout + redirect, matching the expectation recorded in campus-admin#14. Verified locally against the dev auth service: a Flask session with a stale logins_login_id (and a dummy client) now logs out cleanly with a warning instead of raising.

The auth-service side (DELETE /logins rejecting server-to-server clients whose per-process cookie jar lost the auth session) deserves a separate look; I'll file that on the campus repo.

Revoking the login session remotely could raise (e.g. 404 'No session
ID in client' when the client's auth service session cookie was lost
across app workers or swept server-side), which turned /logout into a
500 for the whole app. Logout must always succeed locally: clear
flask.g and the stored login session id, attempt remote revocation,
and log a warning if it fails.
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.

2 participants