feat(auth): add POST /auth/logout-all to end every session - #296
Open
nicolasgutierrezdev wants to merge 1 commit into
Open
nicolasgutierrezdev wants to merge 1 commit into
nicolasgutierrezdev wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Users could only end their current session (
POST /api/v1/auth/logout). After a suspected compromise there was no way to kill sessions on other devices, including ones they no longer control. crudauth 0.6 already has the primitive (revoke_all/terminate_all_user_sessions) and its own/logout-allroute, but the boilerplate mounts its own auth router, so that route was never exposed.Behavior
POST /logout-allPOST /logout-all?keep_current=trueResponse:
{"message": ..., "terminated_count": n}./logout(401 / 403 otherwise).logout_alldefault (10/hour).Verified against Redis (docker stack)
session_users:1holds 3?keep_current=trueterminated_count: 2, A and C logged out, B still logged in, 1 key leftlogout-allterminated_count: 2, B and D logged out, cookie cleared, 0session:*keysx-ratelimit-limit: 10, remaining 9 → 8Changes
src/infrastructure/auth/routes.py:POST /logout-allwithkeep_currenttests/integration/auth/test_endpoints.py: all sessions ended,keep_currentkeeps the calling session, 401 without a session, 403 without CSRF. Each test first clears the user's leftover sessions, because the in-memory store is shared across the test run and every test'stest_usergets the same id.authentication/sessions.md,api/index.md,project-structure.md): new "Logout All Sessions" section with curl examples; route lists updated