Server Context¶
Module: s2auth.server.context
PairingToken = Annotated[str, StringConstraints(pattern='^[A-Za-z0-9+/]{4,}={0,2}$', min_length=4)]
module-attribute
¶
log = logging.getLogger(__name__)
module-attribute
¶
ClientNodeId = UUID
module-attribute
¶
PairingAttemptId = UUID
module-attribute
¶
ContextTypeT = TypeVar('ContextTypeT', bound=BaseModel)
module-attribute
¶
s2_client_node_id_var = ContextVar('s2_client_node_id', default=None)
module-attribute
¶
pairing_attempt_id_var = ContextVar('pairing_attempt_id', default=None)
module-attribute
¶
pairing_token_var = ContextVar('pairing_token', default=None)
module-attribute
¶
HmacChallenge
¶
Bases: RootModel[Base64Bytes]
Source code in src/s2auth/common/model/s2_connect_pairing.py
HmacHashingAlgorithm
¶
S2PairingAttemptId
¶
Bases: RootModel[str]
Source code in src/s2auth/common/model/s2_connect_pairing.py
NodeIdAlias
¶
Bases: RootModel[str]
Source code in src/s2auth/common/model/s2_connect_pairing.py
AccessToken
¶
Bases: RootModel[Base64Bytes]
Source code in src/s2auth/common/model/s2_connect_common.py
EndpointDescription
¶
NodeDescription
¶
NodeId
¶
ClientState
¶
PairingState
¶
S2InMemoryContextStorage
¶
Bases: InMemoryContextStorage
In-memory context storage with typed context listing support.
Source code in src/s2auth/server/context.py
list_contexts(ctx_type)
async
¶
Return snapshots of all stored contexts for the requested type.
Source code in src/s2auth/server/context.py
delete_context(ctx_type, context_id)
async
¶
Delete a stored context for the requested type and ID.
Source code in src/s2auth/server/context.py
AuthenticationContext
¶
Bases: BaseModel
Authentication context data for a client connection.
Note: Modifications to context instances should be done carefully in multi-threaded/async environments. Consider using the storage's locking mechanisms if implementing complex state updates.
Source code in src/s2auth/server/context.py
PairingAttemptContext
¶
Bases: BaseModel
Context data for a pairing attempt.
Note: Modifications to context instances should be done carefully in multi-threaded/async environments. Consider using the storage's locking mechanisms if implementing complex state updates.
Source code in src/s2auth/server/context.py
ReadOnlyAuthenticationContext
¶
Bases: AuthenticationContext
Read-only view of AuthenticationContext for passing to hooks.
This class prevents accidental modification of context state in hooks. Any attempt to modify attributes will raise a ValidationError.
Source code in src/s2auth/server/context.py
ReadOnlyPairingAttemptContext
¶
Bases: PairingAttemptContext
Read-only view of PairingAttemptContext for passing to hooks.
This class prevents accidental modification of context state in hooks. Any attempt to modify attributes will raise a ValidationError.
Source code in src/s2auth/server/context.py
s2_context_storage_singleton()
¶
Use s2auth context storage for server context providers.
client_node_id()
¶
Returns the s2_client_node_id from contextvars.
Source code in src/s2auth/server/context.py
pairing_attempt_id()
¶
Returns the pairing_attempt_id from contextvars.
Source code in src/s2auth/server/context.py
pairing_token()
¶
Returns the pairing token from contextvars.
authentication_context(client_node_id=Depends[client_node_id], storage=Depends[context_storage_singleton])
async
¶
Retrieves the context for the specified client_node_id.
This is an async generator provider that yields the context while holding its per-ID lock. The lock is held for the entire duration that dependent functions use the context, ensuring thread-safe and async-safe modifications.
Works in both async and threaded environments through wepositive-di storage.
Source code in src/s2auth/server/context.py
pairing_attempt_context(pairing_attempt_id=Depends[pairing_attempt_id], storage=Depends[context_storage_singleton])
async
¶
Retrieves the context for the specified pairing_attempt_id.
This is an async generator provider that yields the context while holding its per-ID lock. The lock is held for the entire duration that dependent functions use the context, ensuring thread-safe and async-safe modifications.
Works in both async and threaded environments through wepositive-di storage.
Source code in src/s2auth/server/context.py
pairing_attempt_context_by_client_node_id(client_node_id=Depends[client_node_id], storage=Depends[context_storage_singleton])
async
¶
Retrieve a pairing attempt context by its client_node_id.
Source code in src/s2auth/server/context.py
authentication_context_by_pairing_attempt_context(pairing_attempt_id=Depends[pairing_attempt_id], storage=Depends[context_storage_singleton])
async
¶
Retrieve authentication context through the current pairing attempt.
Source code in src/s2auth/server/context.py
store_authentication_context(storage=Depends[context_storage_singleton])
async
¶
Provider that returns a function to store authentication contexts.
Returns a callable that can be used to safely store AuthenticationContext objects in the context storage. Thread-safe and async-safe.
Usage
@inject async def my_function( store_ctx: Callable[[AuthenticationContext], Awaitable[None]] = Depends[store_authentication_context] ): ctx = AuthenticationContext(client_node_id=some_uuid) await store_ctx(ctx)
Source code in src/s2auth/server/context.py
store_pairing_attempt_context(storage=Depends[context_storage_singleton])
async
¶
Provider that returns a function to store pairing attempt contexts.
Returns a callable that can be used to safely store PairingAttemptContext objects in the context storage. Thread-safe and async-safe.
Usage
@inject async def my_function( store_ctx: Callable[[PairingAttemptContext], Awaitable[None]] = Depends[store_pairing_attempt_context] ): ctx = PairingAttemptContext(pairing_attempt_id=some_uuid, ...) await store_ctx(ctx)