feat: login mit serverseitigen sessions
- POST /api/auth/login|logout, GET /api/auth/me - Session-Token nur gehasht gespeichert, Cookie HttpOnly/Secure/SameSite=Lax - Ablauf nach 30 Tagen Inaktivität bzw. spätestens 90 Tagen - Sessions pro Gerät auflisten und widerrufen, Rotation beim Login - Passwortänderung beendet alle anderen Sessions Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
04161bcf1d
commit
18f0d04ce9
11 files changed
+556
-3
No files matched your search
@@ -57,3 +57,25 @@ def client(app_env) -> Iterator[TestClient]:
|
||||
# https so that Secure cookies are sent back by the test client
|
||||
with TestClient(create_app(), base_url="https://testserver") as test_client:
|
||||
yield test_client
|
||||
|
||||
|
||||
PASSWORD = "correct horse battery"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def make_user(db):
|
||||
from app.models import Role
|
||||
from app.services.users import create_user
|
||||
|
||||
def _make(username: str = "anna", role: Role = Role.USER, password: str = PASSWORD):
|
||||
return create_user(db, username, password, role)
|
||||
|
||||
return _make
|
||||
|
||||
|
||||
def login(client: TestClient, username: str, password: str = PASSWORD):
|
||||
"""Log in and return the response; the CSRF token is set as default header."""
|
||||
response = client.post("/api/auth/login", json={"username": username, "password": password})
|
||||
if response.status_code == 200:
|
||||
client.headers["X-CSRF-Token"] = client.cookies["lc_csrf"]
|
||||
return response
|
||||
Reference in new issue
Block a user