s365b.auth.sessions¶
Server-side sessions.
The browser gets a random token in an HttpOnly, Secure,
SameSite=Lax cookie; the database stores only its SHA-256. Every session
also has a CSRF token that state-changing requests must echo in the
X-CSRF-Token header.
Lifetimes are shorter for break-glass sessions, which should only be used for the emergency at hand.
Attributes¶
Classes¶
Idle and absolute session lifetimes. |
Functions¶
|
Start a session for a user who just signed in. |
|
Return the live session for a cookie token, refreshing its idle timer. |
|
Sign out: delete one session. |
|
Delete every session of a user (password reset, disable, role change). |
|
Delete sessions past their absolute expiry. |
Module Contents¶
- class s365b.auth.sessions.SessionPolicy[source]¶
Idle and absolute session lifetimes.
- Variables:
idle – Session ends after this long without requests.
absolute – Session ends this long after sign-in regardless of activity.
- async s365b.auth.sessions.create_session(s: sqlalchemy.ext.asyncio.AsyncSession, user: s365b.db.models.UserAccount, method: s365b.db.models.AuthSource, role: s365b.db.models.UserRole, *, ip: str | None, user_agent: str) tuple[str, s365b.db.models.UserSession][source]¶
Start a session for a user who just signed in.
- Parameters:
s – Open session; the caller commits.
user – The signed-in user.
method – How they signed in.
role – Their role for this session.
ip – Client IP address.
user_agent – Client user agent.
- Returns:
the cookie value and the stored session.
- Return type:
(token, row)
- async s365b.auth.sessions.load_session(s: sqlalchemy.ext.asyncio.AsyncSession, token: str) s365b.db.models.UserSession | None[source]¶
Return the live session for a cookie token, refreshing its idle timer.
Expired sessions and sessions of disabled users are deleted.
- Parameters:
s – Open session; the caller commits.
token – Cookie value.
- Returns:
The session (with
userloaded) orNone.
- async s365b.auth.sessions.end_session(s: sqlalchemy.ext.asyncio.AsyncSession, token: str) None[source]¶
Sign out: delete one session.
- Parameters:
s – Open session; the caller commits.
token – Cookie value.