Session, transaction and replay stores¶
rn_forge.auth.stores
¶
Server-side records: login sessions and transactions, replayed token IDs and revoked sessions.
InMemoryReplayStore(*, clock=time.monotonic)
¶
:class:ReplayStore held in process memory.
Thread-safe. The records are not shared across processes, so it suits tests and single-process deployments only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clock
|
Callable[[], float]
|
Returns the current time in seconds, monotonic. |
monotonic
|
InMemorySessionStore(*, clock=_utc_now)
¶
:class:SessionStore held in process memory.
Thread-safe. The sessions are not shared across processes, so it suits tests and single-process deployments only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clock
|
Callable[[], datetime]
|
Returns the current time as an aware datetime. |
_utc_now
|
InMemoryTransactionStore(*, clock=time.monotonic)
¶
:class:TransactionStore held in process memory.
Thread-safe. The records are not shared across processes, so it suits tests and single-process deployments only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clock
|
Callable[[], float]
|
Returns the current time in seconds, monotonic. |
monotonic
|
ReplayStore
¶
Bases: Protocol
Records that a value was seen once, and which sessions are revoked.
Every record expires after its ttl. Implementations shared by several
processes must make :meth:record_once atomic.
is_sid_revoked(issuer, sid)
¶
Return whether the session sid of issuer is currently revoked.
record_once(key, *, ttl)
¶
Record key for ttl unless it is already recorded.
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
has not expired was already present. |
revoke_sid(issuer, sid, *, ttl)
¶
Mark the session sid of issuer revoked for ttl.
SessionStore
¶
Bases: Protocol
Holds login sessions under random, unguessable IDs.
A session ends at the first of two times: its idle expiry, which
:meth:touch and :meth:rotate extend, and SessionInfo.expires_at,
which nothing extends. A session past either is absent.
create(session, *, idle_ttl)
¶
Store session and return its new session ID.
The session is idle-expired idle_ttl from now.
delete(session_id)
¶
Remove the session; absent sessions are ignored.
get(session_id)
¶
Return the session, or None when absent or expired.
Reading does not extend the idle expiry.
rotate(session_id, *, idle_ttl)
¶
Move the session to a new ID and remove the old record.
The idle expiry restarts at idle_ttl from now, capped at expires_at.
Returns:
| Type | Description |
|---|---|
str | None
|
The new session ID, or |
str | None
|
expired. |
touch(session_id, *, idle_ttl)
¶
Move the idle expiry to idle_ttl from now, but not past expires_at.
Returns:
| Type | Description |
|---|---|
bool
|
|
TransactionStore
¶
Bases: Protocol
Holds login transactions between the login redirect and the callback.
Implementations shared by several processes must make :meth:consume
atomic.
consume(transaction_id)
¶
Remove and return the transaction with ID transaction_id.
When callers race, exactly one receives the transaction.
Returns:
| Type | Description |
|---|---|
LoginTransaction | None
|
The transaction, or |
LoginTransaction | None
|
has expired. |
save(transaction, *, ttl)
¶
Store transaction under its id for ttl.